(t *testing.T)
| 511 | } |
| 512 | |
| 513 | func TestRunner_Run_BuildFailed(t *testing.T) { |
| 514 | t.Parallel() |
| 515 | |
| 516 | testCtx := testutil.Context(t, testutil.WaitShort) |
| 517 | runCtx, cancel := context.WithCancel(testCtx) |
| 518 | defer cancel() |
| 519 | |
| 520 | mClock := quartz.NewMock(t) |
| 521 | fClient := newFakeClient(t) |
| 522 | fUpdater := newFakeAppStatusUpdater(t) |
| 523 | templateID := uuid.UUID{5, 6, 7, 8} |
| 524 | workspaceName := "test-workspace" |
| 525 | appSlug := "test-app" |
| 526 | |
| 527 | reg := prometheus.NewRegistry() |
| 528 | metrics := NewMetrics(reg, "test") |
| 529 | |
| 530 | connectedWaitGroup := &sync.WaitGroup{} |
| 531 | connectedWaitGroup.Add(1) |
| 532 | startReporting := make(chan struct{}) |
| 533 | |
| 534 | cfg := Config{ |
| 535 | TemplateID: templateID, |
| 536 | WorkspaceName: workspaceName, |
| 537 | AppSlug: appSlug, |
| 538 | ConnectedWaitGroup: connectedWaitGroup, |
| 539 | StartReporting: startReporting, |
| 540 | ReportStatusPeriod: 10 * time.Second, |
| 541 | ReportStatusDuration: 35 * time.Second, |
| 542 | Metrics: metrics, |
| 543 | MetricLabelValues: []string{"test"}, |
| 544 | } |
| 545 | runner := &Runner{ |
| 546 | client: fClient, |
| 547 | updater: fUpdater, |
| 548 | cfg: cfg, |
| 549 | clock: mClock, |
| 550 | randFloat64: func() float64 { return 0.5 }, // not random in tests |
| 551 | reportTimes: make(map[int]time.Time), |
| 552 | } |
| 553 | |
| 554 | buildTickerTrap := mClock.Trap().TickerFunc("createExternalWorkspace") |
| 555 | defer buildTickerTrap.Close() |
| 556 | // Run the runner in a goroutine |
| 557 | runErr := make(chan error, 1) |
| 558 | go func() { |
| 559 | runErr <- runner.Run(runCtx, "test-runner", testutil.NewTestLogWriter(t)) |
| 560 | }() |
| 561 | |
| 562 | // complete the build |
| 563 | buildTickerTrap.MustWait(testCtx).MustRelease(testCtx) |
| 564 | w := mClock.Advance(30 * time.Second) |
| 565 | testutil.RequireSend(testCtx, t, fClient.workspaceByOwnerAndNameStatus, codersdk.ProvisionerJobFailed) |
| 566 | w.MustWait(testCtx) |
| 567 | |
| 568 | connectedWaitGroup.Wait() |
| 569 | |
| 570 | // Wait for the runner to complete |
nothing calls this directly
no test coverage detected