(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func 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] |
nothing calls this directly
no test coverage detected