Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
more tests after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Schwartz committed Apr 15, 2021
1 parent f0aa4f2 commit f4b401f
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,19 +583,23 @@ func TestDialSimultaneousJoin(t *testing.T) {
go acceptAndHang(s2silentListener)

connch := make(chan network.Conn, 512)
errs := make(chan error, 2)

// start a dial to s2 through the silent addr
go func() {
s1.Peerstore().AddAddrs(s2.LocalPeer(), s2silentAddrs, peerstore.PermanentAddrTTL)

c, err := s1.DialPeer(ctx, s2.LocalPeer())
if err != nil {
t.Fatal(err)
errs <- err
connch <- nil
return
}

t.Logf("first dial succedded; conn: %+v", c)

connch <- c
errs <- nil
}()

// wait a bit for the dial to take hold
Expand All @@ -605,18 +609,22 @@ func TestDialSimultaneousJoin(t *testing.T) {
go func() {
s2addrs, err := s2.InterfaceListenAddresses()
if err != nil {
t.Fatal(err)
errs <- err
return
}
s1.Peerstore().AddAddrs(s2.LocalPeer(), s2addrs[:1], peerstore.PermanentAddrTTL)

c, err := s1.DialPeer(ctx, s2.LocalPeer())
if err != nil {
t.Fatal(err)
errs <- err
connch <- nil
return
}

t.Logf("second dial succedded; conn: %+v", c)

connch <- c
errs <- nil
}()

// wait for the second dial to finish
Expand All @@ -626,16 +634,27 @@ func TestDialSimultaneousJoin(t *testing.T) {
go func() {
c, err := s1.DialPeer(ctx, s2.LocalPeer())
if err != nil {
t.Fatal(err)
errs <- err
connch <- nil
return
}

t.Logf("third dial succedded; conn: %+v", c)

connch <- c
errs <- nil
}()

c3 := <-connch

// raise any errors from the two
for i := 0; i < 3; i++ {
err := <-errs
if err != nil {
t.Fatal(err)
}
}

if c2 != c3 {
t.Fatal("expected c2 and c3 to be the same")
}
Expand Down

0 comments on commit f4b401f

Please sign in to comment.