Skip to content

Commit 610fd1a

Browse files
committed
chore(kms-connector): add tests
1 parent f7f29b7 commit 610fd1a

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

kms-connector/crates/gw-listener/src/core/gw_listener.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ mod tests {
408408
#[timeout(Duration::from_secs(90))]
409409
#[tokio::test]
410410
async fn test_reset_filter_stops_listener() {
411-
let (_test_instance, asserter, gw_listener) = test_setup().await;
411+
let (_test_instance, asserter, gw_listener) = test_setup(None).await;
412412

413413
asserter.push_failure(ErrorPayload {
414414
code: -32000,
@@ -419,11 +419,31 @@ mod tests {
419419
gw_listener.subscribe(EventType::KeygenRequest).await;
420420
}
421421

422+
#[rstest::rstest]
423+
#[timeout(Duration::from_secs(90))]
424+
#[tokio::test]
425+
async fn test_failed_catchup_does_not_stop_listener() {
426+
let (mut test_instance, asserter, gw_listener) = test_setup(Some(0)).await;
427+
428+
asserter.push_failure(ErrorPayload {
429+
code: -32002,
430+
message: "request timed out".into(),
431+
data: None,
432+
});
433+
434+
let event_type = EventType::KeygenRequest;
435+
tokio::spawn(gw_listener.subscribe(event_type));
436+
test_instance.wait_for_log("Failed to catch up").await;
437+
test_instance
438+
.wait_for_log(&format!("Waiting for next {event_type}"))
439+
.await;
440+
}
441+
422442
#[rstest::rstest]
423443
#[timeout(Duration::from_secs(90))]
424444
#[tokio::test]
425445
async fn test_listener_ended_by_end_of_any_task() {
426-
let (mut test_instance, _asserter, gw_listener) = test_setup().await;
446+
let (mut test_instance, _asserter, gw_listener) = test_setup(None).await;
427447

428448
// Will stop because some subcription tasks will not be able to init their event filter
429449
gw_listener.start().await;
@@ -439,7 +459,9 @@ mod tests {
439459
RootProvider,
440460
>;
441461

442-
async fn test_setup() -> (TestInstance, Asserter, GatewayListener<MockProvider>) {
462+
async fn test_setup(
463+
from_block_number: Option<u64>,
464+
) -> (TestInstance, Asserter, GatewayListener<MockProvider>) {
443465
let test_instance = TestInstanceBuilder::db_setup().await.unwrap();
444466

445467
// Create a mocked `alloy::Provider`
@@ -453,6 +475,7 @@ mod tests {
453475
let config = Config {
454476
decryption_polling: Duration::from_millis(500),
455477
key_management_polling: Duration::from_millis(500),
478+
from_block_number,
456479
..Default::default()
457480
};
458481
let listener = GatewayListener::new(

0 commit comments

Comments
 (0)