Skip to content

Commit def317c

Browse files
committed
add test for deleted workspace
1 parent cc1c466 commit def317c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

coderd/autostart/lifecycle/lifecycle_executor_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,46 @@ func Test_Executor_Autostop_NotEnabled(t *testing.T) {
234234
}, 5*time.Second, 250*time.Millisecond)
235235
}
236236

237+
func Test_Executor_Workspace_Deleted(t *testing.T) {
238+
t.Parallel()
239+
240+
var (
241+
ctx = context.Background()
242+
err error
243+
tickCh = make(chan time.Time)
244+
client = coderdtest.New(t, &coderdtest.Options{
245+
LifecycleTicker: tickCh,
246+
})
247+
// Given: we have a user with a workspace
248+
workspace = MustProvisionWorkspace(t, client)
249+
)
250+
251+
// Given: the workspace initially has autostart disabled
252+
require.Empty(t, workspace.AutostopSchedule)
253+
254+
// When: we enable workspace autostart
255+
sched, err := schedule.Weekly("* * * * *")
256+
require.NoError(t, err)
257+
require.NoError(t, client.UpdateWorkspaceAutostop(ctx, workspace.ID, codersdk.UpdateWorkspaceAutostopRequest{
258+
Schedule: sched.String(),
259+
}))
260+
261+
// Given: workspace is deleted
262+
MustTransitionWorkspace(t, client, workspace.ID, database.WorkspaceTransitionStart, database.WorkspaceTransitionDelete)
263+
264+
// When: the lifecycle executor ticks
265+
go func() {
266+
tickCh <- time.Now().UTC().Add(time.Minute)
267+
close(tickCh)
268+
}()
269+
270+
// Then: nothing should happen
271+
require.Never(t, func() bool {
272+
ws := coderdtest.MustWorkspace(t, client, workspace.ID)
273+
return ws.LatestBuild.Transition != database.WorkspaceTransitionDelete
274+
}, 5*time.Second, 250*time.Millisecond)
275+
}
276+
237277
func MustProvisionWorkspace(t *testing.T, client *codersdk.Client) codersdk.Workspace {
238278
t.Helper()
239279
coderdtest.NewProvisionerDaemon(t, client)

0 commit comments

Comments
 (0)