Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit a80b2fe

Browse files
committed
Fix flaky test TestCompareTraceQueryResponse
The test occasionally fails with: ``` Received unexpected error: http get: Get "http://localhost:9201/api/services": dial tcp [::1]:9201: connect: connection refused ``` The server listen and client connect, which run in separate goroutines, race against one another. Occasionally, the client connect is faster than the server listen, causing the above error. By moving the call to `net.Listen` out of the goroutine, we ensure that both threads of execution must wait on the socket listen to complete before proceeding, eliminating the race.
1 parent c50b6c9 commit a80b2fe

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/tests/end_to_end_tests/trace_query_integration_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ func TestCompareTraceQueryResponse(t *testing.T) {
102102
jaegerQuery := jaegerquery.New(pgxconn.NewPgxConn(db), &jaegerquery.DefaultConfig)
103103
promscaleJaeger.ExtendQueryAPIs(router, pgxconn.NewPgxConn(db), jaegerQuery)
104104

105+
// Bind to the server port. This must be outside of the goroutine below
106+
// to prevent the server bind and client connect from racing.
107+
listener, err := net.Listen("tcp", ":0")
108+
require.NoError(t, err)
109+
105110
go func() {
106-
listener, err := net.Listen("tcp", ":9201")
107-
require.NoError(t, err)
108111
server := http.Server{Handler: router}
109112
require.NoError(t, server.Serve(listener))
110113
}()
111114

112115
// Create client for querying and comparing results.
113-
promscaleClient := httpClient{"http://localhost:9201"}
116+
promscaleClient := httpClient{"http://" + listener.Addr().String()}
114117
jaegerResponse, err := loadJaegerQueryResponses()
115118
require.NoError(t, err)
116119

0 commit comments

Comments
 (0)