|
8 | 8 | "testing"
|
9 | 9 | "time"
|
10 | 10 |
|
11 |
| -"github.com/aws/smithy-go/ptr" |
12 | 11 | "github.com/google/uuid"
|
13 | 12 | "github.com/stretchr/testify/assert"
|
14 | 13 | "github.com/stretchr/testify/require"
|
@@ -36,102 +35,86 @@ func TestProvisionerJobs(t *testing.T) {
|
36 | 35 | templateAdminClient,templateAdmin:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID,rbac.ScopedRoleOrgTemplateAdmin(owner.OrganizationID))
|
37 | 36 | memberClient,member:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID)
|
38 | 37 |
|
39 |
| -// Create initial resources with a running provisioner. |
40 |
| -firstProvisioner:=coderdtest.NewTaggedProvisionerDaemon(t,coderdAPI,"default-provisioner",map[string]string{"owner":"","scope":"organization"}) |
41 |
| -t.Cleanup(func() {_=firstProvisioner.Close() }) |
42 |
| -version:=coderdtest.CreateTemplateVersion(t,client,owner.OrganizationID,completeWithAgent()) |
43 |
| -coderdtest.AwaitTemplateVersionJobCompleted(t,client,version.ID) |
44 |
| -template:=coderdtest.CreateTemplate(t,client,owner.OrganizationID,version.ID,func(req*codersdk.CreateTemplateRequest) { |
45 |
| -req.AllowUserCancelWorkspaceJobs=ptr.Bool(true) |
| 38 | +// Create minimal template setup without provisioner overhead |
| 39 | +template:=dbgen.Template(t,db, database.Template{ |
| 40 | +OrganizationID:owner.OrganizationID, |
| 41 | +CreatedBy:owner.UserID, |
| 42 | +AllowUserCancelWorkspaceJobs:true, |
| 43 | +}) |
| 44 | +version:=dbgen.TemplateVersion(t,db, database.TemplateVersion{ |
| 45 | +OrganizationID:owner.OrganizationID, |
| 46 | +CreatedBy:owner.UserID, |
| 47 | +TemplateID: uuid.NullUUID{UUID:template.ID,Valid:true}, |
46 | 48 | })
|
47 |
| - |
48 |
| -// Stop the provisioner so it doesn't grab any more jobs. |
49 |
| -firstProvisioner.Close() |
50 | 49 |
|
51 | 50 | t.Run("Cancel",func(t*testing.T) {
|
52 | 51 | t.Parallel()
|
53 | 52 |
|
54 |
| -// Set up test helpers. |
55 |
| -typejobInputstruct { |
56 |
| -WorkspaceBuildIDstring`json:"workspace_build_id,omitempty"` |
57 |
| -TemplateVersionIDstring`json:"template_version_id,omitempty"` |
58 |
| -DryRunbool`json:"dry_run,omitempty"` |
59 |
| -} |
60 |
| -prepareJob:=func(t*testing.T,inputjobInput) database.ProvisionerJob { |
| 53 | +// Set up test helpers - simplified to avoid provisioner daemon overhead. |
| 54 | +prepareJob:=func(t*testing.T,jobType database.ProvisionerJobType,input json.RawMessage) database.ProvisionerJob { |
61 | 55 | t.Helper()
|
62 |
| - |
63 |
| -inputBytes,err:=json.Marshal(input) |
64 |
| -require.NoError(t,err) |
65 |
| - |
66 |
| -vartyp database.ProvisionerJobType |
67 |
| -switch { |
68 |
| -caseinput.WorkspaceBuildID!="": |
69 |
| -typ=database.ProvisionerJobTypeWorkspaceBuild |
70 |
| -caseinput.TemplateVersionID!="": |
71 |
| -ifinput.DryRun { |
72 |
| -typ=database.ProvisionerJobTypeTemplateVersionDryRun |
73 |
| -}else { |
74 |
| -typ=database.ProvisionerJobTypeTemplateVersionImport |
75 |
| -} |
76 |
| -default: |
77 |
| -t.Fatal("invalid input") |
78 |
| -} |
79 |
| - |
80 |
| -var ( |
81 |
| -tags= database.StringMap{"owner":"","scope":"organization","foo":uuid.New().String()} |
82 |
| -_=dbgen.ProvisionerDaemon(t,db, database.ProvisionerDaemon{Tags:tags}) |
83 |
| -job=dbgen.ProvisionerJob(t,db,coderdAPI.Pubsub, database.ProvisionerJob{ |
84 |
| -InitiatorID:member.ID, |
85 |
| -Input:json.RawMessage(inputBytes), |
86 |
| -Type:typ, |
87 |
| -Tags:tags, |
88 |
| -StartedAt: sql.NullTime{Time:coderdAPI.Clock.Now().Add(-time.Minute),Valid:true}, |
89 |
| -}) |
90 |
| -) |
91 |
| -returnjob |
| 56 | +returndbgen.ProvisionerJob(t,db,coderdAPI.Pubsub, database.ProvisionerJob{ |
| 57 | +InitiatorID:member.ID, |
| 58 | +Input:input, |
| 59 | +Type:jobType, |
| 60 | +StartedAt: sql.NullTime{Time:coderdAPI.Clock.Now().Add(-time.Minute),Valid:true}, |
| 61 | +}) |
92 | 62 | }
|
93 | 63 |
|
94 | 64 | prepareWorkspaceBuildJob:=func(t*testing.T) database.ProvisionerJob {
|
95 | 65 | t.Helper()
|
96 |
| -var ( |
97 |
| -wbID=uuid.New() |
98 |
| -job=prepareJob(t,jobInput{WorkspaceBuildID:wbID.String()}) |
99 |
| -w=dbgen.Workspace(t,db, database.WorkspaceTable{ |
100 |
| -OrganizationID:owner.OrganizationID, |
101 |
| -OwnerID:member.ID, |
102 |
| -TemplateID:template.ID, |
103 |
| -}) |
104 |
| -_=dbgen.WorkspaceBuild(t,db, database.WorkspaceBuild{ |
105 |
| -ID:wbID, |
106 |
| -InitiatorID:member.ID, |
107 |
| -WorkspaceID:w.ID, |
108 |
| -TemplateVersionID:version.ID, |
109 |
| -JobID:job.ID, |
110 |
| -}) |
111 |
| -) |
| 66 | +wbID:=uuid.New() |
| 67 | +input,_:=json.Marshal(map[string]string{"workspace_build_id":wbID.String()}) |
| 68 | +job:=prepareJob(t,database.ProvisionerJobTypeWorkspaceBuild,input) |
| 69 | + |
| 70 | +w:=dbgen.Workspace(t,db, database.WorkspaceTable{ |
| 71 | +OrganizationID:owner.OrganizationID, |
| 72 | +OwnerID:member.ID, |
| 73 | +TemplateID:template.ID, |
| 74 | +}) |
| 75 | +_=dbgen.WorkspaceBuild(t,db, database.WorkspaceBuild{ |
| 76 | +ID:wbID, |
| 77 | +InitiatorID:member.ID, |
| 78 | +WorkspaceID:w.ID, |
| 79 | +TemplateVersionID:version.ID, |
| 80 | +JobID:job.ID, |
| 81 | +}) |
112 | 82 | returnjob
|
113 | 83 | }
|
114 | 84 |
|
115 |
| -prepareTemplateVersionImportJobBuilder:=func(t*testing.T,dryRunbool) database.ProvisionerJob { |
| 85 | +prepareTemplateVersionImportJob:=func(t*testing.T) database.ProvisionerJob { |
116 | 86 | t.Helper()
|
117 |
| -var ( |
118 |
| -tvID=uuid.New() |
119 |
| -job=prepareJob(t,jobInput{TemplateVersionID:tvID.String(),DryRun:dryRun}) |
120 |
| -_=dbgen.TemplateVersion(t,db, database.TemplateVersion{ |
121 |
| -OrganizationID:owner.OrganizationID, |
122 |
| -CreatedBy:templateAdmin.ID, |
123 |
| -ID:tvID, |
124 |
| -TemplateID:uuid.NullUUID{UUID:template.ID,Valid:true}, |
125 |
| -JobID:job.ID, |
126 |
| -}) |
127 |
| -) |
| 87 | +tvID:=uuid.New() |
| 88 | +input,_:=json.Marshal(map[string]string{"template_version_id":tvID.String()}) |
| 89 | +job:=prepareJob(t,database.ProvisionerJobTypeTemplateVersionImport,input) |
| 90 | + |
| 91 | +_=dbgen.TemplateVersion(t,db, database.TemplateVersion{ |
| 92 | +OrganizationID:owner.OrganizationID, |
| 93 | +CreatedBy:templateAdmin.ID, |
| 94 | +ID:tvID, |
| 95 | +TemplateID:uuid.NullUUID{UUID:template.ID,Valid:true}, |
| 96 | +JobID:job.ID, |
| 97 | +}) |
128 | 98 | returnjob
|
129 | 99 | }
|
130 |
| -prepareTemplateVersionImportJob:=func(t*testing.T) database.ProvisionerJob { |
131 |
| -returnprepareTemplateVersionImportJobBuilder(t,false) |
132 |
| -} |
| 100 | + |
133 | 101 | prepareTemplateVersionImportJobDryRun:=func(t*testing.T) database.ProvisionerJob {
|
134 |
| -returnprepareTemplateVersionImportJobBuilder(t,true) |
| 102 | +t.Helper() |
| 103 | +tvID:=uuid.New() |
| 104 | +input,_:=json.Marshal(map[string]interface{}{ |
| 105 | +"template_version_id":tvID.String(), |
| 106 | +"dry_run":true, |
| 107 | +}) |
| 108 | +job:=prepareJob(t,database.ProvisionerJobTypeTemplateVersionDryRun,input) |
| 109 | + |
| 110 | +_=dbgen.TemplateVersion(t,db, database.TemplateVersion{ |
| 111 | +OrganizationID:owner.OrganizationID, |
| 112 | +CreatedBy:templateAdmin.ID, |
| 113 | +ID:tvID, |
| 114 | +TemplateID: uuid.NullUUID{UUID:template.ID,Valid:true}, |
| 115 | +JobID:job.ID, |
| 116 | +}) |
| 117 | +returnjob |
135 | 118 | }
|
136 | 119 |
|
137 | 120 | // Run the cancellation test suite.
|
|