Skip to content

Commit

Permalink
Wait for connection handshake finished in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma233 committed Sep 4, 2023
1 parent 8303909 commit 92ed3fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 0 additions & 2 deletions core/src/tests/default/test_stabilization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ async fn test_stabilization_once() -> Result<()> {
);
} => { unreachable!(); }
_ = async {
sleep(Duration::from_millis(1000)).await;
assert!(swarm1.dht().successors().list()?.contains(&key2.address().into()));
assert!(swarm2.dht().successors().list()?.contains(&key1.address().into()));
let stabilization = Stabilization::new(Arc::clone(&swarm1), 5usize);
Expand Down Expand Up @@ -122,7 +121,6 @@ async fn test_stabilization() -> Result<()> {
);
} => { unreachable!(); }
_ = async {
sleep(Duration::from_millis(1000)).await;
assert!(swarm1.dht().successors().list()?.contains(&key2.address().into()));
assert!(swarm2.dht().successors().list()?.contains(&key1.address().into()));
sleep(Duration::from_millis(10000)).await;
Expand Down
8 changes: 8 additions & 0 deletions core/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ pub async fn manually_establish_connection(swarm1: &Swarm, swarm2: &Swarm) {

assert!(swarm1.get_connection(swarm2.did()).is_some());
assert!(swarm2.get_connection(swarm1.did()).is_some());

// Wait for connectin established
swarm1
.get_connection(swarm2.did())
.unwrap()
.webrtc_wait_for_data_channel_ready()
.await
.unwrap();
}
2 changes: 1 addition & 1 deletion transport/src/connections/native_webrtc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl WebrtcConnection {
.ok_or(Error::WebrtcLocalSdpGenerationError)
}

async fn webrtc_wait_for_data_channel_ready(&self) -> Result<()> {
pub async fn webrtc_wait_for_data_channel_ready(&self) -> Result<()> {
loop {
if matches!(
self.webrtc_connection_state(),
Expand Down

0 comments on commit 92ed3fb

Please sign in to comment.