MCPcopy Index your code
hub / github.com/coder/coder / RunReturningWorkspace

Method RunReturningWorkspace

scaletest/workspacebuild/run.go:41–105  ·  view source on GitHub ↗

Run implements Runnable.

(ctx context.Context, id string, logs io.Writer)

Source from the content-addressed store, hash-verified

39
40// Run implements Runnable.
41func (r *Runner) RunReturningWorkspace(ctx context.Context, id string, logs io.Writer) (SlimWorkspace, error) {
42 ctx, span := tracing.StartSpan(ctx)
43 defer span.End()
44
45 logs = loadtestutil.NewSyncWriter(logs)
46 logger := slog.Make(sloghuman.Sink(logs)).Leveled(slog.LevelDebug)
47 r.client.SetLogger(logger)
48 r.client.SetLogBodies(true)
49
50 req := r.cfg.Request
51 if req.Name == "" {
52 randName, err := loadtestutil.GenerateWorkspaceName(id)
53 if err != nil {
54 return SlimWorkspace{}, xerrors.Errorf("generate random name for workspace: %w", err)
55 }
56 req.Name = randName
57 }
58
59 workspace, err := r.client.CreateWorkspace(ctx, r.cfg.OrganizationID, r.cfg.UserID, req)
60 if err != nil {
61 return SlimWorkspace{}, xerrors.Errorf("create workspace: %w", err)
62 }
63 r.workspaceID = workspace.ID
64
65 if r.cfg.NoWaitForBuild {
66 _, _ = fmt.Fprintln(logs, "Skipping waiting for build")
67 } else {
68 err = waitForBuild(ctx, logs, r.client, workspace.LatestBuild.ID)
69 if err != nil {
70 for i := 0; i < r.cfg.Retry; i++ {
71 _, _ = fmt.Fprintf(logs, "Retrying build %d/%d...\n", i+1, r.cfg.Retry)
72
73 workspace.LatestBuild, err = r.client.CreateWorkspaceBuild(ctx, workspace.ID, codersdk.CreateWorkspaceBuildRequest{
74 Transition: codersdk.WorkspaceTransitionStart,
75 RichParameterValues: req.RichParameterValues,
76 TemplateVersionID: req.TemplateVersionID,
77 })
78 if err != nil {
79 return SlimWorkspace{}, xerrors.Errorf("create workspace build: %w", err)
80 }
81 err = waitForBuild(ctx, logs, r.client, workspace.LatestBuild.ID)
82 if err == nil {
83 break
84 }
85 }
86 if err != nil {
87 return SlimWorkspace{}, xerrors.Errorf("wait for build: %w", err)
88 }
89 }
90 }
91
92 if r.cfg.NoWaitForAgents {
93 _, _ = fmt.Fprintln(logs, "Skipping agent connectivity check.")
94 } else {
95 _, _ = fmt.Fprintln(logs, "")
96 err = waitForAgents(ctx, logs, r.client, workspace.ID)
97 if err != nil {
98 return SlimWorkspace{}, xerrors.Errorf("wait for agent: %w", err)

Callers 4

Test_RunnerFunction · 0.95
RunMethod · 0.95
RunReturningResultMethod · 0.80
RunMethod · 0.80

Calls 10

StartSpanFunction · 0.92
NewSyncWriterFunction · 0.92
GenerateWorkspaceNameFunction · 0.92
waitForAgentsFunction · 0.85
CreateWorkspaceMethod · 0.80
CreateWorkspaceBuildMethod · 0.80
waitForBuildFunction · 0.70
SetLoggerMethod · 0.65
SetLogBodiesMethod · 0.65
ErrorfMethod · 0.45

Tested by 1

Test_RunnerFunction · 0.76