diff --git a/cmd/workspace/up/detach.go b/cmd/workspace/up/detach.go index f486c282f..bf051e7ff 100644 --- a/cmd/workspace/up/detach.go +++ b/cmd/workspace/up/detach.go @@ -59,7 +59,10 @@ func (cmd *UpCmd) runDetached(args []string, cfg *config.Config) error { return cmd.renderDetachedTask(t, runID) } -const detachedLookupTimeout = 30 * time.Second +const ( + detachedLookupTimeout = 30 * time.Second + detachedLaunchTimeout = 30 * time.Second +) func (cmd *UpCmd) checkDetachedPresentation(cfg *config.Config, workspaceID string) error { ctx, cancel := context.WithTimeout(context.Background(), detachedLookupTimeout) @@ -133,12 +136,7 @@ func launchDetached(t *task.Task, invocationEnv []string) error { AtomicOwnership: true, OnPrepared: t.PrepareProcessOwnership, OnStarted: func(ref command.ProcessRef) error { - if err := t.PublishProcess(ref); err != nil { - return err - } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - return t.CommitLaunch(ctx) + return commitDetachedLaunch(t, ref) }, }, func() (*exec.Cmd, error) { return &exec.Cmd{ @@ -150,6 +148,15 @@ func launchDetached(t *task.Task, invocationEnv []string) error { }) } +func commitDetachedLaunch(t *task.Task, ref command.ProcessRef) error { + if err := t.PublishProcess(ref); err != nil { + return err + } + ctx, cancel := context.WithTimeout(context.Background(), detachedLaunchTimeout) + defer cancel() + return t.CommitLaunch(ctx) +} + // detachedArgs strips --detach so it isn't duplicated alongside --task-id. func detachedArgs(args []string) []string { detachFlag := names.Flag(names.Detach) diff --git a/cmd/workspace/up/launch_handoff_test.go b/cmd/workspace/up/launch_handoff_test.go index bb1b3e455..2bfdf0a66 100644 --- a/cmd/workspace/up/launch_handoff_test.go +++ b/cmd/workspace/up/launch_handoff_test.go @@ -1,7 +1,6 @@ package up import ( - "context" "os" "os/exec" "testing" @@ -20,12 +19,7 @@ func TestDetachedWorkerCommitsBeforeWorkspaceWork(t *testing.T) { Name: task.WorkerProcessName(tk.ID()), Lease: tk.LaunchLease(), AtomicOwnership: true, OnPrepared: tk.PrepareProcessOwnership, OnStarted: func(ref command.ProcessRef) error { - if err := tk.PublishProcess(ref); err != nil { - return err - } - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - return tk.CommitLaunch(ctx) + return commitDetachedLaunch(tk, ref) }, }, func() (*exec.Cmd, error) { child := exec.Command( @@ -52,6 +46,7 @@ func TestDetachedWorkerHandoffHelper(t *testing.T) { if id == "" { return } + time.Sleep(6 * time.Second) cmd := &UpCmd{taskID: id} tk, err := cmd.openTask() require.NoError(t, err) diff --git a/e2e/README.md b/e2e/README.md index 0ba37f906..381bf1253 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -30,6 +30,8 @@ mise run cli:test:e2e:suite up-docker-compose mise run cli:test:e2e:focus "pattern" ``` +The `with env vars` workspace spec uses a local Docker fixture. Its repeated `up` calls test environment changes without waiting for remote repository inspection. + `cli:test:e2e:act:focus` runs a focused pattern through [act](https://github.com/nektos/act). The Docker lifecycle regression covers values with `=` from `--workspace-env` and diff --git a/e2e/tests/up/up.go b/e2e/tests/up/up.go index 0e3c68c9e..161109a0f 100644 --- a/e2e/tests/up/up.go +++ b/e2e/tests/up/up.go @@ -43,11 +43,10 @@ var _ = ginkgo.Describe("testing up command", ginkgo.Label("up-workspaces"), fun f, err := framework.SetupDockerProvider(filepath.Join(initialDir, "bin"), dockerValue) framework.ExpectNoError(err) - name := "vscode-remote-try-python" + name := framework.CopyTestdata("tests/up/testdata/docker", initialDir) ginkgo.DeferCleanup(f.DevsyWorkspaceDelete, name) - // Wait for devsy workspace to come online (deadline: 30s) - err = f.DevsyUp(ctx, "https://github.com/microsoft/vscode-remote-try-python.git") + err = f.DevsyUp(ctx, name) framework.ExpectNoError(err) // check env var diff --git a/sites/docs-devsy-sh/content/docs/developing-in-workspaces/create-a-workspace.mdx b/sites/docs-devsy-sh/content/docs/developing-in-workspaces/create-a-workspace.mdx index 38d75a3fe..6359429e5 100644 --- a/sites/docs-devsy-sh/content/docs/developing-in-workspaces/create-a-workspace.mdx +++ b/sites/docs-devsy-sh/content/docs/developing-in-workspaces/create-a-workspace.mdx @@ -104,6 +104,8 @@ devsy workspace logs WORKSPACE_NAME --source setup --run RUN_ID --result-format= The run ID appears in the result of `devsy workspace up` and in the output of a detached creation task. Use `--list` to find IDs for earlier runs. +For a detached creation, Devsy waits up to 30 seconds for the background worker to register. Workspace setup continues after the command returns. If the worker cannot register within that time, the launch fails and Devsy cleans it up. + - Hooks that run after `waitFor` (default `updateContentCommand`) can finish after `up` returns. Their output joins the same run. Add `--follow` to watch them. - A hook that an earlier attempt already marked is skipped with the reason `already_attempted`. This does not mean the earlier attempt succeeded. Check that run. - `postAttachCommand` runs on every attach. Each run is recorded separately.