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

Function TestDetectorMaxJobsPerRun

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

Source from the content-addressed store, hash-verified

744}
745
746func TestDetectorMaxJobsPerRun(t *testing.T) {
747 t.Parallel()
748
749 ctx := testutil.Context(t, testutil.WaitLong)
750 env := newDetectorTestEnv(ctx, t)
751 defer env.close()
752
753 org := dbgen.Organization(t, env.DB, database.Organization{})
754 user := dbgen.User(t, env.DB, database.User{})
755 file := dbgen.File(t, env.DB, database.File{})
756
757 // Create MaxJobsPerRun + 1 hung jobs.
758 now := time.Now()
759 for i := 0; i < jobreaper.MaxJobsPerRun+1; i++ {
760 pj := dbgen.ProvisionerJob(t, env.DB, env.Pubsub, database.ProvisionerJob{
761 CreatedAt: now.Add(-time.Hour),
762 UpdatedAt: now.Add(-time.Hour),
763 StartedAt: sql.NullTime{
764 Time: now.Add(-time.Hour),
765 Valid: true,
766 },
767 OrganizationID: org.ID,
768 InitiatorID: user.ID,
769 Provisioner: database.ProvisionerTypeEcho,
770 StorageMethod: database.ProvisionerStorageMethodFile,
771 FileID: file.ID,
772 Type: database.ProvisionerJobTypeTemplateVersionImport,
773 Input: []byte("{}"),
774 })
775 _ = dbgen.TemplateVersion(t, env.DB, database.TemplateVersion{
776 OrganizationID: org.ID,
777 JobID: pj.ID,
778 CreatedBy: user.ID,
779 })
780 }
781
782 // Make sure that only MaxJobsPerRun jobs are terminated.
783 stats := env.tick(ctx, now)
784 require.NoError(t, stats.Error)
785 require.Len(t, stats.TerminatedJobIDs, jobreaper.MaxJobsPerRun)
786
787 // Run the detector again and make sure that only the remaining job is
788 // terminated.
789 stats = env.tick(ctx, now)
790 require.NoError(t, stats.Error)
791 require.Len(t, stats.TerminatedJobIDs, 1)
792}
793
794// wrapDBAuthz adds our Authorization/RBAC around the given database store, to
795// ensure the reaper has the right permissions to do its work.

Callers

nothing calls this directly

Calls 11

ContextFunction · 0.92
OrganizationFunction · 0.92
UserFunction · 0.92
FileFunction · 0.92
ProvisionerJobFunction · 0.92
TemplateVersionFunction · 0.92
newDetectorTestEnvFunction · 0.85
closeMethod · 0.65
AddMethod · 0.65
tickMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected