(t *testing.T)
| 549 | } |
| 550 | |
| 551 | func TestDetectorHungCanceledJob(t *testing.T) { |
| 552 | t.Parallel() |
| 553 | |
| 554 | ctx := testutil.Context(t, testutil.WaitLong) |
| 555 | env := newDetectorTestEnv(ctx, t) |
| 556 | defer env.close() |
| 557 | |
| 558 | var ( |
| 559 | now = time.Now() |
| 560 | tenMinAgo = now.Add(-time.Minute * 10) |
| 561 | sixMinAgo = now.Add(-time.Minute * 6) |
| 562 | org = dbgen.Organization(t, env.DB, database.Organization{}) |
| 563 | user = dbgen.User(t, env.DB, database.User{}) |
| 564 | file = dbgen.File(t, env.DB, database.File{}) |
| 565 | |
| 566 | // Template import job. |
| 567 | templateImportJob = dbgen.ProvisionerJob(t, env.DB, env.Pubsub, database.ProvisionerJob{ |
| 568 | CreatedAt: tenMinAgo, |
| 569 | CanceledAt: sql.NullTime{ |
| 570 | Time: tenMinAgo, |
| 571 | Valid: true, |
| 572 | }, |
| 573 | UpdatedAt: sixMinAgo, |
| 574 | StartedAt: sql.NullTime{ |
| 575 | Time: tenMinAgo, |
| 576 | Valid: true, |
| 577 | }, |
| 578 | OrganizationID: org.ID, |
| 579 | InitiatorID: user.ID, |
| 580 | Provisioner: database.ProvisionerTypeEcho, |
| 581 | StorageMethod: database.ProvisionerStorageMethodFile, |
| 582 | FileID: file.ID, |
| 583 | Type: database.ProvisionerJobTypeTemplateVersionImport, |
| 584 | Input: []byte("{}"), |
| 585 | }) |
| 586 | _ = dbgen.TemplateVersion(t, env.DB, database.TemplateVersion{ |
| 587 | OrganizationID: org.ID, |
| 588 | JobID: templateImportJob.ID, |
| 589 | CreatedBy: user.ID, |
| 590 | }) |
| 591 | ) |
| 592 | |
| 593 | t.Log("template import job ID: ", templateImportJob.ID) |
| 594 | |
| 595 | stats := env.tick(ctx, now) |
| 596 | require.NoError(t, stats.Error) |
| 597 | require.Len(t, stats.TerminatedJobIDs, 1) |
| 598 | require.Contains(t, stats.TerminatedJobIDs, templateImportJob.ID) |
| 599 | |
| 600 | // Check that the job was updated. |
| 601 | requireTerminatedJob(ctx, t, env.DB, templateImportJob.ID, now, jobreaper.Hung) |
| 602 | } |
| 603 | |
| 604 | func TestDetectorPushesLogs(t *testing.T) { |
| 605 | t.Parallel() |
nothing calls this directly
no test coverage detected