@@ -234,6 +234,46 @@ func Test_Executor_Autostop_NotEnabled(t *testing.T) {
234
234
}, 5 * time .Second , 250 * time .Millisecond )
235
235
}
236
236
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
+
237
277
func MustProvisionWorkspace (t * testing.T , client * codersdk.Client ) codersdk.Workspace {
238
278
t .Helper ()
239
279
coderdtest .NewProvisionerDaemon (t , client )
0 commit comments