(t *testing.T)
| 283 | } |
| 284 | |
| 285 | func TestRunner_RunMissedUpdate(t *testing.T) { |
| 286 | t.Parallel() |
| 287 | |
| 288 | testCtx := testutil.Context(t, testutil.WaitShort) |
| 289 | runCtx, cancel := context.WithCancel(testCtx) |
| 290 | defer cancel() |
| 291 | |
| 292 | mClock := quartz.NewMock(t) |
| 293 | fClient := newFakeClient(t) |
| 294 | fUpdater := newFakeAppStatusUpdater(t) |
| 295 | templateID := uuid.UUID{5, 6, 7, 8} |
| 296 | workspaceName := "test-workspace" |
| 297 | appSlug := "test-app" |
| 298 | |
| 299 | reg := prometheus.NewRegistry() |
| 300 | metrics := NewMetrics(reg, "test") |
| 301 | |
| 302 | connectedWaitGroup := &sync.WaitGroup{} |
| 303 | connectedWaitGroup.Add(1) |
| 304 | startReporting := make(chan struct{}) |
| 305 | |
| 306 | cfg := Config{ |
| 307 | TemplateID: templateID, |
| 308 | WorkspaceName: workspaceName, |
| 309 | AppSlug: appSlug, |
| 310 | ConnectedWaitGroup: connectedWaitGroup, |
| 311 | StartReporting: startReporting, |
| 312 | ReportStatusPeriod: 10 * time.Second, |
| 313 | ReportStatusDuration: 35 * time.Second, |
| 314 | Metrics: metrics, |
| 315 | MetricLabelValues: []string{"test"}, |
| 316 | } |
| 317 | runner := &Runner{ |
| 318 | client: fClient, |
| 319 | updater: fUpdater, |
| 320 | cfg: cfg, |
| 321 | clock: mClock, |
| 322 | randFloat64: func() float64 { return 0.5 }, // not random in tests |
| 323 | reportTimes: make(map[int]time.Time), |
| 324 | } |
| 325 | |
| 326 | tickerTrap := mClock.Trap().NewTimer("reportTaskStatus") |
| 327 | defer tickerTrap.Close() |
| 328 | sinceTrap := mClock.Trap().Since("watchWorkspaceUpdates") |
| 329 | defer sinceTrap.Close() |
| 330 | buildTickerTrap := mClock.Trap().TickerFunc("createExternalWorkspace") |
| 331 | defer buildTickerTrap.Close() |
| 332 | |
| 333 | // Run the runner in a goroutine |
| 334 | runErr := make(chan error, 1) |
| 335 | go func() { |
| 336 | runErr <- runner.Run(runCtx, "test-runner", testutil.NewTestLogWriter(t)) |
| 337 | }() |
| 338 | |
| 339 | // complete the build |
| 340 | buildTickerTrap.MustWait(testCtx).MustRelease(testCtx) |
| 341 | w := mClock.Advance(30 * time.Second) |
| 342 | testutil.RequireSend(testCtx, t, fClient.workspaceByOwnerAndNameStatus, codersdk.ProvisionerJobSucceeded) |
nothing calls this directly
no test coverage detected