Skip to content

Commit 8a04c47

Browse files
committed
Fix 'address already in use' errors in tests
1 parent b00b498 commit 8a04c47

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

proxy/run_test.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net"
2323
"net/http"
2424
"strconv"
25+
"sync"
2526
"testing"
2627
"time"
2728

@@ -48,6 +49,9 @@ func TestRun_HealthChecks(t *testing.T) {
4849

4950
defer cluster.Shutdown()
5051

52+
var wg sync.WaitGroup
53+
wg.Add(1)
54+
5155
go func() {
5256
rc := Run(ctx, []string{
5357
"--contact-points", testClusterContactPoint,
@@ -56,7 +60,8 @@ func TestRun_HealthChecks(t *testing.T) {
5660
"--http-bind", testProxyHTTPBind,
5761
"--readiness-timeout", "200ms", // Use short timeout for the test
5862
})
59-
require.Equal(t, 0, rc)
63+
assert.Equal(t, 0, rc)
64+
wg.Done()
6065
}()
6166

6267
waitUntil(10*time.Second, func() bool {
@@ -87,6 +92,9 @@ func TestRun_HealthChecks(t *testing.T) {
8792
outage, status = checkReadiness(t)
8893
return outage == 0 && status == http.StatusOK
8994
})
95+
96+
cancel()
97+
wg.Wait()
9098
}
9199

92100
func TestRun_ConfigFileWithPeers(t *testing.T) {
@@ -126,11 +134,15 @@ func TestRun_ConfigFileWithPeers(t *testing.T) {
126134
}},
127135
})
128136

137+
var wg sync.WaitGroup
138+
wg.Add(1)
139+
129140
go func() {
130141
rc := Run(ctx, []string{
131142
"--config", configFileName,
132143
})
133-
require.Equal(t, 0, rc)
144+
assert.Equal(t, 0, rc)
145+
wg.Done()
134146
}()
135147

136148
waitUntil(10*time.Second, func() bool {
@@ -177,6 +189,9 @@ func TestRun_ConfigFileWithPeers(t *testing.T) {
177189
tokens = val.([]*string)
178190
assert.NotEmpty(t, tokens)
179191
assert.Equal(t, "-3074457345618258602", *tokens[0])
192+
193+
cancel()
194+
wg.Wait()
180195
}
181196

182197
func TestRun_ConfigFileWithTokensProvided(t *testing.T) {
@@ -215,11 +230,15 @@ func TestRun_ConfigFileWithTokensProvided(t *testing.T) {
215230
}},
216231
})
217232

233+
var wg sync.WaitGroup
234+
wg.Add(1)
235+
218236
go func() {
219237
rc := Run(ctx, []string{
220238
"--config", configFileName,
221239
})
222-
require.Equal(t, 0, rc)
240+
assert.Equal(t, 0, rc)
241+
wg.Done()
223242
}()
224243

225244
waitUntil(10*time.Second, func() bool {
@@ -260,6 +279,9 @@ func TestRun_ConfigFileWithTokensProvided(t *testing.T) {
260279
assert.NotEmpty(t, tokens)
261280
assert.Equal(t, "42", *tokens[0])
262281
assert.Equal(t, "613", *tokens[1])
282+
283+
cancel()
284+
wg.Wait()
263285
}
264286

265287
func TestRun_ConfigFileWithPeersAndNoRPCAddr(t *testing.T) {

0 commit comments

Comments
 (0)