Skip to content

feat(agent): send devcontainer CLI logs during recreate #17845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 15, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
testutil.Eventually
  • Loading branch information
mafredri committed May 15, 2025
commit 7d9d1615913e2b863a64c3ec7cce5f0b2a6c8a1c
16 changes: 9 additions & 7 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@
// You can run it manually as follows:
//
// CODER_TEST_USE_DOCKER=1 go test -count=1 ./agent -run TestAgent_DevcontainerRecreate
func TestAgent_DevcontainerRecreate(t *testing.T) {

Check failure on line 2134 in agent/agent_test.go

View workflow job for this annotation

GitHub Actions / lint

Function TestAgent_DevcontainerRecreate missing the call to method parallel (paralleltest)
if os.Getenv("CODER_TEST_USE_DOCKER") != "1" {
t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test")
}
Expand Down Expand Up @@ -2178,19 +2178,21 @@
o.ExperimentalDevcontainersEnabled = true
})

ctx := testutil.Context(t, testutil.WaitLong)

// We enabled autostart for the devcontainer, so ready is a good
// indication that the devcontainer is up and running. Importantly,
// this also means that the devcontainer startup is no longer
// producing logs that may interfere with the recreate logs.
require.Eventually(t, func() bool {
testutil.Eventually(ctx, t, func(context.Context) bool {
states := client.GetLifecycleStates()
return slices.Contains(states, codersdk.WorkspaceAgentLifecycleReady)
}, testutil.WaitLong, testutil.IntervalMedium, "devcontainer not ready")
}, testutil.IntervalMedium, "devcontainer not ready")

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

var container docker.APIContainers
require.Eventually(t, func() bool {
testutil.Eventually(ctx, t, func(context.Context) bool {
containers, err := pool.Client.ListContainers(docker.ListContainersOptions{All: true})
if err != nil {
t.Logf("Error listing containers: %v", err)
Expand All @@ -2205,7 +2207,7 @@
}
}
return false
}, testutil.WaitLong, testutil.IntervalMedium, "no container with workspace folder label found")
}, testutil.IntervalMedium, "no container with workspace folder label found")
defer func(container docker.APIContainers) {
// We can't rely on pool here because the container is not
// managed by it (it is managed by @devcontainer/cli).
Expand All @@ -2217,7 +2219,7 @@
assert.Error(t, err, "container should be removed by recreate")
}(container)

ctx := testutil.Context(t, testutil.WaitLong)
ctx = testutil.Context(t, testutil.WaitLong) // Reset context.

// Capture logs via ScriptLogger.
logsCh := make(chan *proto.BatchCreateLogsRequest, 1)
Expand Down Expand Up @@ -2253,7 +2255,7 @@
t.Logf("Checking there's a new container with label: devcontainer.local_folder=%s", workspaceFolder)

// Make sure the container exists and isn't the same as the old one.
require.Eventually(t, func() bool {
testutil.Eventually(ctx, t, func(context.Context) bool {
containers, err := pool.Client.ListContainers(docker.ListContainersOptions{All: true})
if err != nil {
t.Logf("Error listing containers: %v", err)
Expand All @@ -2272,7 +2274,7 @@
}
}
return false
}, testutil.WaitLong, testutil.IntervalMedium, "new devcontainer not found")
}, testutil.IntervalMedium, "new devcontainer not found")
defer func(container docker.APIContainers) {
// We can't rely on pool here because the container is not
// managed by it (it is managed by @devcontainer/cli).
Expand Down
Loading