Skip to content

fix: test: do not block Prometheus port #13945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions enterprise/cli/provisionerdaemons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,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{
Expand Down Expand Up @@ -199,18 +199,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
Expand Down
Loading