Skip to content

Commit 40609c2

Browse files
authored
fix: test: do not block Prometheus port (coder#13945)
1 parent c88e416 commit 40609c2

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

enterprise/cli/provisionerdaemons_test.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) {
303303
t.Run("PrometheusEnabled", func(t *testing.T) {
304304
t.Parallel()
305305

306-
prometheusPort := testutil.RandomPort(t)
306+
prometheusPort := testutil.RandomPortNoListen(t)
307307

308308
// Configure CLI client
309309
client, admin := coderdenttest.New(t, &coderdenttest.Options{
@@ -333,18 +333,27 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) {
333333
return false
334334
}
335335
return len(daemons) == 1
336-
}, testutil.WaitShort, testutil.IntervalSlow)
336+
}, testutil.WaitLong, testutil.IntervalSlow)
337337
require.Equal(t, "daemon-with-prometheus", daemons[0].Name)
338338

339339
// Fetch metrics from Prometheus endpoint
340+
var req *http.Request
340341
var res *http.Response
341342
require.Eventually(t, func() bool {
342-
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://127.0.0.1:%d", prometheusPort), nil)
343-
assert.NoError(t, err)
343+
req, err = http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://127.0.0.1:%d", prometheusPort), nil)
344+
if err != nil {
345+
t.Logf("unable to create new HTTP request: %s", err.Error())
346+
return false
347+
}
348+
344349
// nolint:bodyclose
345350
res, err = http.DefaultClient.Do(req)
346-
return err == nil
347-
}, testutil.WaitShort, testutil.IntervalFast)
351+
if err != nil {
352+
t.Logf("unable to call Prometheus endpoint: %s", err.Error())
353+
return false
354+
}
355+
return true
356+
}, testutil.WaitShort, testutil.IntervalMedium)
348357
defer res.Body.Close()
349358

350359
// Scan for metric patterns

0 commit comments

Comments
 (0)