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

Commitec417de

Browse files
refactor(scaletest): make workspacebuild return the built workspace (#19997)
Similar idea as in#19811, this runner doesn't need to conform to `Runnable`, so we have it return the workspace from the `RunReturningWorkspace` function, instead of the more fragile `Run`, followed by a `.WorkspaceID()`.
1 parent0be9221 commitec417de

File tree

4 files changed

+16
-34
lines changed

4 files changed

+16
-34
lines changed

‎scaletest/createworkspaces/run.go‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
8787
workspaceBuildConfig.OrganizationID=r.cfg.User.OrganizationID
8888
workspaceBuildConfig.UserID=user.ID.String()
8989
r.workspacebuildRunner=workspacebuild.NewRunner(client,workspaceBuildConfig)
90-
err=r.workspacebuildRunner.Run(ctx,id,logs)
90+
workspace,err:=r.workspacebuildRunner.RunReturningWorkspace(ctx,id,logs)
9191
iferr!=nil {
9292
returnxerrors.Errorf("create workspace: %w",err)
9393
}
@@ -96,16 +96,6 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
9696
returnnil
9797
}
9898

99-
// Get the workspace.
100-
workspaceID,err:=r.workspacebuildRunner.WorkspaceID()
101-
iferr!=nil {
102-
returnxerrors.Errorf("get workspace ID: %w",err)
103-
}
104-
workspace,err:=client.Workspace(ctx,workspaceID)
105-
iferr!=nil {
106-
returnxerrors.Errorf("get workspace %q: %w",workspaceID.String(),err)
107-
}
108-
10999
// Find the first agent.
110100
varagent codersdk.WorkspaceAgent
111101
resourceLoop:
@@ -116,7 +106,7 @@ resourceLoop:
116106
}
117107
}
118108
ifagent.ID==uuid.Nil {
119-
returnxerrors.Errorf("no agents found for workspace %q",workspaceID.String())
109+
returnxerrors.Errorf("no agents found for workspace %q",workspace.ID.String())
120110
}
121111

122112
eg,egCtx:=errgroup.WithContext(ctx)

‎scaletest/workspacebuild/run.go‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ type Runner struct {
2626
workspaceID uuid.UUID
2727
}
2828

29-
var (
30-
_ harness.Runnable=&Runner{}
31-
_ harness.Cleanable=&Runner{}
32-
)
33-
3429
funcNewRunner(client*codersdk.Client,cfgConfig)*Runner {
3530
return&Runner{
3631
client:client,
@@ -39,7 +34,7 @@ func NewRunner(client *codersdk.Client, cfg Config) *Runner {
3934
}
4035

4136
// Run implements Runnable.
42-
func (r*Runner)Run(ctx context.Context,idstring,logs io.Writer)error {
37+
func (r*Runner)RunReturningWorkspace(ctx context.Context,idstring,logs io.Writer)(codersdk.Workspace,error) {
4338
ctx,span:=tracing.StartSpan(ctx)
4439
deferspan.End()
4540

@@ -52,14 +47,14 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
5247
ifreq.Name=="" {
5348
randName,err:=loadtestutil.GenerateWorkspaceName(id)
5449
iferr!=nil {
55-
returnxerrors.Errorf("generate random name for workspace: %w",err)
50+
returncodersdk.Workspace{},xerrors.Errorf("generate random name for workspace: %w",err)
5651
}
5752
req.Name=randName
5853
}
5954

6055
workspace,err:=r.client.CreateWorkspace(ctx,r.cfg.OrganizationID,r.cfg.UserID,req)
6156
iferr!=nil {
62-
returnxerrors.Errorf("create workspace: %w",err)
57+
returncodersdk.Workspace{},xerrors.Errorf("create workspace: %w",err)
6358
}
6459
r.workspaceID=workspace.ID
6560

@@ -74,15 +69,15 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
7469
TemplateVersionID:req.TemplateVersionID,
7570
})
7671
iferr!=nil {
77-
returnxerrors.Errorf("create workspace build: %w",err)
72+
returncodersdk.Workspace{},xerrors.Errorf("create workspace build: %w",err)
7873
}
7974
err=waitForBuild(ctx,logs,r.client,workspace.LatestBuild.ID)
8075
iferr==nil {
8176
break
8277
}
8378
}
8479
iferr!=nil {
85-
returnxerrors.Errorf("wait for build: %w",err)
80+
returncodersdk.Workspace{},xerrors.Errorf("wait for build: %w",err)
8681
}
8782
}
8883

@@ -92,19 +87,16 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
9287
_,_=fmt.Fprintln(logs,"")
9388
err=waitForAgents(ctx,logs,r.client,workspace.ID)
9489
iferr!=nil {
95-
returnxerrors.Errorf("wait for agent: %w",err)
90+
returncodersdk.Workspace{},xerrors.Errorf("wait for agent: %w",err)
9691
}
9792
}
9893

99-
returnnil
100-
}
101-
102-
func (r*Runner)WorkspaceID() (uuid.UUID,error) {
103-
ifr.workspaceID==uuid.Nil {
104-
returnuuid.Nil,xerrors.New("workspace ID not set")
94+
workspace,err=r.client.Workspace(ctx,workspace.ID)
95+
iferr!=nil {
96+
return codersdk.Workspace{},xerrors.Errorf("get workspace %q: %w",workspace.ID.String(),err)
10597
}
10698

107-
returnr.workspaceID,nil
99+
returnworkspace,nil
108100
}
109101

110102
// CleanupRunner is a runner that deletes a workspace in the Run phase.

‎scaletest/workspacebuild/run_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func Test_Runner(t *testing.T) {
158158
})
159159

160160
logs:=bytes.NewBuffer(nil)
161-
err:=runner.Run(ctx,"1",logs)
161+
_,err:=runner.RunReturningWorkspace(ctx,"1",logs)
162162
logsStr:=logs.String()
163163
t.Log("Runner logs:\n\n"+logsStr)
164164
require.NoError(t,err)
@@ -224,7 +224,7 @@ func Test_Runner(t *testing.T) {
224224
})
225225

226226
logs:=bytes.NewBuffer(nil)
227-
err:=runner.Run(ctx,"1",logs)
227+
_,err:=runner.RunReturningWorkspace(ctx,"1",logs)
228228
logsStr:=logs.String()
229229
t.Log("Runner logs:\n\n"+logsStr)
230230
require.Error(t,err)
@@ -271,7 +271,7 @@ func Test_Runner(t *testing.T) {
271271
})
272272

273273
logs:=bytes.NewBuffer(nil)
274-
err:=runner.Run(ctx,"1",logs)
274+
_,err:=runner.RunReturningWorkspace(ctx,"1",logs)
275275
logsStr:=logs.String()
276276
t.Log("Runner logs:\n\n"+logsStr)
277277
require.Error(t,err)

‎scaletest/workspaceupdates/run.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
126126
r.workspaces[workspaceName]=&workspace{
127127
buildStartTime:time.Now(),
128128
}
129-
err=runner.Run(ctx,fmt.Sprintf("%s-%d",id,i),logs)
129+
_,err=runner.RunReturningWorkspace(ctx,fmt.Sprintf("%s-%d",id,i),logs)
130130
iferr!=nil {
131131
returnxerrors.Errorf("create workspace %d: %w",i,err)
132132
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp