mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix: test: do not block Prometheus port (#13945)
This commit is contained in:
@ -303,7 +303,7 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) {
|
||||
t.Run("PrometheusEnabled", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
prometheusPort := testutil.RandomPort(t)
|
||||
prometheusPort := testutil.RandomPortNoListen(t)
|
||||
|
||||
// Configure CLI client
|
||||
client, admin := coderdenttest.New(t, &coderdenttest.Options{
|
||||
@ -333,18 +333,27 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) {
|
||||
return false
|
||||
}
|
||||
return len(daemons) == 1
|
||||
}, testutil.WaitShort, testutil.IntervalSlow)
|
||||
}, testutil.WaitLong, testutil.IntervalSlow)
|
||||
require.Equal(t, "daemon-with-prometheus", daemons[0].Name)
|
||||
|
||||
// Fetch metrics from Prometheus endpoint
|
||||
var req *http.Request
|
||||
var res *http.Response
|
||||
require.Eventually(t, func() bool {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://127.0.0.1:%d", prometheusPort), nil)
|
||||
assert.NoError(t, err)
|
||||
req, err = http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://127.0.0.1:%d", prometheusPort), nil)
|
||||
if err != nil {
|
||||
t.Logf("unable to create new HTTP request: %s", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
// nolint:bodyclose
|
||||
res, err = http.DefaultClient.Do(req)
|
||||
return err == nil
|
||||
}, testutil.WaitShort, testutil.IntervalFast)
|
||||
if err != nil {
|
||||
t.Logf("unable to call Prometheus endpoint: %s", err.Error())
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}, testutil.WaitShort, testutil.IntervalMedium)
|
||||
defer res.Body.Close()
|
||||
|
||||
// Scan for metric patterns
|
||||
|
Reference in New Issue
Block a user