From 92bba56b87fd06e3b0a5ea42862307718d8c4bd9 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 18 May 2023 09:46:08 +1000 Subject: [PATCH] Relax TestTcpSimultaneousOpen --- ut-holepunching_test.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/ut-holepunching_test.go b/ut-holepunching_test.go index 29be6d1e..5df98bfb 100644 --- a/ut-holepunching_test.go +++ b/ut-holepunching_test.go @@ -153,6 +153,7 @@ func TestTcpSimultaneousOpen(t *testing.T) { makeDialer := func(localPort int, remoteAddr string) func() (net.Conn, error) { dialer := net.Dialer{ LocalAddr: &net.TCPAddr{ + //IP: net.IPv6loopback, Port: localPort, }, } @@ -161,14 +162,28 @@ func TestTcpSimultaneousOpen(t *testing.T) { } } c := qt.New(t) - first, second := randPortPair() - t.Logf("ports are %v and %v", first, second) - err := testSimultaneousOpen( - c.Cleanup, - makeDialer(first, fmt.Sprintf("localhost:%d", second)), - makeDialer(second, fmt.Sprintf("localhost:%d", first)), - ) - c.Assert(err, qt.IsNil) + // I really hate doing this in unit tests, but we would need to pick apart Dialer to get + // perfectly synchronized simultaneous dials. + for range iter.N(10) { + first, second := randPortPair() + t.Logf("ports are %v and %v", first, second) + err := testSimultaneousOpen( + c.Cleanup, + makeDialer(first, fmt.Sprintf("localhost:%d", second)), + makeDialer(second, fmt.Sprintf("localhost:%d", first)), + ) + if err == nil { + return + } + // This proves that the connections are not the same. + if errors.Is(err, errMsgNotReceived) { + t.Fatal(err) + } + // Could be a timing issue, so try again. + t.Log(err) + } + // If we weren't able to get a simultaneous dial to occur, then we can't call it a failure. + t.Skip("couldn't synchronize dials") } func randIntInRange(low, high int) int { -- 2.44.0