Skip to content

Commit 32918e8

Browse files
committed
[ws-manager-mk2] Update tests with content readiness
1 parent 1bacab8 commit 32918e8

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

components/ws-manager-mk2/controllers/workspace_controller_test.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,28 @@ var _ = Describe("WorkspaceController", func() {
119119
})
120120
})
121121

122+
It("should not take a backup if content init did not happen", func() {
123+
ws := newWorkspace(uuid.NewString(), "default")
124+
m := collectMetricCounts(wsMetrics, ws)
125+
pod := createWorkspaceExpectPod(ws)
126+
127+
requestStop(ws)
128+
129+
// No content init, expect cleanup without backup.
130+
expectWorkspaceCleanup(ws, pod)
131+
132+
expectMetricsDelta(m, collectMetricCounts(wsMetrics, ws), metricCounts{
133+
stops: 1,
134+
})
135+
})
136+
122137
It("should handle backup failure", func() {
123138
ws := newWorkspace(uuid.NewString(), "default")
124139
m := collectMetricCounts(wsMetrics, ws)
125140
pod := createWorkspaceExpectPod(ws)
126141

142+
markContentReady(ws)
143+
127144
// Stop the workspace.
128145
requestStop(ws)
129146

@@ -134,6 +151,7 @@ var _ = Describe("WorkspaceController", func() {
134151
expectWorkspaceCleanup(ws, pod)
135152

136153
expectMetricsDelta(m, collectMetricCounts(wsMetrics, ws), metricCounts{
154+
restores: 1,
137155
backups: 1,
138156
backupFailures: 1,
139157
stops: 1,
@@ -145,6 +163,8 @@ var _ = Describe("WorkspaceController", func() {
145163
m := collectMetricCounts(wsMetrics, ws)
146164
pod := createWorkspaceExpectPod(ws)
147165

166+
markContentReady(ws)
167+
148168
// Update Pod with failed exit status.
149169
updateObjWithRetries(k8sClient, pod, true, func(pod *corev1.Pod) {
150170
pod.Status.ContainerStatuses = append(pod.Status.ContainerStatuses, corev1.ContainerStatus{
@@ -165,6 +185,7 @@ var _ = Describe("WorkspaceController", func() {
165185
expectWorkspaceCleanup(ws, pod)
166186

167187
expectMetricsDelta(m, collectMetricCounts(wsMetrics, ws), metricCounts{
188+
restores: 1,
168189
startFailures: 1,
169190
stops: 1,
170191
backups: 1,
@@ -176,6 +197,8 @@ var _ = Describe("WorkspaceController", func() {
176197
m := collectMetricCounts(wsMetrics, ws)
177198
pod := createWorkspaceExpectPod(ws)
178199

200+
markContentReady(ws)
201+
179202
By("adding Timeout condition")
180203
updateObjWithRetries(k8sClient, ws, true, func(ws *workspacev1.Workspace) {
181204
ws.Status.Conditions = wsk8s.AddUniqueCondition(ws.Status.Conditions, metav1.Condition{
@@ -190,8 +213,9 @@ var _ = Describe("WorkspaceController", func() {
190213
expectWorkspaceCleanup(ws, pod)
191214

192215
expectMetricsDelta(m, collectMetricCounts(wsMetrics, ws), metricCounts{
193-
stops: 1,
194-
backups: 1,
216+
restores: 1,
217+
stops: 1,
218+
backups: 1,
195219
})
196220
})
197221

@@ -200,6 +224,8 @@ var _ = Describe("WorkspaceController", func() {
200224
m := collectMetricCounts(wsMetrics, ws)
201225
pod := createWorkspaceExpectPod(ws)
202226

227+
markContentReady(ws)
228+
203229
// Update Pod with stop and abort conditions.
204230
updateObjWithRetries(k8sClient, ws, true, func(ws *workspacev1.Workspace) {
205231
ws.Status.Conditions = wsk8s.AddUniqueCondition(ws.Status.Conditions, metav1.Condition{
@@ -218,7 +244,8 @@ var _ = Describe("WorkspaceController", func() {
218244
expectWorkspaceCleanup(ws, pod)
219245

220246
expectMetricsDelta(m, collectMetricCounts(wsMetrics, ws), metricCounts{
221-
stops: 1,
247+
restores: 1,
248+
stops: 1,
222249
})
223250
})
224251

@@ -227,6 +254,8 @@ var _ = Describe("WorkspaceController", func() {
227254
m := collectMetricCounts(wsMetrics, ws)
228255
pod := createWorkspaceExpectPod(ws)
229256

257+
markContentReady(ws)
258+
230259
Expect(k8sClient.Delete(ctx, ws)).To(Succeed())
231260

232261
expectPhaseEventually(ws, workspacev1.WorkspacePhaseStopping)
@@ -236,8 +265,9 @@ var _ = Describe("WorkspaceController", func() {
236265
expectWorkspaceCleanup(ws, pod)
237266

238267
expectMetricsDelta(m, collectMetricCounts(wsMetrics, ws), metricCounts{
239-
stops: 1,
240-
backups: 1,
268+
restores: 1,
269+
stops: 1,
270+
backups: 1,
241271
})
242272
})
243273
})

0 commit comments

Comments
 (0)