mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
test: wait for devcontainer readiness (#25567)
This commit is contained in:
+66
-1
@@ -433,7 +433,72 @@ func TestOpenVSCodeDevContainer(t *testing.T) {
|
||||
agentcontainers.WithContainerLabelIncludeFilter("coder.test", t.Name()),
|
||||
)
|
||||
})
|
||||
coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).AgentNames([]string{parentAgentName, devcontainerName}).Wait()
|
||||
resources := coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).AgentNames([]string{parentAgentName}).Wait()
|
||||
parentAgent := coderdtest.RequireWorkspaceAgentByName(t, resources, parentAgentName)
|
||||
parentAgentID := parentAgent.ID
|
||||
|
||||
// Agent connection does not guarantee the parent agent's container API
|
||||
// has completed its first devcontainer update. Wait for that endpoint so
|
||||
// parallel open commands do not race the initial cache population.
|
||||
ctx := testutil.Context(t, testutil.WaitSuperLong)
|
||||
testutil.Eventually(ctx, t, func(ctx context.Context) bool {
|
||||
resp, err := client.WorkspaceAgentListContainers(ctx, parentAgentID, nil)
|
||||
if err != nil {
|
||||
t.Logf("list containers: %v", err)
|
||||
return false
|
||||
}
|
||||
var devcontainerAgentID uuid.UUID
|
||||
for _, dc := range resp.Devcontainers {
|
||||
if dc.ID != devcontainerID {
|
||||
continue
|
||||
}
|
||||
if dc.Status != codersdk.WorkspaceAgentDevcontainerStatusRunning {
|
||||
t.Logf("devcontainer %s status %q", devcontainerName, dc.Status)
|
||||
return false
|
||||
}
|
||||
if dc.Container == nil {
|
||||
t.Logf("devcontainer %s missing container", devcontainerName)
|
||||
return false
|
||||
}
|
||||
if dc.Container.ID != containerID {
|
||||
t.Logf("devcontainer %s has container %s, want %s", devcontainerName, dc.Container.ID, containerID)
|
||||
return false
|
||||
}
|
||||
if dc.Agent == nil {
|
||||
t.Logf("devcontainer %s missing subagent", devcontainerName)
|
||||
return false
|
||||
}
|
||||
if dc.Agent.Name != devcontainerName {
|
||||
t.Logf("devcontainer %s has subagent %s, want %s", devcontainerName, dc.Agent.Name, devcontainerName)
|
||||
return false
|
||||
}
|
||||
devcontainerAgentID = dc.Agent.ID
|
||||
}
|
||||
if devcontainerAgentID == uuid.Nil {
|
||||
t.Logf("devcontainer %s not found", devcontainerName)
|
||||
return false
|
||||
}
|
||||
|
||||
workspace, err := client.Workspace(ctx, workspace.ID)
|
||||
if err != nil {
|
||||
t.Logf("get workspace: %v", err)
|
||||
return false
|
||||
}
|
||||
for _, resource := range workspace.LatestBuild.Resources {
|
||||
for _, workspaceAgent := range resource.Agents {
|
||||
if workspaceAgent.ID != devcontainerAgentID {
|
||||
continue
|
||||
}
|
||||
if workspaceAgent.Status != codersdk.WorkspaceAgentConnected {
|
||||
t.Logf("devcontainer subagent %s status %q", devcontainerAgentID, workspaceAgent.Status)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
t.Logf("devcontainer subagent %s not found in workspace", devcontainerAgentID)
|
||||
return false
|
||||
}, testutil.IntervalMedium, "devcontainer did not become ready")
|
||||
|
||||
insideWorkspaceEnv := map[string]string{
|
||||
"CODER": "true",
|
||||
|
||||
Reference in New Issue
Block a user