MCPcopy Index your code
hub / github.com/coder/coder / TestNotifications

Function TestNotifications

coderd/autobuild/lifecycle_executor_test.go:1267–1340  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1265}
1266
1267func TestNotifications(t *testing.T) {
1268 t.Parallel()
1269
1270 t.Run("Dormancy", func(t *testing.T) {
1271 t.Parallel()
1272
1273 // Setup template with dormancy and create a workspace with it
1274 var (
1275 ticker = make(chan time.Time)
1276 statCh = make(chan autobuild.Stats)
1277 notifyEnq = notificationstest.FakeEnqueuer{}
1278 timeTilDormant = time.Minute
1279 client, db = coderdtest.NewWithDatabase(t, &coderdtest.Options{
1280 AutobuildTicker: ticker,
1281 AutobuildStats: statCh,
1282 IncludeProvisionerDaemon: true,
1283 NotificationsEnqueuer: &notifyEnq,
1284 TemplateScheduleStore: schedule.MockTemplateScheduleStore{
1285 SetFn: func(ctx context.Context, db database.Store, template database.Template, options schedule.TemplateScheduleOptions) (database.Template, error) {
1286 template.TimeTilDormant = int64(options.TimeTilDormant)
1287 return schedule.NewAGPLTemplateScheduleStore().Set(ctx, db, template, options)
1288 },
1289 GetFn: func(_ context.Context, _ database.Store, _ uuid.UUID) (schedule.TemplateScheduleOptions, error) {
1290 return schedule.TemplateScheduleOptions{
1291 UserAutostartEnabled: false,
1292 UserAutostopEnabled: true,
1293 DefaultTTL: 0,
1294 AutostopRequirement: schedule.TemplateAutostopRequirement{},
1295 TimeTilDormant: timeTilDormant,
1296 }, nil
1297 },
1298 },
1299 })
1300 admin = coderdtest.CreateFirstUser(t, client)
1301 version = coderdtest.CreateTemplateVersion(t, client, admin.OrganizationID, nil)
1302 )
1303
1304 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
1305 template := coderdtest.CreateTemplate(t, client, admin.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
1306 ctr.TimeTilDormantMillis = ptr.Ref(timeTilDormant.Milliseconds())
1307 })
1308 userClient, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
1309 workspace := coderdtest.CreateWorkspace(t, userClient, template.ID)
1310 coderdtest.AwaitWorkspaceBuildJobCompleted(t, userClient, workspace.LatestBuild.ID)
1311
1312 // Stop workspace
1313 workspace = coderdtest.MustTransitionWorkspace(t, client, workspace.ID, codersdk.WorkspaceTransitionStart, codersdk.WorkspaceTransitionStop)
1314 _ = coderdtest.AwaitWorkspaceBuildJobCompleted(t, userClient, workspace.LatestBuild.ID)
1315
1316 p, err := coderdtest.GetProvisionerForTags(db, time.Now(), workspace.OrganizationID, nil)
1317 require.NoError(t, err)
1318
1319 // Wait for workspace to become dormant
1320 notifyEnq.Clear()
1321 tickTime := workspace.LastUsedAt.Add(timeTilDormant * 3)
1322 coderdtest.UpdateProvisionerLastSeenAt(t, db, p.ID, tickTime)
1323 ticker <- tickTime
1324 _ = testutil.TryReceive(testutil.Context(t, testutil.WaitShort), t, statCh)

Callers

nothing calls this directly

Calls 15

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
RefFunction · 0.92
CreateAnotherUserFunction · 0.92
CreateWorkspaceFunction · 0.92
MustTransitionWorkspaceFunction · 0.92
GetProvisionerForTagsFunction · 0.92

Tested by

no test coverage detected