- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: implement claiming of prebuilt workspaces#17458
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 from1 commit
8b9e30dd9497df217e46fc459533f90521982663384098ed750d23e4546b7ae85f7926ee9908c70bf1797a72d03b246589ff8d3defcdbba8e7b7f80e7455db077d7f00d426c7663a8c0bc31fac087bd209f661697f25f24ff9eeb431b873f4fe770d8d8fc99af323250826e8acbb6c12e466844f24557bfa6556453b38d76c41e039173e9aFile 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
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -10,13 +10,13 @@ import ( | ||
| "github.com/coder/quartz" | ||
| "github.com/google/uuid" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/coder/coder/v2/coderd/coderdtest" | ||
| "github.com/coder/coder/v2/coderd/database" | ||
| "github.com/coder/coder/v2/coderd/database/dbauthz" | ||
| "github.com/coder/coder/v2/coderd/database/dbtestutil" | ||
| agplprebuilds "github.com/coder/coder/v2/coderd/prebuilds" | ||
| "github.com/coder/coder/v2/coderd/rbac" | ||
| "github.com/coder/coder/v2/codersdk" | ||
| "github.com/coder/coder/v2/enterprise/coderd/coderdenttest" | ||
| @@ -78,40 +78,20 @@ func TestClaimPrebuild(t *testing.T) { | ||
| ) | ||
| cases := map[string]struct { | ||
| expectPrebuildClaimed bool | ||
| markPrebuildsClaimable bool | ||
| }{ | ||
| "no eligible prebuilds to claim": { | ||
| expectPrebuildClaimed: false, | ||
| markPrebuildsClaimable: false, | ||
| }, | ||
| "claiming an eligible prebuild should succeed": { | ||
| expectPrebuildClaimed: true, | ||
| markPrebuildsClaimable: true, | ||
| }, | ||
| "claiming an eligible prebuild results in error": { | ||
| expectPrebuildClaimed: true, | ||
| markPrebuildsClaimable: true, | ||
| }, | ||
evgeniy-scherbina marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| @@ -121,49 +101,26 @@ func TestClaimPrebuild(t *testing.T) { | ||
| t.Run(name, func(t *testing.T) { | ||
| t.Parallel() | ||
| // Setup. | ||
| ctx := testutil.Context(t, testutil.WaitMedium) | ||
evgeniy-scherbina marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| db, pubsub := dbtestutil.NewDB(t) | ||
| spy := newStoreSpy(db) | ||
| expectedPrebuildsCount := desiredInstances * presetCount | ||
| logger := testutil.Logger(t) | ||
| client, _,api, owner := coderdenttest.NewWithAPI(t, &coderdenttest.Options{ | ||
| Options: &coderdtest.Options{ | ||
| IncludeProvisionerDaemon: true, | ||
| Database: spy, | ||
| Pubsub: pubsub, | ||
| }, | ||
| EntitlementsUpdateInterval: time.Second, | ||
| }) | ||
| reconciler := prebuilds.NewStoreReconciler(spy, pubsub, codersdk.PrebuildsConfig{}, logger, quartz.NewMock(t)) | ||
| var claimer agplprebuilds.Claimer = &prebuilds.EnterpriseClaimer{} | ||
| api.AGPL.PrebuildsClaimer.Store(&claimer) | ||
| version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, templateWithAgentAndPresetsWithPrebuilds(desiredInstances)) | ||
| _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) | ||
| @@ -179,14 +136,8 @@ func TestClaimPrebuild(t *testing.T) { | ||
| // Given: the reconciliation state is snapshot. | ||
| state, err := reconciler.SnapshotState(ctx, spy) | ||
| require.NoError(t, err) | ||
| require.Len(t, state.Presets, presetCount) | ||
| // When: a reconciliation is setup for each preset. | ||
| for _, preset := range presets { | ||
| ps, err := state.FilterByPreset(preset.ID) | ||
| @@ -215,6 +166,7 @@ func TestClaimPrebuild(t *testing.T) { | ||
| agents, err := db.GetWorkspaceAgentsInLatestBuildByWorkspaceID(ctx, row.ID) | ||
| require.NoError(t, err) | ||
| // Workspaces are eligible once its agent is marked "ready". | ||
| for _, agent := range agents { | ||
| require.NoError(t, db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{ | ||
| ID: agent.ID, | ||
| @@ -225,9 +177,9 @@ func TestClaimPrebuild(t *testing.T) { | ||
| } | ||
| } | ||
| t.Logf("found %d running prebuilds so far, want %d", len(runningPrebuilds), expectedPrebuildsCount) | ||
| return len(runningPrebuilds) == expectedPrebuildsCount | ||
| }, testutil.WaitSuperLong, testutil.IntervalSlow) | ||
evgeniy-scherbina marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| // When: a user creates a new workspace with a preset for which prebuilds are configured. | ||
| @@ -243,21 +195,10 @@ func TestClaimPrebuild(t *testing.T) { | ||
| TemplateVersionPresetID: presets[0].ID, | ||
| ClaimPrebuildIfAvailable: true, // TODO: doesn't do anything yet; it probably should though. | ||
| }) | ||
| require.NoError(t, err) | ||
| coderdtest.AwaitWorkspaceBuildJobCompleted(t, userClient, userWorkspace.LatestBuild.ID) | ||
| // Then: a prebuild should have been claimed. | ||
| require.EqualValues(t, spy.claims.Load(), 1) | ||
| require.NotNil(t, spy.claims.Load()) | ||
evgeniy-scherbina marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| @@ -315,9 +256,9 @@ func TestClaimPrebuild(t *testing.T) { | ||
| rows, err := spy.GetRunningPrebuiltWorkspaces(ctx) | ||
| require.NoError(t, err) | ||
| t.Logf("found %d running prebuilds so far, want %d", len(rows), expectedPrebuildsCount) | ||
| return len(runningPrebuilds) == expectedPrebuildsCount | ||
| }, testutil.WaitSuperLong, testutil.IntervalSlow) | ||
| // Then: when restarting the created workspace (which claimed a prebuild), it should not try and claim a new prebuild. | ||