Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix flaky service test (#12472)
Browse files Browse the repository at this point in the history
Sometimes `NotificationStreamOpenened` would be received for the
other protocol before `SyncConnected` was received so when the
connection was closed, an incorrect event was read from the event
stream.
  • Loading branch information
altonen committed Oct 11, 2022
1 parent 60be7b8 commit 6072b90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 4 additions & 0 deletions client/network/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ pub struct NonDefaultSetConfig {
/// `sc_network::protocol::event::Event::NotificationStreamOpened::negotiated_fallback`
pub fallback_names: Vec<protocol::ProtocolName>,
/// Handshake of the protocol
///
/// NOTE: Currently custom handshakes are not fully supported. See issue #5685 for more
/// details. This field is temporarily used to allow moving the hardcoded block announcement
/// protocol out of `protocol.rs`.
pub handshake: Option<NotificationHandshake>,
/// Maximum allowed size of single notifications.
pub max_notification_size: u64,
Expand Down
26 changes: 14 additions & 12 deletions client/network/src/service/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,19 +637,21 @@ async fn disconnect_sync_peer_using_block_announcement_protocol_name() {
..config::NetworkConfiguration::new_local()
});

loop {
match events_stream1.next().await.unwrap() {
Event::NotificationStreamOpened { .. } => break,
_ => {},
};
async fn wait_for_events(stream: &mut (impl Stream<Item = Event> + std::marker::Unpin)) {
let mut notif_received = false;
let mut sync_received = false;

while !notif_received || !sync_received {
match stream.next().await.unwrap() {
Event::NotificationStreamOpened { .. } => notif_received = true,
Event::SyncConnected { .. } => sync_received = true,
_ => {},
};
}
}

loop {
match events_stream2.next().await.unwrap() {
Event::NotificationStreamOpened { .. } => break,
_ => {},
};
}
wait_for_events(&mut events_stream1).await;
wait_for_events(&mut events_stream2).await;

// disconnect peer using `PROTOCOL_NAME`, verify `NotificationStreamClosed` event is emitted
node2.disconnect_peer(node1.local_peer_id(), PROTOCOL_NAME.into());
Expand All @@ -659,7 +661,7 @@ async fn disconnect_sync_peer_using_block_announcement_protocol_name() {
));
let _ = events_stream2.next().await; // ignore the reopen event

// now disconnect using the block announcement protocol, verify that `SyncDisconnected` is
// now disconnect using `BLOCK_ANNOUNCE_PROTO_NAME`, verify that `SyncDisconnected` is
// emitted
node2.disconnect_peer(node1.local_peer_id(), BLOCK_ANNOUNCE_PROTO_NAME.into());
assert!(std::matches!(events_stream2.next().await, Some(Event::SyncDisconnected { .. })));
Expand Down

0 comments on commit 6072b90

Please sign in to comment.