MCPcopy Create free account
hub / github.com/coder/coder / TestAppHealth_Healthy

Function TestAppHealth_Healthy

agent/apphealth_test.go:25–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestAppHealth_Healthy(t *testing.T) {
26 t.Parallel()
27 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
28 defer cancel()
29 apps := []codersdk.WorkspaceApp{
30 {
31 ID: uuid.UUID{1},
32 Slug: "app1",
33 Healthcheck: codersdk.Healthcheck{},
34 Health: codersdk.WorkspaceAppHealthDisabled,
35 },
36 {
37 ID: uuid.UUID{2},
38 Slug: "app2",
39 Healthcheck: codersdk.Healthcheck{
40 // URL: We don't set the URL for this test because the setup will
41 // create a httptest server for us and set it for us.
42 Interval: 1,
43 Threshold: 1,
44 },
45 Health: codersdk.WorkspaceAppHealthInitializing,
46 },
47 {
48 ID: uuid.UUID{3},
49 Slug: "app3",
50 Healthcheck: codersdk.Healthcheck{
51 Interval: 2,
52 Threshold: 1,
53 },
54 Health: codersdk.WorkspaceAppHealthInitializing,
55 },
56 }
57 checks2 := 0
58 checks3 := 0
59 handlers := []http.Handler{
60 nil,
61 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
62 checks2++
63 httpapi.Write(r.Context(), w, http.StatusOK, nil)
64 }),
65 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
66 checks3++
67 httpapi.Write(r.Context(), w, http.StatusOK, nil)
68 }),
69 }
70 mClock := quartz.NewMock(t)
71 healthcheckTrap := mClock.Trap().TickerFunc("healthcheck")
72 defer healthcheckTrap.Close()
73 reportTrap := mClock.Trap().TickerFunc("report")
74 defer reportTrap.Close()
75
76 fakeAPI, closeFn := setupAppReporter(ctx, t, slices.Clone(apps), handlers, mClock)
77 defer closeFn()
78 healthchecksStarted := make([]string, 2)
79 for i := 0; i < 2; i++ {
80 c := healthcheckTrap.MustWait(ctx)
81 c.MustRelease(ctx)
82 healthchecksStarted[i] = c.Tags[1]

Callers

nothing calls this directly

Calls 11

WriteFunction · 0.92
TryReceiveFunction · 0.92
setupAppReporterFunction · 0.85
applyUpdateFunction · 0.85
AppHealthChMethod · 0.80
GetUpdatesMethod · 0.80
ContextMethod · 0.65
CloseMethod · 0.65
CloneMethod · 0.45
EqualMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected