Skip to content

Commit

Permalink
L1-271: Improve flaky session map test (#1776)
Browse files Browse the repository at this point in the history
# Description

Recently failed there:
https://github.com/Cardinal-Cryptography/aleph-node/actions/runs/9736643972/job/26867555923.
Reason:
```
    ---- session_map::tests::prunes_old_sessions stdout ----
    thread 'session_map::tests::prunes_old_sessions' panicked at finality-aleph/src/session_map.rs:776:13:
    assertion `left == right` failed: Session 0 should be pruned
```
Replaced some delays with `handle.await.unwrap()` and `sender` drop, as
such a drop will cause `SessionMapUpdater` to finish.


## Type of change

Please delete options that are not relevant.

- Bug fix (non-breaking change which fixes an issue) [non-prod code]

# Checklist:
  • Loading branch information
ggawryal authored Jul 2, 2024
1 parent 9dbdf36 commit 0757e1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 128 deletions.
102 changes: 3 additions & 99 deletions Cargo.lock

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

45 changes: 16 additions & 29 deletions finality-aleph/src/session_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn genesis_catch_up() {
let (_sender, receiver) = tracing_unbounded("test", 1_000);
let (_, receiver) = tracing_unbounded("test", 1_000);
let mut mock_provider = MockProvider::new();
let mock_notifier = MockNotifier::new(receiver);

Expand All @@ -564,10 +564,7 @@ mod tests {
let updater = SessionMapUpdater::new(mock_provider, mock_notifier, SessionPeriod(1));
let session_map = updater.readonly_session_map();

let _handle = tokio::spawn(updater.run());

// wait a bit
Delay::new(Duration::from_millis(50)).await;
updater.run().await;

assert_eq!(
session_map.get(SessionId(0)).await,
Expand Down Expand Up @@ -596,10 +593,8 @@ mod tests {
sender.unbounded_send(n).unwrap();
}

let _handle = tokio::spawn(updater.run());

// wait a bit
Delay::new(Duration::from_millis(50)).await;
drop(sender);
updater.run().await;

assert_eq!(
session_map.get(SessionId(0)).await,
Expand All @@ -621,7 +616,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn catch_up() {
let (_sender, receiver) = tracing_unbounded("test", 1_000);
let (_, receiver) = tracing_unbounded("test", 1_000);
let mut mock_provider = MockProvider::new();
let mut mock_notificator = MockNotifier::new(receiver);

Expand All @@ -634,10 +629,7 @@ mod tests {
let updater = SessionMapUpdater::new(mock_provider, mock_notificator, SessionPeriod(1));
let session_map = updater.readonly_session_map();

let _handle = tokio::spawn(updater.run());

// wait a bit
Delay::new(Duration::from_millis(50)).await;
updater.run().await;

assert_eq!(
session_map.get(SessionId(0)).await,
Expand All @@ -659,7 +651,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn catch_up_old_sessions() {
let (_sender, receiver) = tracing_unbounded("test", 1_000);
let (_, receiver) = tracing_unbounded("test", 1_000);
let mut mock_provider = MockProvider::new();
let mut mock_notificator = MockNotifier::new(receiver);

Expand All @@ -672,10 +664,7 @@ mod tests {
let updater = SessionMapUpdater::new(mock_provider, mock_notificator, SessionPeriod(1));
let session_map = updater.readonly_session_map();

let _handle = tokio::spawn(updater.run());

// wait a bit
Delay::new(Duration::from_millis(50)).await;
updater.run().await;

for i in 0..FIRST_THRESHOLD {
assert_eq!(
Expand All @@ -695,7 +684,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn deals_with_database_pruned_authorities() {
let (_sender, receiver) = tracing_unbounded("test", 1_000);
let (_, receiver) = tracing_unbounded("test", 1_000);
let mut mock_provider = MockProvider::new();
let mut mock_notificator = MockNotifier::new(receiver);

Expand All @@ -705,10 +694,7 @@ mod tests {
let updater = SessionMapUpdater::new(mock_provider, mock_notificator, SessionPeriod(1));
let session_map = updater.readonly_session_map();

let _handle = tokio::spawn(updater.run());

// wait a bit
Delay::new(Duration::from_millis(50)).await;
updater.run().await;

for i in 0..5 {
assert_eq!(
Expand Down Expand Up @@ -741,14 +727,14 @@ mod tests {
let updater = SessionMapUpdater::new(mock_provider, mock_notificator, SessionPeriod(1));
let session_map = updater.readonly_session_map();

let _handle = tokio::spawn(updater.run());
let handle = tokio::spawn(updater.run());

for n in 1..FIRST_THRESHOLD {
sender.unbounded_send(n).unwrap();
}

// wait a bit
Delay::new(Duration::from_millis(50)).await;
Delay::new(Duration::from_millis(100)).await;

for i in 0..=FIRST_THRESHOLD {
assert_eq!(
Expand All @@ -762,15 +748,16 @@ mod tests {
assert_eq!(
session_map.get(SessionId(i)).await,
None,
"Session {i:?} should not be avalable yet"
"Session {i:?} should not be available yet"
);
}

for n in FIRST_THRESHOLD..SECOND_THRESHOLD {
sender.unbounded_send(n).unwrap();
}

Delay::new(Duration::from_millis(50)).await;
drop(sender);
handle.await.unwrap();

for i in 0..(FIRST_THRESHOLD - 1) {
assert_eq!(
Expand All @@ -784,7 +771,7 @@ mod tests {
assert_eq!(
session_map.get(SessionId(i)).await,
Some(authority_data_for_session(i)),
"Session {i:?} should be avalable"
"Session {i:?} should be available"
);
}
}
Expand Down

0 comments on commit 0757e1b

Please sign in to comment.