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

Function TestMultipleLifecycleExecutors

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

Source from the content-addressed store, hash-verified

88}
89
90func TestMultipleLifecycleExecutors(t *testing.T) {
91 t.Parallel()
92
93 db, ps := dbtestutil.NewDB(t)
94
95 var (
96 sched = mustSchedule(t, "CRON_TZ=UTC 0 * * * *")
97 // Create our first client
98 tickCh = make(chan time.Time, 2)
99 statsChA = make(chan autobuild.Stats)
100 clientA = coderdtest.New(t, &coderdtest.Options{
101 IncludeProvisionerDaemon: true,
102 AutobuildTicker: tickCh,
103 AutobuildStats: statsChA,
104 Database: db,
105 Pubsub: ps,
106 })
107 // ... And then our second client
108 statsChB = make(chan autobuild.Stats)
109 _ = coderdtest.New(t, &coderdtest.Options{
110 IncludeProvisionerDaemon: true,
111 AutobuildTicker: tickCh,
112 AutobuildStats: statsChB,
113 Database: db,
114 Pubsub: ps,
115 })
116 // Now create a workspace (we can use either client, it doesn't matter)
117 workspace = mustProvisionWorkspace(t, clientA, func(cwr *codersdk.CreateWorkspaceRequest) {
118 cwr.AutostartSchedule = ptr.Ref(sched.String())
119 })
120 )
121
122 // Have the workspace stopped so we can perform an autostart
123 workspace = coderdtest.MustTransitionWorkspace(t, clientA, workspace.ID, codersdk.WorkspaceTransitionStart, codersdk.WorkspaceTransitionStop)
124
125 p, err := coderdtest.GetProvisionerForTags(db, time.Now(), workspace.OrganizationID, nil)
126 require.NoError(t, err)
127 // Get both clients to perform a lifecycle execution tick
128 next := sched.Next(workspace.LatestBuild.CreatedAt)
129 coderdtest.UpdateProvisionerLastSeenAt(t, db, p.ID, next)
130
131 startCh := make(chan struct{})
132 go func() {
133 <-startCh
134 tickCh <- next
135 }()
136 go func() {
137 <-startCh
138 tickCh <- next
139 }()
140 close(startCh)
141
142 // Now we want to check the stats for both clients
143 statsA := <-statsChA
144 statsB := <-statsChB
145
146 // We expect there to be no errors
147 assert.Len(t, statsA.Errors, 0)

Callers

nothing calls this directly

Calls 13

NewDBFunction · 0.92
NewFunction · 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
EqualMethod · 0.45

Tested by

no test coverage detected