8000 feat(agent/agentcontainers): recreate devcontainers concurrently (#18… · coder/coder@0731304 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0731304

Browse files
authored
feat(agent/agentcontainers): recreate devcontainers concurrently (#18042)
This change introduces a refactor of the devcontainers recreation logic which is now handled asynchronously rather than being request scoped. The response was consequently changed from "No Content" to "Accepted" to reflect this. A new `Status` field was introduced to the devcontainer struct which replaces `Running` (bool). This reflects that the devcontainer can now be in various states (starting, running, stopped or errored). The status field also protects against multiple concurrent recrations, as long as they are initiated via the API. Updates #16424
1 parent 60fd03d commit 0731304

File tree

10 files changed

+414
-157
lines changed

10 files changed

+414
-157
lines changed

agent/agent_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,14 +2188,14 @@ func TestAgent_DevcontainerRecreate(t *testing.T) {
21882188

21892189
t.Logf("Looking for container with label: devcontainer.local_folder=%s", workspaceFolder)
21902190

2191-
var container docker.APIContainers
2191+
var container codersdk.WorkspaceAgentContainer
21922192
testutil.Eventually(ctx, t, func(context.Context) bool {
2193-
containers, err := pool.Client.ListContainers(docker.ListContainersOptions{All: true})
2193+
resp, err := conn.ListContainers(ctx)
21942194
if err != nil {
21952195
t.Logf("Error listing containers: %v", err)
21962196
return false
21972197
}
2198-
for _, c := range containers {
2198+
for _, c := range resp.Containers {
21992199
t.Logf("Found container: %s with labels: %v", c.ID[:12], c.Labels)
22002200
if v, ok := c.Labels["devcontainer.local_folder"]; ok && v == workspaceFolder {
22012201
t.Logf("Found matching container: %s", c.ID[:12])
@@ -2205,7 +2205,7 @@ func TestAgent_DevcontainerRecreate(t *testing.T) {
22052205
}
22062206
return false
22072207
}, testutil.IntervalMedium, "no container with workspace folder label found")
2208-
defer func(container docker.APIContainers) {
2208+
defer func(container codersdk.WorkspaceAgentContainer) {
22092209
// We can't rely on pool here because the container is not
22102210
// managed by it (it is managed by @devcontainer/cli).
22112211
err := pool.Client.RemoveContainer(docker.RemoveContainerOptions{
@@ -2225,7 +2225,7 @@ func TestAgent_DevcontainerRecreate(t *testing.T) {
22252225
// Invoke recreate to trigger the destruction and recreation of the
22262226
// devcontainer, we do it in a goroutine so we can process logs
22272227
// concurrently.
2228-
go func(container docker.APIContainers) {
2228+
go func(container codersdk.WorkspaceAgentContainer) {
22292229
err := conn.RecreateDevcontainer(ctx, container.ID)
22302230
assert.NoError(t, err, "recreate devcontainer should succeed")
22312231
}(container)
@@ -2253,12 +2253,12 @@ waitForOutcomeLoop:
22532253

22542254
// Make sure the container exists and isn't the same as the old one.
22552255
testutil.Eventually(ctx, t, func(context.Context) bool {
2256-
containers, err := pool.Client.ListContainers(docker.ListContainersOptions{All: true})
2256+
resp, err := conn.ListContainers(ctx)
22572257
if err != nil {
22582258
t.Logf("Error listing containers: %v", err)
22592259
return false
22602260
}
2261-
for _, c := range containers {
2261+
for _, c := range resp.Containers {
22622262
t.Logf("Found container: %s with labels: %v", c.ID[:12], c.Labels)
22632263
if v, ok := c.Labels["devcontainer.local_folder"]; ok && v == workspaceFolder {
22642264
if c.ID == container.ID {
@@ -2272,7 +2272,7 @@ waitForOutcomeLoop:
22722272
}
22732273
return false
22742274
}, testutil.IntervalMedium, "new devcontainer not found")
2275-
defer func(container docker.APIContainers) {
2275+
defer func(container codersdk.WorkspaceAgentContainer) {
22762276
// We can't rely on pool here because the container is not
22772277
// managed by it (it is managed by @devcontainer/cli).
22782278
err := pool.Client.RemoveContainer(docker.RemoveContainerOptions{

0 commit comments

Comments
 (0)
0