forked from quic-go/quic-go
fix flaky TestDial test (#5029)
* give the kernel some time to free the socket * remove problematic assertion The listen function is started in a Goroutine, hence we can’t be sure it’s already started.
This commit is contained in:
@@ -67,7 +67,6 @@ func testDial(t *testing.T,
|
|||||||
|
|
||||||
_, addr, err := server.ReadFrom(make([]byte, 1500))
|
_, addr, err := server.ReadFrom(make([]byte, 1500))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, areTransportsRunning())
|
|
||||||
cancel()
|
cancel()
|
||||||
select {
|
select {
|
||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
@@ -76,20 +75,30 @@ func testDial(t *testing.T,
|
|||||||
t.Fatal("timeout")
|
t.Fatal("timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if shouldCloseConn {
|
||||||
// The socket that the client used for dialing should be closed now.
|
// The socket that the client used for dialing should be closed now.
|
||||||
// Binding to the same address would error if the address was still in use.
|
// Binding to the same address would error if the address was still in use.
|
||||||
|
require.Eventually(t, func() bool {
|
||||||
conn, err := net.ListenUDP("udp", addr.(*net.UDPAddr))
|
conn, err := net.ListenUDP("udp", addr.(*net.UDPAddr))
|
||||||
if shouldCloseConn {
|
if err != nil {
|
||||||
require.NoError(t, err)
|
return false
|
||||||
defer conn.Close()
|
}
|
||||||
} else {
|
conn.Close()
|
||||||
|
return true
|
||||||
|
}, scaleDuration(200*time.Millisecond), scaleDuration(10*time.Millisecond))
|
||||||
|
require.False(t, areTransportsRunning())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// The socket that the client used for dialing should not be closed now.
|
||||||
|
// Binding to the same address will error if the address was still in use.
|
||||||
|
_, err = net.ListenUDP("udp", addr.(*net.UDPAddr))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
require.ErrorContains(t, err, "bind: Only one usage of each socket address")
|
require.ErrorContains(t, err, "bind: Only one usage of each socket address")
|
||||||
} else {
|
} else {
|
||||||
require.ErrorContains(t, err, "address already in use")
|
require.ErrorContains(t, err, "address already in use")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
require.False(t, areTransportsRunning())
|
require.False(t, areTransportsRunning())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user