From 384a4b8d50438e55fec2ceb769d546fae89ef871 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 29 Mar 2025 06:04:18 +0100 Subject: [PATCH] proxy: fix test timeout failures during cleanup (#5010) Several proxy tests timed out because it got stuck in the packet read loop after all tests have run. Avoid this by running the `conn.Close()` Cleanup call from `newUPDConnLocalhost` before the timeout handler. Update CI to run these tests. Fixes: 3e87ea3f50df ("proxy: add function to simulate NAT rebinding (#4922)") Relates to: #5009 --- .github/workflows/integration.yml | 2 +- integrationtests/tools/proxy/proxy_test.go | 24 +++++++++------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index dcfc4edac..f762af337 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -47,7 +47,7 @@ jobs: run: echo "GOARCH=386" >> $GITHUB_ENV - run: go version - name: Run tools tests - run: go test ${{ env.RACEFLAG }} -v -timeout 30s -shuffle=on ./integrationtests/tools + run: go test ${{ env.RACEFLAG }} -v -timeout 30s -shuffle=on ./integrationtests/tools/... - name: Run version negotiation tests run: go test ${{ env.RACEFLAG }} -v -timeout 30s -shuffle=on ./integrationtests/versionnegotiation ${{ env.QLOGFLAG }} - name: Run self tests, using QUIC v1 diff --git a/integrationtests/tools/proxy/proxy_test.go b/integrationtests/tools/proxy/proxy_test.go index b53a214b7..4211512ef 100644 --- a/integrationtests/tools/proxy/proxy_test.go +++ b/integrationtests/tools/proxy/proxy_test.go @@ -79,10 +79,17 @@ func readPacketNumber(t *testing.T, b []byte) protocol.PacketNumber { // Set up a dumb UDP server. // In production this would be a QUIC server. func runServer(t *testing.T) (*net.UDPAddr, chan []byte) { - serverConn := newUPDConnLocalhost(t) - - serverReceivedPackets := make(chan []byte, 100) done := make(chan struct{}) + t.Cleanup(func() { + select { + case <-done: + case <-time.After(time.Second): + t.Fatal("timeout") + } + }) + + serverConn := newUPDConnLocalhost(t) + serverReceivedPackets := make(chan []byte, 100) go func() { defer close(done) for { @@ -100,14 +107,6 @@ func runServer(t *testing.T) (*net.UDPAddr, chan []byte) { } }() - t.Cleanup(func() { - select { - case <-done: - case <-time.After(time.Second): - t.Fatalf("timeout") - } - }) - return serverConn.LocalAddr().(*net.UDPAddr), serverReceivedPackets } @@ -433,11 +432,8 @@ func TestProxySwitchConn(t *testing.T) { Data []byte Addr *net.UDPAddr } - serverReceivedPackets := make(chan packet, 1) - done := make(chan struct{}) go func() { - defer close(done) for { buf := make([]byte, 1000) n, addr, err := serverConn.ReadFromUDP(buf)