fix(tests): fix data races EE-6867 (#11387)

pull/11418/head
andres-portainer 8 months ago committed by GitHub
parent 573f003226
commit bd3440bf3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,6 +1,7 @@
package chisel
import (
"context"
"net"
"net/http"
"testing"
@ -28,12 +29,17 @@ func TestPingAgentPanic(t *testing.T) {
ln, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
require.NoError(t, err)
srv := &http.Server{Handler: mux}
errCh := make(chan error)
go func() {
require.NoError(t, http.Serve(ln, mux))
errCh <- srv.Serve(ln)
}()
s.getTunnelDetails(endpointID)
s.tunnelDetailsMap[endpointID].Port = ln.Addr().(*net.TCPAddr).Port
require.Error(t, s.pingAgent(endpointID))
require.NoError(t, srv.Shutdown(context.Background()))
require.ErrorIs(t, <-errCh, http.ErrServerClosed)
}

@ -138,13 +138,14 @@ func agentServer(t *testing.T) string {
Handler: h,
}
errCh := make(chan error)
go func() {
err := s.Serve(l)
require.ErrorIs(t, err, http.ErrServerClosed)
errCh <- s.Serve(l)
}()
t.Cleanup(func() {
s.Shutdown(context.Background())
require.NoError(t, s.Shutdown(context.Background()))
require.ErrorIs(t, <-errCh, http.ErrServerClosed)
})
return "http://" + l.Addr().String()

Loading…
Cancel
Save