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

Function TestProvisionerJobs

coderd/provisionerjobs_test.go:26–397  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestProvisionerJobs(t *testing.T) {
27 t.Parallel()
28
29 t.Run("ProvisionerJobs", func(t *testing.T) {
30 db, ps, sqlDB := dbtestutil.NewDBWithSQLDB(t, dbtestutil.WithDumpOnFailure())
31 client := coderdtest.New(t, &coderdtest.Options{
32 IncludeProvisionerDaemon: true,
33 Database: db,
34 Pubsub: ps,
35 })
36 owner := coderdtest.CreateFirstUser(t, client)
37 templateAdminClient, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.ScopedRoleOrgTemplateAdmin(owner.OrganizationID))
38 memberClient, member := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
39
40 version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
41 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
42 template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)
43
44 workspace := coderdtest.CreateWorkspace(t, client, template.ID)
45 coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
46
47 // Ensure the workspace build job has a different timestamp from
48 // the template version job for sorting, without sleeping.
49 _, err := sqlDB.ExecContext(context.Background(),
50 "UPDATE provisioner_jobs SET created_at = created_at + INTERVAL '2 seconds' WHERE id = $1",
51 workspace.LatestBuild.Job.ID,
52 )
53 require.NoError(t, err)
54
55 // Create a pending job.
56 w := dbgen.Workspace(t, db, database.WorkspaceTable{
57 OrganizationID: owner.OrganizationID,
58 OwnerID: member.ID,
59 TemplateID: template.ID,
60 })
61 wbID := uuid.New()
62 job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{
63 OrganizationID: w.OrganizationID,
64 StartedAt: sql.NullTime{Time: dbtime.Now(), Valid: true},
65 Type: database.ProvisionerJobTypeWorkspaceBuild,
66 Input: json.RawMessage(`{"workspace_build_id":"` + wbID.String() + `"}`),
67 InitiatorID: member.ID,
68 Tags: database.StringMap{"initiatorTest": "true"},
69 })
70 dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{
71 ID: wbID,
72 JobID: job.ID,
73 WorkspaceID: w.ID,
74 TemplateVersionID: version.ID,
75 })
76
77 // Add more jobs than the default limit.
78 for i := range 60 {
79 dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{
80 OrganizationID: owner.OrganizationID,
81 Tags: database.StringMap{"count": strconv.Itoa(i)},
82 InitiatorID: owner.UserID,
83 })

Callers

nothing calls this directly

Calls 15

NewDBWithSQLDBFunction · 0.92
WithDumpOnFailureFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92
WorkspaceFunction · 0.92

Tested by

no test coverage detected