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

Commit

Permalink
add new TestDialSelf
Browse files Browse the repository at this point in the history
so that we exercise the dialWorker dial to self error path
  • Loading branch information
vyzo committed Apr 1, 2021
1 parent 4a69fa2 commit 967e89f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 20 additions & 0 deletions dial_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,23 @@ func TestStressActiveDial(t *testing.T) {

wg.Wait()
}

func TestDialSelf(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

self := peer.ID("ABC")
s := NewSwarm(ctx, self, nil, nil)
defer s.Close()

_, err := s.DialPeer(ctx, self)
if err != ErrDialToSelf {
t.Fatal("expected error from self dial")
}

// do it twice to make sure we get a new active dial object that fails again
_, err = s.DialPeer(ctx, self)
if err != ErrDialToSelf {
t.Fatal("expected error from self dial")
}
}
8 changes: 1 addition & 7 deletions dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ func TestDialSimultaneousJoin(t *testing.T) {
}
}

func TestDialSelf(t *testing.T) {
func TestDialSelf2(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand All @@ -664,10 +664,4 @@ func TestDialSelf(t *testing.T) {
if err != ErrDialToSelf {
t.Fatal("expected error from self dial")
}

// do it twice to make sure we get a new active dial object that fails again
_, err = s1.DialPeer(ctx, s1.LocalPeer())
if err != ErrDialToSelf {
t.Fatal("expected error from self dial")
}
}

0 comments on commit 967e89f

Please sign in to comment.