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 43b0382
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 23 additions & 0 deletions dial_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,26 @@ 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()

ds := NewDialSync(s.dialWorker)

// this should fail
_, err := ds.DialLock(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 = ds.DialLock(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 43b0382

Please sign in to comment.