MCPcopy Index your code
hub / github.com/coder/coder / TestDebugHealth

Function TestDebugHealth

coderd/debug_test.go:29–246  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestDebugHealth(t *testing.T) {
30 t.Parallel()
31 t.Run("OK", func(t *testing.T) {
32 t.Parallel()
33
34 var (
35 calls = atomic.Int64{}
36 ctx, cancel = context.WithTimeout(context.Background(), testutil.WaitShort)
37 sessionToken string
38 client = coderdtest.New(t, &coderdtest.Options{
39 HealthcheckFunc: func(_ context.Context, apiKey string, _ *healthcheck.Progress) *healthsdk.HealthcheckReport {
40 calls.Add(1)
41 assert.Equal(t, sessionToken, apiKey)
42 return &healthsdk.HealthcheckReport{
43 Time: time.Now(),
44 }
45 },
46 HealthcheckRefresh: time.Hour, // Avoid flakes.
47 })
48 _ = coderdtest.CreateFirstUser(t, client)
49 )
50 defer cancel()
51
52 sessionToken = client.SessionToken()
53 for i := 0; i < 10; i++ {
54 res, err := client.Request(ctx, "GET", "/api/v2/debug/health", nil)
55 require.NoError(t, err)
56 _, _ = io.ReadAll(res.Body)
57 res.Body.Close()
58 require.Equal(t, http.StatusOK, res.StatusCode)
59 }
60 // The healthcheck should only have been called once.
61 require.EqualValues(t, 1, calls.Load())
62 })
63
64 t.Run("Forced", func(t *testing.T) {
65 t.Parallel()
66
67 var (
68 calls = atomic.Int64{}
69 ctx, cancel = context.WithTimeout(context.Background(), testutil.WaitShort)
70 sessionToken string
71 client = coderdtest.New(t, &coderdtest.Options{
72 HealthcheckFunc: func(_ context.Context, apiKey string, _ *healthcheck.Progress) *healthsdk.HealthcheckReport {
73 calls.Add(1)
74 assert.Equal(t, sessionToken, apiKey)
75 return &healthsdk.HealthcheckReport{
76 Time: time.Now(),
77 }
78 },
79 HealthcheckRefresh: time.Hour, // Avoid flakes.
80 })
81 _ = coderdtest.CreateFirstUser(t, client)
82 )
83 defer cancel()
84
85 sessionToken = client.SessionToken()
86 for i := 0; i < 10; i++ {

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
FatalMethod · 0.80
RunMethod · 0.65
AddMethod · 0.65
CloseMethod · 0.65
StartMethod · 0.65
EqualMethod · 0.45
SessionTokenMethod · 0.45
RequestMethod · 0.45
ReadAllMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected