(t *testing.T)
| 162 | } |
| 163 | |
| 164 | func TestRunner_Run(t *testing.T) { |
| 165 | t.Parallel() |
| 166 | |
| 167 | ctx := testutil.Context(t, testutil.WaitShort) |
| 168 | |
| 169 | mClock := quartz.NewMock(t) |
| 170 | fClient := newFakeClient(t) |
| 171 | fUpdater := newFakeAppStatusUpdater(t) |
| 172 | templateID := uuid.UUID{5, 6, 7, 8} |
| 173 | workspaceName := "test-workspace" |
| 174 | appSlug := "test-app" |
| 175 | |
| 176 | reg := prometheus.NewRegistry() |
| 177 | metrics := NewMetrics(reg, "test") |
| 178 | |
| 179 | connectedWaitGroup := &sync.WaitGroup{} |
| 180 | connectedWaitGroup.Add(1) |
| 181 | startReporting := make(chan struct{}) |
| 182 | |
| 183 | cfg := Config{ |
| 184 | TemplateID: templateID, |
| 185 | WorkspaceName: workspaceName, |
| 186 | AppSlug: appSlug, |
| 187 | ConnectedWaitGroup: connectedWaitGroup, |
| 188 | StartReporting: startReporting, |
| 189 | ReportStatusPeriod: 10 * time.Second, |
| 190 | ReportStatusDuration: 35 * time.Second, |
| 191 | Metrics: metrics, |
| 192 | MetricLabelValues: []string{"test"}, |
| 193 | } |
| 194 | runner := &Runner{ |
| 195 | client: fClient, |
| 196 | updater: fUpdater, |
| 197 | cfg: cfg, |
| 198 | clock: mClock, |
| 199 | randFloat64: func() float64 { return 0.5 }, // not random in tests |
| 200 | reportTimes: make(map[int]time.Time), |
| 201 | } |
| 202 | |
| 203 | reportTickerTrap := mClock.Trap().NewTimer("reportTaskStatus") |
| 204 | defer reportTickerTrap.Close() |
| 205 | sinceTrap := mClock.Trap().Since("watchWorkspaceUpdates") |
| 206 | defer sinceTrap.Close() |
| 207 | buildTickerTrap := mClock.Trap().TickerFunc("createExternalWorkspace") |
| 208 | defer buildTickerTrap.Close() |
| 209 | |
| 210 | // Run the runner in a goroutine |
| 211 | runErr := make(chan error, 1) |
| 212 | go func() { |
| 213 | runErr <- runner.Run(ctx, "test-runner", testutil.NewTestLogWriter(t)) |
| 214 | }() |
| 215 | |
| 216 | // complete the build |
| 217 | buildTickerTrap.MustWait(ctx).MustRelease(ctx) |
| 218 | w := mClock.Advance(30 * time.Second) |
| 219 | testutil.RequireSend(ctx, t, fClient.workspaceByOwnerAndNameStatus, codersdk.ProvisionerJobSucceeded) |
| 220 | w.MustWait(ctx) |
| 221 |
nothing calls this directly
no test coverage detected