Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor(scaletest): make workspacebuild return the built workspace#19997

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 1 commit intomainfromethan/scaletest-wsbuild-return-ws
Sep 30, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
14 changes: 2 additions & 12 deletionsscaletest/createworkspaces/run.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -87,7 +87,7 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
workspaceBuildConfig.OrganizationID = r.cfg.User.OrganizationID
workspaceBuildConfig.UserID = user.ID.String()
r.workspacebuildRunner = workspacebuild.NewRunner(client, workspaceBuildConfig)
err = r.workspacebuildRunner.Run(ctx, id, logs)
workspace,err:= r.workspacebuildRunner.RunReturningWorkspace(ctx, id, logs)
if err != nil {
return xerrors.Errorf("create workspace: %w", err)
}
Expand All@@ -96,16 +96,6 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
return nil
}

// Get the workspace.
workspaceID, err := r.workspacebuildRunner.WorkspaceID()
if err != nil {
return xerrors.Errorf("get workspace ID: %w", err)
}
workspace, err := client.Workspace(ctx, workspaceID)
if err != nil {
return xerrors.Errorf("get workspace %q: %w", workspaceID.String(), err)
}

// Find the first agent.
var agent codersdk.WorkspaceAgent
resourceLoop:
Expand All@@ -116,7 +106,7 @@ resourceLoop:
}
}
if agent.ID == uuid.Nil {
return xerrors.Errorf("no agents found for workspace %q",workspaceID.String())
return xerrors.Errorf("no agents found for workspace %q",workspace.ID.String())
}

eg, egCtx := errgroup.WithContext(ctx)
Expand Down
28 changes: 10 additions & 18 deletionsscaletest/workspacebuild/run.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,11 +26,6 @@ type Runner struct {
workspaceID uuid.UUID
}

var (
_ harness.Runnable = &Runner{}
_ harness.Cleanable = &Runner{}
)

func NewRunner(client *codersdk.Client, cfg Config) *Runner {
return &Runner{
client: client,
Expand All@@ -39,7 +34,7 @@ func NewRunner(client *codersdk.Client, cfg Config) *Runner {
}

// Run implements Runnable.
func (r *Runner)Run(ctx context.Context, id string, logs io.Writer) error {
func (r *Runner)RunReturningWorkspace(ctx context.Context, id string, logs io.Writer)(codersdk.Workspace,error) {
ctx, span := tracing.StartSpan(ctx)
defer span.End()

Expand All@@ -52,14 +47,14 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
if req.Name == "" {
randName, err := loadtestutil.GenerateWorkspaceName(id)
if err != nil {
return xerrors.Errorf("generate random name for workspace: %w", err)
returncodersdk.Workspace{},xerrors.Errorf("generate random name for workspace: %w", err)
}
req.Name = randName
}

workspace, err := r.client.CreateWorkspace(ctx, r.cfg.OrganizationID, r.cfg.UserID, req)
if err != nil {
return xerrors.Errorf("create workspace: %w", err)
returncodersdk.Workspace{},xerrors.Errorf("create workspace: %w", err)
}
r.workspaceID = workspace.ID

Expand All@@ -74,15 +69,15 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
TemplateVersionID: req.TemplateVersionID,
})
if err != nil {
return xerrors.Errorf("create workspace build: %w", err)
returncodersdk.Workspace{},xerrors.Errorf("create workspace build: %w", err)
}
err = waitForBuild(ctx, logs, r.client, workspace.LatestBuild.ID)
if err == nil {
break
}
}
if err != nil {
return xerrors.Errorf("wait for build: %w", err)
returncodersdk.Workspace{},xerrors.Errorf("wait for build: %w", err)
}
}

Expand All@@ -92,19 +87,16 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
_, _ = fmt.Fprintln(logs, "")
err = waitForAgents(ctx, logs, r.client, workspace.ID)
if err != nil {
return xerrors.Errorf("wait for agent: %w", err)
returncodersdk.Workspace{},xerrors.Errorf("wait for agent: %w", err)
}
}

return nil
}

func (r *Runner) WorkspaceID() (uuid.UUID, error) {
if r.workspaceID == uuid.Nil {
return uuid.Nil, xerrors.New("workspace ID not set")
workspace, err = r.client.Workspace(ctx, workspace.ID)
if err != nil {
return codersdk.Workspace{}, xerrors.Errorf("get workspace %q: %w", workspace.ID.String(), err)
}

returnr.workspaceID, nil
returnworkspace, nil
}

// CleanupRunner is a runner that deletes a workspace in the Run phase.
Expand Down
6 changes: 3 additions & 3 deletionsscaletest/workspacebuild/run_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -158,7 +158,7 @@ func Test_Runner(t *testing.T) {
})

logs := bytes.NewBuffer(nil)
err := runner.Run(ctx, "1", logs)
_,err := runner.RunReturningWorkspace(ctx, "1", logs)
logsStr := logs.String()
t.Log("Runner logs:\n\n" + logsStr)
require.NoError(t, err)
Expand DownExpand Up@@ -224,7 +224,7 @@ func Test_Runner(t *testing.T) {
})

logs := bytes.NewBuffer(nil)
err := runner.Run(ctx, "1", logs)
_,err := runner.RunReturningWorkspace(ctx, "1", logs)
logsStr := logs.String()
t.Log("Runner logs:\n\n" + logsStr)
require.Error(t, err)
Expand DownExpand Up@@ -271,7 +271,7 @@ func Test_Runner(t *testing.T) {
})

logs := bytes.NewBuffer(nil)
err := runner.Run(ctx, "1", logs)
_,err := runner.RunReturningWorkspace(ctx, "1", logs)
logsStr := logs.String()
t.Log("Runner logs:\n\n" + logsStr)
require.Error(t, err)
Expand Down
2 changes: 1 addition & 1 deletionscaletest/workspaceupdates/run.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -126,7 +126,7 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
r.workspaces[workspaceName] = &workspace{
buildStartTime: time.Now(),
}
err = runner.Run(ctx, fmt.Sprintf("%s-%d", id, i), logs)
_,err = runner.RunReturningWorkspace(ctx, fmt.Sprintf("%s-%d", id, i), logs)
if err != nil {
return xerrors.Errorf("create workspace %d: %w", i, err)
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp