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

Function TestExecutorAutostartMultipleOK

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

Source from the content-addressed store, hash-verified

866}
867
868func TestExecutorAutostartMultipleOK(t *testing.T) {
869 t.Parallel()
870
871 var (
872 sched = mustSchedule(t, "CRON_TZ=UTC 0 * * * *")
873 tickCh = make(chan time.Time)
874 tickCh2 = make(chan time.Time)
875 statsCh1 = make(chan autobuild.Stats)
876 statsCh2 = make(chan autobuild.Stats)
877 client, db = coderdtest.NewWithDatabase(t, &coderdtest.Options{
878 AutobuildTicker: tickCh,
879 IncludeProvisionerDaemon: true,
880 AutobuildStats: statsCh1,
881 })
882 _, _ = coderdtest.NewWithDatabase(t, &coderdtest.Options{
883 AutobuildTicker: tickCh2,
884 IncludeProvisionerDaemon: true,
885 AutobuildStats: statsCh2,
886 })
887 // Given: we have a user with a workspace that has autostart enabled (default)
888 workspace = mustProvisionWorkspace(t, client, func(cwr *codersdk.CreateWorkspaceRequest) {
889 cwr.AutostartSchedule = ptr.Ref(sched.String())
890 })
891 )
892 // Given: workspace is stopped
893 workspace = coderdtest.MustTransitionWorkspace(t, client, workspace.ID, codersdk.WorkspaceTransitionStart, codersdk.WorkspaceTransitionStop)
894
895 p, err := coderdtest.GetProvisionerForTags(db, time.Now(), workspace.OrganizationID, nil)
896 require.NoError(t, err)
897
898 // When: the autobuild executor ticks past the scheduled time
899 go func() {
900 tickTime := sched.Next(workspace.LatestBuild.CreatedAt)
901 coderdtest.UpdateProvisionerLastSeenAt(t, db, p.ID, tickTime)
902 tickCh <- tickTime
903 tickCh2 <- tickTime
904 close(tickCh)
905 close(tickCh2)
906 }()
907
908 // Then: the workspace should eventually be started
909 stats1 := <-statsCh1
910 assert.Len(t, stats1.Errors, 0)
911 assert.Len(t, stats1.Transitions, 1)
912 assert.Contains(t, stats1.Transitions, workspace.ID)
913 assert.Equal(t, database.WorkspaceTransitionStart, stats1.Transitions[workspace.ID])
914
915 // Then: the other executor should not have done anything
916 stats2 := <-statsCh2
917 assert.Len(t, stats2.Errors, 0)
918 assert.Len(t, stats2.Transitions, 0)
919}
920
921func TestExecutorAutostartWithParameters(t *testing.T) {
922 t.Parallel()

Callers

nothing calls this directly

Calls 12

NewWithDatabaseFunction · 0.92
RefFunction · 0.92
MustTransitionWorkspaceFunction · 0.92
GetProvisionerForTagsFunction · 0.92
mustProvisionWorkspaceFunction · 0.85
mustScheduleFunction · 0.70
NextMethod · 0.65
StringMethod · 0.45
LenMethod · 0.45
ContainsMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected