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

Fix flaky service test #12472

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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