(t *testing.T)
| 312 | } |
| 313 | |
| 314 | func TestAcquireJob(t *testing.T) { |
| 315 | t.Parallel() |
| 316 | |
| 317 | // These test acquiring a single job without canceling, and tests both AcquireJob (deprecated) and |
| 318 | // AcquireJobWithCancel as the way to get the job. |
| 319 | cases := []struct { |
| 320 | name string |
| 321 | acquire func(context.Context, proto.DRPCProvisionerDaemonServer) (*proto.AcquiredJob, error) |
| 322 | }{ |
| 323 | {name: "Deprecated", acquire: func(ctx context.Context, srv proto.DRPCProvisionerDaemonServer) (*proto.AcquiredJob, error) { |
| 324 | return srv.AcquireJob(ctx, nil) |
| 325 | }}, |
| 326 | {name: "WithCancel", acquire: func(ctx context.Context, srv proto.DRPCProvisionerDaemonServer) (*proto.AcquiredJob, error) { |
| 327 | fs := newFakeStream(ctx) |
| 328 | err := srv.AcquireJobWithCancel(fs) |
| 329 | if err != nil { |
| 330 | return nil, err |
| 331 | } |
| 332 | return fs.waitForJob() |
| 333 | }}, |
| 334 | } |
| 335 | for _, tc := range cases { |
| 336 | t.Run(tc.name+"_InitiatorNotFound", func(t *testing.T) { |
| 337 | t.Parallel() |
| 338 | srv, db, _, pd := setup(t, false, nil) |
| 339 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 340 | defer cancel() |
| 341 | |
| 342 | _, err := db.InsertProvisionerJob(context.Background(), database.InsertProvisionerJobParams{ |
| 343 | OrganizationID: pd.OrganizationID, |
| 344 | ID: uuid.New(), |
| 345 | InitiatorID: uuid.New(), |
| 346 | Provisioner: database.ProvisionerTypeEcho, |
| 347 | StorageMethod: database.ProvisionerStorageMethodFile, |
| 348 | Type: database.ProvisionerJobTypeTemplateVersionDryRun, |
| 349 | Input: json.RawMessage("{}"), |
| 350 | Tags: pd.Tags, |
| 351 | }) |
| 352 | require.NoError(t, err) |
| 353 | _, err = tc.acquire(ctx, srv) |
| 354 | require.ErrorContains(t, err, "sql: no rows in result set") |
| 355 | }) |
| 356 | for _, prebuiltWorkspaceBuildStage := range []sdkproto.PrebuiltWorkspaceBuildStage{ |
| 357 | sdkproto.PrebuiltWorkspaceBuildStage_NONE, |
| 358 | sdkproto.PrebuiltWorkspaceBuildStage_CREATE, |
| 359 | sdkproto.PrebuiltWorkspaceBuildStage_CLAIM, |
| 360 | } { |
| 361 | t.Run(tc.name+"_WorkspaceBuildJob_Stage"+prebuiltWorkspaceBuildStage.String(), func(t *testing.T) { |
| 362 | t.Parallel() |
| 363 | // Set the max session token lifetime so we can assert we |
| 364 | // create an API key with an expiration within the bounds of the |
| 365 | // deployment config. |
| 366 | dv := &codersdk.DeploymentValues{ |
| 367 | Sessions: codersdk.SessionLifetime{ |
| 368 | MaximumTokenDuration: serpent.Duration(time.Hour), |
| 369 | }, |
| 370 | } |
| 371 | gitAuthProvider := &sdkproto.ExternalAuthProviderResource{ |
nothing calls this directly
no test coverage detected