Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 14 additions & 7 deletions cmd/workspace/up/detach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand All @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions cmd/workspace/up/launch_handoff_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package up

import (
"context"
"os"
"os/exec"
"testing"
Expand All @@ -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(
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions e2e/tests/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading