chore(cli): increase healthcheck timeout in TestSupportbundle (#17291)

Fixes https://github.com/coder/internal/issues/272

* Increases healthcheck timeout in tests. This seems to be the most
usual cause of test failures.
* Adds a non-nilness check before caching a healthcheck report.
* Modifies the HTTP response code to 503 (was 404) when no healthcheck
report is available. 503 seems to be a better indicator of the server
state in this case, whereas 404 could be misinterpreted as a typo in the
healthcheck URL.
This commit is contained in:
Cian Johnston
2025-04-09 09:21:17 +01:00
committed by GitHub
parent 8d122aa4ab
commit a8fbe71a22
3 changed files with 11 additions and 6 deletions

View File

@ -50,7 +50,8 @@ func TestSupportBundle(t *testing.T) {
secretValue := uuid.NewString() secretValue := uuid.NewString()
seedSecretDeploymentOptions(t, &dc, secretValue) seedSecretDeploymentOptions(t, &dc, secretValue)
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{ client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
DeploymentValues: dc.Values, DeploymentValues: dc.Values,
HealthcheckTimeout: testutil.WaitSuperLong,
}) })
owner := coderdtest.CreateFirstUser(t, client) owner := coderdtest.CreateFirstUser(t, client)
r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
@ -113,7 +114,8 @@ func TestSupportBundle(t *testing.T) {
secretValue := uuid.NewString() secretValue := uuid.NewString()
seedSecretDeploymentOptions(t, &dc, secretValue) seedSecretDeploymentOptions(t, &dc, secretValue)
client := coderdtest.New(t, &coderdtest.Options{ client := coderdtest.New(t, &coderdtest.Options{
DeploymentValues: dc.Values, DeploymentValues: dc.Values,
HealthcheckTimeout: testutil.WaitSuperLong,
}) })
_ = coderdtest.CreateFirstUser(t, client) _ = coderdtest.CreateFirstUser(t, client)
@ -133,7 +135,8 @@ func TestSupportBundle(t *testing.T) {
secretValue := uuid.NewString() secretValue := uuid.NewString()
seedSecretDeploymentOptions(t, &dc, secretValue) seedSecretDeploymentOptions(t, &dc, secretValue)
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{ client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
DeploymentValues: dc.Values, DeploymentValues: dc.Values,
HealthcheckTimeout: testutil.WaitSuperLong,
}) })
admin := coderdtest.CreateFirstUser(t, client) admin := coderdtest.CreateFirstUser(t, client)
r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{

View File

@ -84,13 +84,15 @@ func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) {
defer cancel() defer cancel()
report := api.HealthcheckFunc(ctx, apiKey) report := api.HealthcheckFunc(ctx, apiKey)
api.healthCheckCache.Store(report) if report != nil { // Only store non-nil reports.
api.healthCheckCache.Store(report)
}
return report, nil return report, nil
}) })
select { select {
case <-ctx.Done(): case <-ctx.Done():
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{ httpapi.Write(ctx, rw, http.StatusServiceUnavailable, codersdk.Response{
Message: "Healthcheck is in progress and did not complete in time. Try again in a few seconds.", Message: "Healthcheck is in progress and did not complete in time. Try again in a few seconds.",
}) })
return return

View File

@ -117,7 +117,7 @@ func TestDebugHealth(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer res.Body.Close() defer res.Body.Close()
_, _ = io.ReadAll(res.Body) _, _ = io.ReadAll(res.Body)
require.Equal(t, http.StatusNotFound, res.StatusCode) require.Equal(t, http.StatusServiceUnavailable, res.StatusCode)
}) })
t.Run("Refresh", func(t *testing.T) { t.Run("Refresh", func(t *testing.T) {