forked from quic-go/quic-go
fix flaky TestServerReceiveQueue (#5249)
This commit is contained in:
@@ -858,7 +858,9 @@ func TestServerGetConfigForClientReject(t *testing.T) {
|
|||||||
func TestServerReceiveQueue(t *testing.T) {
|
func TestServerReceiveQueue(t *testing.T) {
|
||||||
mockCtrl := gomock.NewController(t)
|
mockCtrl := gomock.NewController(t)
|
||||||
acceptConn := make(chan struct{})
|
acceptConn := make(chan struct{})
|
||||||
|
defer close(acceptConn)
|
||||||
tracer, mockTracer := mocklogging.NewMockTracer(mockCtrl)
|
tracer, mockTracer := mocklogging.NewMockTracer(mockCtrl)
|
||||||
|
newConnChan := make(chan struct{}, protocol.MaxServerUnprocessedPackets+2)
|
||||||
server := newTestServer(t, &serverOpts{
|
server := newTestServer(t, &serverOpts{
|
||||||
tracer: tracer,
|
tracer: tracer,
|
||||||
newConn: func(
|
newConn: func(
|
||||||
@@ -882,14 +884,23 @@ func TestServerReceiveQueue(t *testing.T) {
|
|||||||
_ utils.Logger,
|
_ utils.Logger,
|
||||||
_ protocol.Version,
|
_ protocol.Version,
|
||||||
) *wrappedConn {
|
) *wrappedConn {
|
||||||
|
newConnChan <- struct{}{}
|
||||||
<-acceptConn
|
<-acceptConn
|
||||||
return &wrappedConn{testHooks: &connTestHooks{handlePacket: func(receivedPacket) {}}}
|
return &wrappedConn{testHooks: &connTestHooks{handlePacket: func(receivedPacket) {}}}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
conn := newUDPConnLocalhost(t)
|
conn := newUDPConnLocalhost(t)
|
||||||
for range protocol.MaxServerUnprocessedPackets + 1 {
|
for i := range protocol.MaxServerUnprocessedPackets + 1 {
|
||||||
server.handlePacket(getValidInitialPacket(t, conn.LocalAddr(), randConnID(6), randConnID(8)))
|
server.handlePacket(getValidInitialPacket(t, conn.LocalAddr(), randConnID(6), randConnID(8)))
|
||||||
|
// newConn blocks on the acceptConn channel, so this blocks the server's run loop
|
||||||
|
if i == 0 {
|
||||||
|
select {
|
||||||
|
case <-newConnChan:
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
t.Fatal("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
@@ -904,7 +915,6 @@ func TestServerReceiveQueue(t *testing.T) {
|
|||||||
case <-time.After(time.Second):
|
case <-time.After(time.Second):
|
||||||
t.Fatal("timeout")
|
t.Fatal("timeout")
|
||||||
}
|
}
|
||||||
close(acceptConn)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerAccept(t *testing.T) {
|
func TestServerAccept(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user