Skip to content

Commit 802801e

Browse files
committed
more tests
1 parent a62c6ae commit 802801e

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

coderd/workspaces_test.go

+55-1
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ func TestWorkspace(t *testing.T) {
200200

201201
workspace, err := client.Workspace(ctx, workspace.ID)
202202
require.NoError(t, err)
203+
203204
agent := workspace.LatestBuild.Resources[0].Agents[0]
204205

206+
assert.True(t, workspace.Health.Healthy)
207+
assert.Len(t, workspace.Health.FailingAgents, 0)
205208
assert.True(t, agent.Health.Healthy)
206209
assert.Empty(t, agent.Health.Reason)
207210
})
@@ -239,7 +242,6 @@ func TestWorkspace(t *testing.T) {
239242
var err error
240243
testutil.Eventually(ctx, t, func(ctx context.Context) bool {
241244
workspace, err = client.Workspace(ctx, workspace.ID)
242-
t.Logf("%#v", workspace)
243245
return assert.NoError(t, err) && !workspace.Health.Healthy
244246
}, testutil.IntervalMedium)
245247

@@ -250,6 +252,58 @@ func TestWorkspace(t *testing.T) {
250252
assert.False(t, agent.Health.Healthy)
251253
assert.NotEmpty(t, agent.Health.Reason)
252254
})
255+
256+
t.Run("Mixed health", func(t *testing.T) {
257+
t.Parallel()
258+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
259+
user := coderdtest.CreateFirstUser(t, client)
260+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
261+
Parse: echo.ParseComplete,
262+
ProvisionApply: []*proto.Provision_Response{{
263+
Type: &proto.Provision_Response_Complete{
264+
Complete: &proto.Provision_Complete{
265+
Resources: []*proto.Resource{{
266+
Name: "some",
267+
Type: "example",
268+
Agents: []*proto.Agent{{
269+
Id: uuid.NewString(),
270+
Name: "a1",
271+
Auth: &proto.Agent_Token{},
272+
}, {
273+
Id: uuid.NewString(),
274+
Name: "a2",
275+
Auth: &proto.Agent_Token{},
276+
ConnectionTimeoutSeconds: 1,
277+
}},
278+
}},
279+
},
280+
},
281+
}},
282+
})
283+
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
284+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
285+
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
286+
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
287+
288+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
289+
defer cancel()
290+
291+
var err error
292+
testutil.Eventually(ctx, t, func(ctx context.Context) bool {
293+
workspace, err = client.Workspace(ctx, workspace.ID)
294+
return assert.NoError(t, err) && !workspace.Health.Healthy
295+
}, testutil.IntervalMedium)
296+
297+
assert.False(t, workspace.Health.Healthy)
298+
assert.Len(t, workspace.Health.FailingAgents, 1)
299+
300+
agent1 := workspace.LatestBuild.Resources[0].Agents[0]
301+
assert.True(t, agent1.Health.Healthy)
302+
assert.Empty(t, agent1.Health.Reason)
303+
agent2 := workspace.LatestBuild.Resources[0].Agents[1]
304+
assert.False(t, agent2.Health.Healthy)
305+
assert.NotEmpty(t, agent2.Health.Reason)
306+
})
253307
})
254308
}
255309

0 commit comments

Comments
 (0)