- Notifications
You must be signed in to change notification settings - Fork1k
chore: reduce execution time of TestProvisionerJobs#19475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8,7 +8,6 @@ import ( | ||
"testing" | ||
"time" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
@@ -20,6 +19,7 @@ import ( | ||
"github.com/coder/coder/v2/coderd/database/dbtestutil" | ||
"github.com/coder/coder/v2/coderd/rbac" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/provisionersdk" | ||
"github.com/coder/coder/v2/testutil" | ||
) | ||
@@ -36,67 +36,43 @@ func TestProvisionerJobs(t *testing.T) { | ||
templateAdminClient, templateAdmin := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.ScopedRoleOrgTemplateAdmin(owner.OrganizationID)) | ||
memberClient, member := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID) | ||
// These CLI tests are related to provisioner job CRUD operations and as such | ||
// do not require the overhead of starting a provisioner. Other provisioner job | ||
// functionalities (acquisition etc.) are tested elsewhere. | ||
template := dbgen.Template(t, db, database.Template{ | ||
OrganizationID: owner.OrganizationID, | ||
CreatedBy: owner.UserID, | ||
AllowUserCancelWorkspaceJobs: true, | ||
}) | ||
version := dbgen.TemplateVersion(t, db, database.TemplateVersion{ | ||
OrganizationID: owner.OrganizationID, | ||
CreatedBy: owner.UserID, | ||
TemplateID: uuid.NullUUID{UUID: template.ID, Valid: true}, | ||
}) | ||
t.Run("Cancel", func(t *testing.T) { | ||
t.Parallel() | ||
// Test helper to create a provisioner job of a given type with a given input. | ||
prepareJob := func(t *testing.T, jobType database.ProvisionerJobType, input json.RawMessage) database.ProvisionerJob { | ||
t.Helper() | ||
return dbgen.ProvisionerJob(t, db, coderdAPI.Pubsub, database.ProvisionerJob{ | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
InitiatorID: member.ID, | ||
Input: input, | ||
Type: jobType, | ||
StartedAt: sql.NullTime{Time: coderdAPI.Clock.Now().Add(-time.Minute), Valid: true}, | ||
Tags: database.StringMap{provisionersdk.TagOwner: "", provisionersdk.TagScope: provisionersdk.ScopeOrganization, "foo": uuid.NewString()}, | ||
}) | ||
} | ||
// Test helper to create a workspace build job with a predefined input. | ||
prepareWorkspaceBuildJob := func(t *testing.T) database.ProvisionerJob { | ||
t.Helper() | ||
var ( | ||
wbID = uuid.New() | ||
input, _ = json.Marshal(map[string]string{"workspace_build_id": wbID.String()}) | ||
job = prepareJob(t, database.ProvisionerJobTypeWorkspaceBuild, input) | ||
w = dbgen.Workspace(t, db, database.WorkspaceTable{ | ||
OrganizationID: owner.OrganizationID, | ||
OwnerID: member.ID, | ||
TemplateID: template.ID, | ||
@@ -112,12 +88,14 @@ func TestProvisionerJobs(t *testing.T) { | ||
return job | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Review: it's simpler to have separate test helpers instead of one with a control flag. | ||
// Test helper to create a template version import job with a predefined input. | ||
prepareTemplateVersionImportJob := func(t *testing.T) database.ProvisionerJob { | ||
t.Helper() | ||
var ( | ||
tvID = uuid.New() | ||
input, _ = json.Marshal(map[string]string{"template_version_id": tvID.String()}) | ||
job = prepareJob(t, database.ProvisionerJobTypeTemplateVersionImport, input) | ||
_ = dbgen.TemplateVersion(t, db, database.TemplateVersion{ | ||
OrganizationID: owner.OrganizationID, | ||
CreatedBy: templateAdmin.ID, | ||
ID: tvID, | ||
@@ -127,11 +105,26 @@ func TestProvisionerJobs(t *testing.T) { | ||
) | ||
return job | ||
} | ||
// Test helper to create a template version import dry run job with a predefined input. | ||
prepareTemplateVersionImportJobDryRun := func(t *testing.T) database.ProvisionerJob { | ||
t.Helper() | ||
var ( | ||
tvID = uuid.New() | ||
input, _ = json.Marshal(map[string]interface{}{ | ||
"template_version_id": tvID.String(), | ||
"dry_run": true, | ||
}) | ||
job = prepareJob(t, database.ProvisionerJobTypeTemplateVersionDryRun, input) | ||
_ = dbgen.TemplateVersion(t, db, database.TemplateVersion{ | ||
OrganizationID: owner.OrganizationID, | ||
CreatedBy: templateAdmin.ID, | ||
ID: tvID, | ||
TemplateID: uuid.NullUUID{UUID: template.ID, Valid: true}, | ||
JobID: job.ID, | ||
}) | ||
) | ||
return job | ||
} | ||
// Run the cancellation test suite. | ||
Uh oh!
There was an error while loading.Please reload this page.