Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce flakiness in tests #2379

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.7.18"
version = "0.7.19"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
38 changes: 23 additions & 15 deletions mithril-aggregator/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ pub mod tests {
use mithril_signed_entity_lock::SignedEntityTypeLock;
use mockall::predicate::eq;
use mockall::{mock, Sequence};
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::RwLock;

Expand Down Expand Up @@ -585,8 +586,11 @@ pub mod tests {
AggregatorRunner::new(Arc::new(deps))
}

async fn build_runner(mock_certifier_service: MockCertifierService) -> AggregatorRunner {
let mut deps = initialize_dependencies!().await;
async fn build_runner(
temp_dir: PathBuf,
mock_certifier_service: MockCertifierService,
) -> AggregatorRunner {
let mut deps = initialize_dependencies(temp_dir).await;
deps.certifier_service = Arc::new(mock_certifier_service);

let mut mock_signable_builder_service = MockSignableBuilderServiceImpl::new();
Expand Down Expand Up @@ -944,7 +948,7 @@ pub mod tests {
.expect_create_open_message()
.return_once(|_, _| Ok(open_message_created))
.times(1);
build_runner(mock_certifier_service).await
build_runner(temp_dir!(), mock_certifier_service).await
};

let open_message_returned = runner
Expand All @@ -969,7 +973,7 @@ pub mod tests {
);

mock_certifier_service.expect_create_open_message().never();
build_runner(mock_certifier_service).await
build_runner(temp_dir!(), mock_certifier_service).await
};

let open_message_returned = runner
Expand All @@ -996,7 +1000,7 @@ pub mod tests {
);

mock_certifier_service.expect_create_open_message().never();
build_runner(mock_certifier_service).await
build_runner(temp_dir!(), mock_certifier_service).await
};

let open_message_returned = runner
Expand Down Expand Up @@ -1026,7 +1030,7 @@ pub mod tests {
.expect_create_open_message()
.return_once(|_, _| Ok(open_message_created))
.times(1);
build_runner(mock_certifier_service).await
build_runner(temp_dir!(), mock_certifier_service).await
};

let open_message_returned = runner
Expand All @@ -1051,7 +1055,7 @@ pub mod tests {
);

mock_certifier_service.expect_create_open_message().never();
build_runner(mock_certifier_service).await
build_runner(temp_dir!(), mock_certifier_service).await
};

let open_message_returned = runner
Expand All @@ -1078,7 +1082,7 @@ pub mod tests {
);

mock_certifier_service.expect_create_open_message().never();
build_runner(mock_certifier_service).await
build_runner(temp_dir!(), mock_certifier_service).await
};

let open_message_returned = runner
Expand Down Expand Up @@ -1122,7 +1126,7 @@ pub mod tests {
.expect_mark_open_message_if_expired()
.returning(|_| Ok(None));

let runner = build_runner(mock_certifier_service).await;
let runner = build_runner(temp_dir!(), mock_certifier_service).await;

runner
.get_current_non_certified_open_message(&TimePoint::dummy())
Expand Down Expand Up @@ -1203,28 +1207,32 @@ pub mod tests {
#[tokio::test]
async fn is_open_message_outdated_return_false_when_message_is_not_expired_and_no_newer_open_message(
) {
assert!(!is_outdated_returned_when(IsExpired::No, false).await);
assert!(!is_outdated_returned_when(temp_dir!(), IsExpired::No, false).await);
}

#[tokio::test]
async fn is_open_message_outdated_return_true_when_message_is_expired_and_no_newer_open_message(
) {
assert!(is_outdated_returned_when(IsExpired::Yes, false).await);
assert!(is_outdated_returned_when(temp_dir!(), IsExpired::Yes, false).await);
}

#[tokio::test]
async fn is_open_message_outdated_return_true_when_message_is_not_expired_and_exists_newer_open_message(
) {
assert!(is_outdated_returned_when(IsExpired::No, true).await);
assert!(is_outdated_returned_when(temp_dir!(), IsExpired::No, true).await);
}

#[tokio::test]
async fn is_open_message_outdated_return_true_when_message_is_expired_and_exists_newer_open_message(
) {
assert!(is_outdated_returned_when(IsExpired::Yes, true).await);
assert!(is_outdated_returned_when(temp_dir!(), IsExpired::Yes, true).await);
}

async fn is_outdated_returned_when(is_expired: IsExpired, newer_open_message: bool) -> bool {
async fn is_outdated_returned_when(
tmp_path: PathBuf,
is_expired: IsExpired,
newer_open_message: bool,
) -> bool {
let current_time_point = TimePoint {
epoch: Epoch(2),
..TimePoint::dummy()
Expand All @@ -1242,7 +1250,7 @@ pub mod tests {
};

let runner = {
let mut deps = initialize_dependencies!().await;
let mut deps = initialize_dependencies(tmp_path).await;
let mut mock_certifier_service = MockCertifierService::new();

let open_message_current = open_message_to_verify.clone();
Expand Down