(t *testing.T)
| 5187 | } |
| 5188 | |
| 5189 | func TestWorkspaceTimings(t *testing.T) { |
| 5190 | t.Parallel() |
| 5191 | |
| 5192 | db, pubsub := dbtestutil.NewDB(t) |
| 5193 | client := coderdtest.New(t, &coderdtest.Options{ |
| 5194 | Database: db, |
| 5195 | Pubsub: pubsub, |
| 5196 | }) |
| 5197 | coderdtest.CreateFirstUser(t, client) |
| 5198 | |
| 5199 | t.Run("LatestBuild", func(t *testing.T) { |
| 5200 | t.Parallel() |
| 5201 | |
| 5202 | // Given: a workspace with many builds, provisioner, and agent script timings |
| 5203 | db, pubsub := dbtestutil.NewDB(t) |
| 5204 | client := coderdtest.New(t, &coderdtest.Options{ |
| 5205 | Database: db, |
| 5206 | Pubsub: pubsub, |
| 5207 | }) |
| 5208 | owner := coderdtest.CreateFirstUser(t, client) |
| 5209 | file := dbgen.File(t, db, database.File{ |
| 5210 | CreatedBy: owner.UserID, |
| 5211 | }) |
| 5212 | versionJob := dbgen.ProvisionerJob(t, db, pubsub, database.ProvisionerJob{ |
| 5213 | OrganizationID: owner.OrganizationID, |
| 5214 | InitiatorID: owner.UserID, |
| 5215 | FileID: file.ID, |
| 5216 | Tags: database.StringMap{ |
| 5217 | "custom": "true", |
| 5218 | }, |
| 5219 | }) |
| 5220 | version := dbgen.TemplateVersion(t, db, database.TemplateVersion{ |
| 5221 | OrganizationID: owner.OrganizationID, |
| 5222 | JobID: versionJob.ID, |
| 5223 | CreatedBy: owner.UserID, |
| 5224 | }) |
| 5225 | template := dbgen.Template(t, db, database.Template{ |
| 5226 | OrganizationID: owner.OrganizationID, |
| 5227 | ActiveVersionID: version.ID, |
| 5228 | CreatedBy: owner.UserID, |
| 5229 | }) |
| 5230 | ws := dbgen.Workspace(t, db, database.WorkspaceTable{ |
| 5231 | OwnerID: owner.UserID, |
| 5232 | OrganizationID: owner.OrganizationID, |
| 5233 | TemplateID: template.ID, |
| 5234 | }) |
| 5235 | |
| 5236 | // Create multiple builds |
| 5237 | var buildNumber int32 |
| 5238 | makeBuild := func() database.WorkspaceBuild { |
| 5239 | buildNumber++ |
| 5240 | jobID := uuid.New() |
| 5241 | job := dbgen.ProvisionerJob(t, db, pubsub, database.ProvisionerJob{ |
| 5242 | ID: jobID, |
| 5243 | OrganizationID: owner.OrganizationID, |
| 5244 | Tags: database.StringMap{jobID.String(): "true"}, |
| 5245 | }) |
| 5246 | return dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{ |
nothing calls this directly
no test coverage detected