Skip to content

Commit 95cdf68

Browse files
Improve the repeeated test. (#2736)
1 parent e91d2ce commit 95cdf68

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

linera-service/tests/linera_net_tests.rs

+26-21
Original file line numberDiff line numberDiff line change
@@ -3058,29 +3058,25 @@ async fn test_end_to_end_repeated_transfers(config: impl LineraNetConfig) -> Res
30583058
// Make sure all incoming messages are processed, and get both chains' heights.
30593059
let mut next_height1 = {
30603060
let node_service1 = client1.run_node_service(port1, ProcessInbox::Skip).await?;
3061-
node_service1.process_inbox(&chain_id1).await.unwrap();
3061+
node_service1.process_inbox(&chain_id1).await?;
30623062
let mut chain = node_service1
30633063
.query_node(&format!(
30643064
"query {{ chain(chainId: \"{chain_id1}\") {{ tipState {{ nextBlockHeight }} }} }}"
30653065
))
3066-
.await
3067-
.unwrap();
3068-
serde_json::from_value::<BlockHeight>(chain["chain"]["tipState"]["nextBlockHeight"].take())
3069-
.unwrap()
3066+
.await?;
3067+
serde_json::from_value::<BlockHeight>(chain["chain"]["tipState"]["nextBlockHeight"].take())?
30703068
};
30713069
let mut next_height2 = {
3072-
node_service2.process_inbox(&chain_id2).await.unwrap();
3070+
node_service2.process_inbox(&chain_id2).await?;
30733071
let mut chain = node_service2
30743072
.query_node(&format!(
30753073
"query {{ chain(chainId: \"{chain_id2}\") {{ tipState {{ nextBlockHeight }} }} }}"
30763074
))
3077-
.await
3078-
.unwrap();
3079-
serde_json::from_value::<BlockHeight>(chain["chain"]["tipState"]["nextBlockHeight"].take())
3080-
.unwrap()
3075+
.await?;
3076+
serde_json::from_value::<BlockHeight>(chain["chain"]["tipState"]["nextBlockHeight"].take())?
30813077
};
30823078

3083-
let mut notifications2 = Box::pin(node_service2.notifications(chain_id2).await.unwrap());
3079+
let mut notifications2 = Box::pin(node_service2.notifications(chain_id2).await?);
30843080
let mut block_duration = Duration::ZERO;
30853081
let mut message_duration = Duration::ZERO;
30863082

@@ -3089,8 +3085,7 @@ async fn test_end_to_end_repeated_transfers(config: impl LineraNetConfig) -> Res
30893085
let start_time = Instant::now();
30903086
client1
30913087
.transfer(Amount::from_attos(1), chain_id1, chain_id2)
3092-
.await
3093-
.unwrap();
3088+
.await?;
30943089
let mut got_message = false;
30953090

30963091
// Wait until chain 2 created a block receiving the tokens.
@@ -3099,9 +3094,12 @@ async fn test_end_to_end_repeated_transfers(config: impl LineraNetConfig) -> Res
30993094
let duration = timeout.duration_since(Instant::now());
31003095
let sleep = Box::pin(linera_base::time::timer::sleep(duration));
31013096
let reason = match future::select(notifications2.next(), sleep).await {
3102-
Either::Right(((), _)) | Either::Left((None, _)) => {
3097+
Either::Left((None, _)) => {
31033098
panic!("Failed to receive notification about transfer #{i}.");
31043099
}
3100+
Either::Right(((), _)) => {
3101+
panic!("Timeout to receive notification about transfer #{i}.");
3102+
}
31053103
Either::Left((Some(Err(error)), _)) => {
31063104
panic!("Error waiting for notification about transfer #{i}: {error}");
31073105
}
@@ -3117,7 +3115,10 @@ async fn test_end_to_end_repeated_transfers(config: impl LineraNetConfig) -> Res
31173115
assert_eq!(height, next_height1);
31183116
assert_eq!(origin.sender, chain_id1);
31193117
assert_eq!(origin.medium, Medium::Direct);
3120-
assert!(!got_message, "Duplicate message notification");
3118+
assert!(
3119+
!got_message,
3120+
"Duplicate message notification about transfer #{i}"
3121+
);
31213122
got_message = true;
31223123
next_height1.0 += 1;
31233124
if i >= WARMUP_ITERATIONS {
@@ -3126,14 +3127,19 @@ async fn test_end_to_end_repeated_transfers(config: impl LineraNetConfig) -> Res
31263127
}
31273128
Reason::NewBlock { height, hash } => {
31283129
assert_eq!(height, next_height2);
3129-
assert!(got_message, "Missing message notification");
3130+
assert!(
3131+
got_message,
3132+
"Missing message notification about transfer #{i}"
3133+
);
31303134
next_height2.0 += 1;
31313135
if i >= WARMUP_ITERATIONS {
31323136
block_duration += start_time.elapsed();
31333137
}
31343138
break hash;
31353139
}
3136-
reason @ Reason::NewRound { .. } => panic!("Unexpected notification {reason:?}"),
3140+
reason @ Reason::NewRound { .. } => {
3141+
panic!("Unexpected notification about transfer #{i} {reason:?}")
3142+
}
31373143
}
31383144
};
31393145

@@ -3146,15 +3152,14 @@ async fn test_end_to_end_repeated_transfers(config: impl LineraNetConfig) -> Res
31463152
}} }} }} }} \
31473153
}} }}"
31483154
))
3149-
.await
3150-
.unwrap();
3155+
.await?;
31513156
let mut bundle =
31523157
block2["block"]["value"]["executedBlock"]["block"]["incomingBundles"][0].take();
3153-
let origin = serde_json::from_value::<Origin>(bundle["origin"].take()).unwrap();
3158+
let origin = serde_json::from_value::<Origin>(bundle["origin"].take())?;
31543159
assert_eq!(origin.sender, chain_id1);
31553160
assert_eq!(origin.medium, Medium::Direct);
31563161
let sender_height =
3157-
serde_json::from_value::<BlockHeight>(bundle["bundle"]["height"].take()).unwrap();
3162+
serde_json::from_value::<BlockHeight>(bundle["bundle"]["height"].take())?;
31583163
assert_eq!(sender_height + BlockHeight(1), next_height1);
31593164
}
31603165

0 commit comments

Comments
 (0)