Skip to content

Commit

Permalink
fix(notifier): before_epoch_change
Browse files Browse the repository at this point in the history
  • Loading branch information
qti3e committed May 8, 2024
1 parent b094e67 commit f1773cc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/notifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ async fn before_epoch_change<Q>(
return;
}
},
Some(_) = epoch_changed.recv() => {
changed = epoch_changed.recv() => {
if changed.is_none() {
return;
}

continue;
},
else => {
return;
}
}
}
}
Expand Down
44 changes: 44 additions & 0 deletions core/notifier/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,47 @@ async fn sub_recv_last_works_async_drop() {
let ret = timeout(Duration::from_millis(100), sub1.last()).await;
assert_eq!(ret, Ok(None));
}

#[test]
async fn sub_shutdown_1() {
let ctrl = ShutdownController::new(false);

let (tx, _) = broadcast::channel::<u8>(3);
let mut sub1 = BroadcastSub(tx.subscribe(), ctrl.waiter().into());

ctrl.trigger_shutdown();

let ret = timeout(Duration::from_millis(100), sub1.last()).await;
assert_eq!(ret, Ok(None));
}

#[test]
async fn sub_shutdown_2() {
let ctrl = ShutdownController::new(false);

let (tx, _) = broadcast::channel::<u8>(3);
let mut sub1 = BroadcastSub(tx.subscribe(), ctrl.waiter().into());

let ret = timeout(Duration::from_millis(100), sub1.last()).await;
assert!(ret.is_err(), "To time out");

ctrl.trigger_shutdown();

let ret = timeout(Duration::from_millis(100), sub1.last()).await;
assert_eq!(ret, Ok(None));
}

#[test]
async fn sub_shutdown_3() {
let ctrl = ShutdownController::new(false);
let (tx, _) = broadcast::channel::<u8>(3);
let mut sub1 = BroadcastSub(tx.subscribe(), ctrl.waiter().into());

tokio::spawn(async move {
sleep(Duration::from_micros(10)).await;
ctrl.trigger_shutdown();
});

let ret = timeout(Duration::from_millis(100), sub1.last()).await;
assert_eq!(ret, Ok(None));
}

0 comments on commit f1773cc

Please sign in to comment.