(t *testing.T)
| 409 | } |
| 410 | |
| 411 | func TestRunner_Run_WithErrors(t *testing.T) { |
| 412 | t.Parallel() |
| 413 | |
| 414 | testCtx := testutil.Context(t, testutil.WaitShort) |
| 415 | runCtx, cancel := context.WithCancel(testCtx) |
| 416 | defer cancel() |
| 417 | |
| 418 | mClock := quartz.NewMock(t) |
| 419 | fClient := newFakeClient(t) |
| 420 | fUpdater := newFakeAppStatusUpdater(t) |
| 421 | templateID := uuid.UUID{5, 6, 7, 8} |
| 422 | workspaceName := "test-workspace" |
| 423 | appSlug := "test-app" |
| 424 | |
| 425 | reg := prometheus.NewRegistry() |
| 426 | metrics := NewMetrics(reg, "test") |
| 427 | |
| 428 | connectedWaitGroup := &sync.WaitGroup{} |
| 429 | connectedWaitGroup.Add(1) |
| 430 | startReporting := make(chan struct{}) |
| 431 | |
| 432 | cfg := Config{ |
| 433 | TemplateID: templateID, |
| 434 | WorkspaceName: workspaceName, |
| 435 | AppSlug: appSlug, |
| 436 | ConnectedWaitGroup: connectedWaitGroup, |
| 437 | StartReporting: startReporting, |
| 438 | ReportStatusPeriod: 10 * time.Second, |
| 439 | ReportStatusDuration: 35 * time.Second, |
| 440 | Metrics: metrics, |
| 441 | MetricLabelValues: []string{"test"}, |
| 442 | } |
| 443 | runner := &Runner{ |
| 444 | client: fClient, |
| 445 | updater: fUpdater, |
| 446 | cfg: cfg, |
| 447 | clock: mClock, |
| 448 | randFloat64: func() float64 { return 0.5 }, // not random in tests |
| 449 | reportTimes: make(map[int]time.Time), |
| 450 | } |
| 451 | |
| 452 | tickerTrap := mClock.Trap().NewTimer("reportTaskStatus") |
| 453 | defer tickerTrap.Close() |
| 454 | buildTickerTrap := mClock.Trap().TickerFunc("createExternalWorkspace") |
| 455 | defer buildTickerTrap.Close() |
| 456 | // Run the runner in a goroutine |
| 457 | runErr := make(chan error, 1) |
| 458 | go func() { |
| 459 | runErr <- runner.Run(runCtx, "test-runner", testutil.NewTestLogWriter(t)) |
| 460 | }() |
| 461 | |
| 462 | // complete the build |
| 463 | buildTickerTrap.MustWait(testCtx).MustRelease(testCtx) |
| 464 | w := mClock.Advance(30 * time.Second) |
| 465 | testutil.RequireSend(testCtx, t, fClient.workspaceByOwnerAndNameStatus, codersdk.ProvisionerJobSucceeded) |
| 466 | w.MustWait(testCtx) |
| 467 | |
| 468 | connectedWaitGroup.Wait() |
nothing calls this directly
no test coverage detected