Skip to content

Commit e0ddb49

Browse files
committed
Attempt to fix CI flakiness for upkeep services tests
It seems that the log is not always fully written when the assertion are run, making them fails. This should ensure that the logger is dropped, flushin their files, before the assertions are run.
1 parent 3caf4de commit e0ddb49

File tree

2 files changed

+41
-40
lines changed

2 files changed

+41
-40
lines changed

mithril-aggregator/src/services/upkeep.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,17 @@ mod tests {
136136
let main_db_connection = main_db_file_connection(&main_db_path).unwrap();
137137
let cardano_tx_connection = cardano_tx_db_file_connection(&ctx_db_path).unwrap();
138138

139-
let service = AggregatorUpkeepService::new(
140-
Arc::new(main_db_connection),
141-
Arc::new(SqliteConnectionPool::build_from_connection(
142-
cardano_tx_connection,
143-
)),
144-
Arc::new(SignedEntityTypeLock::default()),
145-
TestLogger::file(&log_path),
146-
);
147-
148-
// Separate block to ensure the log is flushed after run
139+
// Separate block to force log flushing by dropping the service that owns the logger
149140
{
141+
let service = AggregatorUpkeepService::new(
142+
Arc::new(main_db_connection),
143+
Arc::new(SqliteConnectionPool::build_from_connection(
144+
cardano_tx_connection,
145+
)),
146+
Arc::new(SignedEntityTypeLock::default()),
147+
TestLogger::file(&log_path),
148+
);
149+
150150
service.run().await.expect("Upkeep service failed");
151151
}
152152

@@ -175,18 +175,18 @@ mod tests {
175175
.join("upkeep.log");
176176

177177
let signed_entity_type_lock = Arc::new(SignedEntityTypeLock::default());
178-
let service = AggregatorUpkeepService::new(
179-
Arc::new(main_db_connection().unwrap()),
180-
Arc::new(SqliteConnectionPool::build(1, cardano_tx_db_connection).unwrap()),
181-
signed_entity_type_lock.clone(),
182-
TestLogger::file(&log_path),
183-
);
178+
signed_entity_type_lock
179+
.lock(SignedEntityTypeDiscriminants::CardanoTransactions)
180+
.await;
184181

185-
// Separate block to ensure the log is flushed after run
182+
// Separate block to force log flushing by dropping the service that owns the logger
186183
{
187-
signed_entity_type_lock
188-
.lock(SignedEntityTypeDiscriminants::CardanoTransactions)
189-
.await;
184+
let service = AggregatorUpkeepService::new(
185+
Arc::new(main_db_connection().unwrap()),
186+
Arc::new(SqliteConnectionPool::build(1, cardano_tx_db_connection).unwrap()),
187+
signed_entity_type_lock.clone(),
188+
TestLogger::file(&log_path),
189+
);
190190
service.run().await.expect("Upkeep service failed");
191191
}
192192

mithril-signer/src/upkeep_service.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,17 @@ mod tests {
136136
let main_db_connection = main_db_file_connection(&main_db_path).unwrap();
137137
let cardano_tx_connection = cardano_tx_db_file_connection(&ctx_db_path).unwrap();
138138

139-
let service = SignerUpkeepService::new(
140-
Arc::new(main_db_connection),
141-
Arc::new(SqliteConnectionPool::build_from_connection(
142-
cardano_tx_connection,
143-
)),
144-
Arc::new(SignedEntityTypeLock::default()),
145-
TestLogger::file(&log_path),
146-
);
147-
148-
// Separate block to ensure the log is flushed after run
139+
// Separate block to force log flushing by dropping the service that owns the logger
149140
{
141+
let service = SignerUpkeepService::new(
142+
Arc::new(main_db_connection),
143+
Arc::new(SqliteConnectionPool::build_from_connection(
144+
cardano_tx_connection,
145+
)),
146+
Arc::new(SignedEntityTypeLock::default()),
147+
TestLogger::file(&log_path),
148+
);
149+
150150
service.run().await.expect("Upkeep service failed");
151151
}
152152

@@ -175,18 +175,19 @@ mod tests {
175175
.join("upkeep.log");
176176

177177
let signed_entity_type_lock = Arc::new(SignedEntityTypeLock::default());
178-
let service = SignerUpkeepService::new(
179-
Arc::new(main_db_connection().unwrap()),
180-
Arc::new(SqliteConnectionPool::build(1, cardano_tx_db_connection).unwrap()),
181-
signed_entity_type_lock.clone(),
182-
TestLogger::file(&log_path),
183-
);
178+
signed_entity_type_lock
179+
.lock(SignedEntityTypeDiscriminants::CardanoTransactions)
180+
.await;
184181

185-
// Separate block to ensure the log is flushed after run
182+
// Separate block to force log flushing by dropping the service that owns the logger
186183
{
187-
signed_entity_type_lock
188-
.lock(SignedEntityTypeDiscriminants::CardanoTransactions)
189-
.await;
184+
let service = SignerUpkeepService::new(
185+
Arc::new(main_db_connection().unwrap()),
186+
Arc::new(SqliteConnectionPool::build(1, cardano_tx_db_connection).unwrap()),
187+
signed_entity_type_lock.clone(),
188+
TestLogger::file(&log_path),
189+
);
190+
190191
service.run().await.expect("Upkeep service failed");
191192
}
192193

0 commit comments

Comments
 (0)