Skip to content

Commit a8fbe71

Browse files
authored
chore(cli): increase healthcheck timeout in TestSupportbundle (#17291)
Fixes coder/internal#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.
1 parent 8d122aa commit a8fbe71

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

cli/support_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ func TestSupportBundle(t *testing.T) {
5050
secretValue := uuid.NewString()
5151
seedSecretDeploymentOptions(t, &dc, secretValue)
5252
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
53-
DeploymentValues: dc.Values,
53+
DeploymentValues: dc.Values,
54+
HealthcheckTimeout: testutil.WaitSuperLong,
5455
})
5556
owner := coderdtest.CreateFirstUser(t, client)
5657
r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
@@ -113,7 +114,8 @@ func TestSupportBundle(t *testing.T) {
113114
secretValue := uuid.NewString()
114115
seedSecretDeploymentOptions(t, &dc, secretValue)
115116
client := coderdtest.New(t, &coderdtest.Options{
116-
DeploymentValues: dc.Values,
117+
DeploymentValues: dc.Values,
118+
HealthcheckTimeout: testutil.WaitSuperLong,
117119
})
118120
_ = coderdtest.CreateFirstUser(t, client)
119121

@@ -133,7 +135,8 @@ func TestSupportBundle(t *testing.T) {
133135
secretValue := uuid.NewString()
134136
seedSecretDeploymentOptions(t, &dc, secretValue)
135137
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
136-
DeploymentValues: dc.Values,
138+
DeploymentValues: dc.Values,
139+
HealthcheckTimeout: testutil.WaitSuperLong,
137140
})
138141
admin := coderdtest.CreateFirstUser(t, client)
139142
r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{

coderd/debug.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) {
8484
defer cancel()
8585

8686
report := api.HealthcheckFunc(ctx, apiKey)
87-
api.healthCheckCache.Store(report)
87+
if report != nil { // Only store non-nil reports.
88+
api.healthCheckCache.Store(report)
89+
}
8890
return report, nil
8991
})
9092

9193
select {
9294
case <-ctx.Done():
93-
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
95+
httpapi.Write(ctx, rw, http.StatusServiceUnavailable, codersdk.Response{
9496
Message: "Healthcheck is in progress and did not complete in time. Try again in a few seconds.",
9597
})
9698
return

coderd/debug_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestDebugHealth(t *testing.T) {
117117
require.NoError(t, err)
118118
defer res.Body.Close()
119119
_, _ = io.ReadAll(res.Body)
120-
require.Equal(t, http.StatusNotFound, res.StatusCode)
120+
require.Equal(t, http.StatusServiceUnavailable, res.StatusCode)
121121
})
122122

123123
t.Run("Refresh", func(t *testing.T) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy