MCPcopy Index your code
hub / github.com/coder/coder / TestDetectorHungCanceledJob

Function TestDetectorHungCanceledJob

coderd/jobreaper/detector_test.go:551–602  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

549}
550
551func 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
604func TestDetectorPushesLogs(t *testing.T) {
605 t.Parallel()

Callers

nothing calls this directly

Calls 14

ContextFunction · 0.92
OrganizationFunction · 0.92
UserFunction · 0.92
FileFunction · 0.92
ProvisionerJobFunction · 0.92
TemplateVersionFunction · 0.92
newDetectorTestEnvFunction · 0.85
requireTerminatedJobFunction · 0.85
LogMethod · 0.80
closeMethod · 0.65
AddMethod · 0.65
tickMethod · 0.45

Tested by

no test coverage detected