Skip to content

Commit 8ef2e2f

Browse files
committed
Don't open 2 channels with same peer in tests
1 parent f1e0eb3 commit 8ef2e2f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/js_interop.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,25 +450,28 @@ async fn on_replication_connection(
450450
use tracing::info;
451451

452452
let mut protocol = ProtocolBuilder::new(is_initiator).connect(stream.compat());
453+
let mut channel_opened = false;
453454
while let Some(event) = protocol.next().await {
454455
let event = event?;
455456
match event {
456457
Event::Handshake(_) => {
457458
info!("Event::Handshake");
458-
if is_initiator {
459+
if is_initiator && !channel_opened {
459460
protocol.open(*hypercore.key()).await?;
461+
channel_opened = true;
460462
}
461463
}
462464
Event::DiscoveryKey(dkey) => {
463465
info!("Event::DiscoveryKey");
464-
if hypercore.discovery_key == dkey {
466+
if hypercore.discovery_key == dkey && !channel_opened {
465467
protocol.open(*hypercore.key()).await?;
468+
channel_opened = true;
466469
} else {
467470
panic!("Invalid discovery key");
468471
}
469472
}
470473
Event::Channel(channel) => {
471-
info!("Event::Channel");
474+
info!("Event::Channel is_initiator = {is_initiator}");
472475
hypercore.on_replication_peer(channel);
473476
}
474477
Event::Close(_dkey) => {

0 commit comments

Comments
 (0)