From 27f6c394db45454e0127d8f852dd2b069d535004 Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 31 Mar 2021 23:04:49 +0300 Subject: [PATCH] add TestSelfDial --- dial_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/dial_test.go b/dial_test.go index 86390d6..26bf47c 100644 --- a/dial_test.go +++ b/dial_test.go @@ -651,3 +651,23 @@ func TestDialSimultaneousJoin(t *testing.T) { t.Fatal("no connection from first dial") } } + +func TestDialSelf(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + swarms := makeSwarms(ctx, t, 2) + s1 := swarms[0] + defer s1.Close() + + _, err := s1.DialPeer(ctx, s1.LocalPeer()) + 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") + } +} -- GitLab