fix flaky server accept queue test (#4453)

This commit is contained in:
Marten Seemann
2024-04-21 16:33:41 +02:00
committed by GitHub
parent 86b53a2516
commit eb1c16bd0e

View File

@@ -1201,7 +1201,7 @@ var _ = Describe("Server", func() {
It("rejects new connection attempts if the accept queue is full", func() { It("rejects new connection attempts if the accept queue is full", func() {
connChan := make(chan *MockQUICConn, 1) connChan := make(chan *MockQUICConn, 1)
var wg sync.WaitGroup // to make sure the test fully completes var wg sync.WaitGroup // to make sure the test fully completes
wg.Add(protocol.MaxAcceptQueueSize + 1) wg.Add(protocol.MaxAcceptQueueSize)
serv.baseServer.newConn = func( serv.baseServer.newConn = func(
_ sendConn, _ sendConn,
runner connRunner, runner connRunner,
@@ -1221,12 +1221,11 @@ var _ = Describe("Server", func() {
_ utils.Logger, _ utils.Logger,
_ protocol.Version, _ protocol.Version,
) quicConn { ) quicConn {
defer wg.Done()
ready := make(chan struct{}) ready := make(chan struct{})
close(ready) close(ready)
conn := <-connChan conn := <-connChan
conn.EXPECT().handlePacket(gomock.Any()) conn.EXPECT().handlePacket(gomock.Any())
conn.EXPECT().run() conn.EXPECT().run().Do(func() error { wg.Done(); return nil })
conn.EXPECT().earlyConnReady().Return(ready) conn.EXPECT().earlyConnReady().Return(ready)
conn.EXPECT().Context().Return(context.Background()) conn.EXPECT().Context().Return(context.Background())
return conn return conn
@@ -1242,14 +1241,19 @@ var _ = Describe("Server", func() {
} }
Eventually(serv.baseServer.connQueue).Should(HaveLen(protocol.MaxAcceptQueueSize)) Eventually(serv.baseServer.connQueue).Should(HaveLen(protocol.MaxAcceptQueueSize))
wg.Wait()
wg.Add(1)
rejected := make(chan struct{})
phm.EXPECT().GetStatelessResetToken(gomock.Any()) phm.EXPECT().GetStatelessResetToken(gomock.Any())
phm.EXPECT().AddWithConnID(gomock.Any(), gomock.Any(), gomock.Any()).Return(true) phm.EXPECT().AddWithConnID(gomock.Any(), gomock.Any(), gomock.Any()).Return(true)
conn := NewMockQUICConn(mockCtrl) conn := NewMockQUICConn(mockCtrl)
conn.EXPECT().closeWithTransportError(ConnectionRefused) conn.EXPECT().closeWithTransportError(ConnectionRefused).Do(func(qerr.TransportErrorCode) {
close(rejected)
})
connChan <- conn connChan <- conn
serv.baseServer.handlePacket(getInitialWithRandomDestConnID()) serv.baseServer.handlePacket(getInitialWithRandomDestConnID())
wg.Wait() Eventually(rejected).Should(BeClosed())
}) })
It("doesn't accept new connections if they were closed in the mean time", func() { It("doesn't accept new connections if they were closed in the mean time", func() {