Fix TestQUICServer flakiness
This commit is contained in:
parent
99c7370f0b
commit
e0927f202c
|
@ -145,21 +145,30 @@ func TestQUICServer(t *testing.T) {
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
var wg sync.WaitGroup
|
defer cancel()
|
||||||
wg.Add(1)
|
|
||||||
|
var serverReady sync.WaitGroup
|
||||||
|
serverReady.Add(1)
|
||||||
|
|
||||||
|
serverFinished := make(chan struct{}, 1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer cancel()
|
||||||
quicServer(
|
quicServer(
|
||||||
t, udpListener, testTLSServerConfig, testQUICConfig,
|
t, udpListener, testTLSServerConfig, testQUICConfig,
|
||||||
test.dest, test.connectionType, test.metadata, test.message, test.expectedResponse,
|
test.dest, test.connectionType, test.metadata, test.message, test.expectedResponse,
|
||||||
|
&serverReady, serverFinished,
|
||||||
)
|
)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
qc := testQUICConnection(udpListener.LocalAddr(), t)
|
serverReady.Wait()
|
||||||
go qc.Serve(ctx)
|
|
||||||
|
|
||||||
wg.Wait()
|
qc := testQUICConnection(udpListener.LocalAddr(), t)
|
||||||
cancel()
|
err = qc.Serve(ctx)
|
||||||
|
select {
|
||||||
|
case <-serverFinished:
|
||||||
|
default:
|
||||||
|
require.Fail(t, "QUICConnection.Serve() finished before server shut down", err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,6 +195,8 @@ func quicServer(
|
||||||
metadata []quicpogs.Metadata,
|
metadata []quicpogs.Metadata,
|
||||||
message []byte,
|
message []byte,
|
||||||
expectedResponse []byte,
|
expectedResponse []byte,
|
||||||
|
serverReady *sync.WaitGroup,
|
||||||
|
serverFinished chan struct{},
|
||||||
) {
|
) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -193,6 +204,7 @@ func quicServer(
|
||||||
earlyListener, err := quic.Listen(conn, tlsConf, config)
|
earlyListener, err := quic.Listen(conn, tlsConf, config)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
serverReady.Done()
|
||||||
session, err := earlyListener.Accept(ctx)
|
session, err := earlyListener.Accept(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -214,13 +226,14 @@ func quicServer(
|
||||||
}
|
}
|
||||||
|
|
||||||
response := make([]byte, len(expectedResponse))
|
response := make([]byte, len(expectedResponse))
|
||||||
_, err = stream.Read(response)
|
if _, err = stream.Read(response); err != io.EOF {
|
||||||
if err != io.EOF {
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// For now it is an echo server. Verify if the same data is returned.
|
// For now it is an echo server. Verify if the same data is returned.
|
||||||
assert.Equal(t, expectedResponse, response)
|
assert.Equal(t, expectedResponse, response)
|
||||||
|
|
||||||
|
serverFinished <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockOriginProxyWithRequest struct{}
|
type mockOriginProxyWithRequest struct{}
|
||||||
|
|
Loading…
Reference in New Issue