Skip to content

Commit e2e8d74

Browse files
committed
fix: avoid sharing t in TestWorkspaceBuildTimings
1 parent 4ec6871 commit e2e8d74

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5854,12 +5854,12 @@ func (q *FakeQuerier) GetWorkspaceAgentScriptTimingsByBuildID(ctx context.Contex
58545854
q.mutex.RLock()
58555855
defer q.mutex.RUnlock()
58565856

5857-
build, err := q.GetWorkspaceBuildByID(ctx, id)
5857+
build, err := q.getWorkspaceBuildByIDNoLock(ctx, id)
58585858
if err != nil {
58595859
return nil, xerrors.Errorf("get build: %w", err)
58605860
}
58615861

5862-
resources, err := q.GetWorkspaceResourcesByJobID(ctx, build.JobID)
5862+
resources, err := q.getWorkspaceResourcesByJobIDNoLock(ctx, build.JobID)
58635863
if err != nil {
58645864
return nil, xerrors.Errorf("get resources: %w", err)
58655865
}
@@ -5868,7 +5868,7 @@ func (q *FakeQuerier) GetWorkspaceAgentScriptTimingsByBuildID(ctx context.Contex
58685868
resourceIDs = append(resourceIDs, res.ID)
58695869
}
58705870

5871-
agents, err := q.GetWorkspaceAgentsByResourceIDs(ctx, resourceIDs)
5871+
agents, err := q.getWorkspaceAgentsByResourceIDsNoLock(ctx, resourceIDs)
58725872
if err != nil {
58735873
return nil, xerrors.Errorf("get agents: %w", err)
58745874
}
@@ -5877,7 +5877,7 @@ func (q *FakeQuerier) GetWorkspaceAgentScriptTimingsByBuildID(ctx context.Contex
58775877
agentIDs = append(agentIDs, agent.ID)
58785878
}
58795879

5880-
scripts, err := q.GetWorkspaceAgentScriptsByAgentIDs(ctx, agentIDs)
5880+
scripts, err := q.getWorkspaceAgentScriptsByAgentIDsNoLock(agentIDs)
58815881
if err != nil {
58825882
return nil, xerrors.Errorf("get scripts: %w", err)
58835883
}
@@ -5933,6 +5933,10 @@ func (q *FakeQuerier) GetWorkspaceAgentScriptsByAgentIDs(_ context.Context, ids
59335933
q.mutex.RLock()
59345934
defer q.mutex.RUnlock()
59355935

5936+
return q.getWorkspaceAgentScriptsByAgentIDsNoLock(ids)
5937+
}
5938+
5939+
func (q *FakeQuerier) getWorkspaceAgentScriptsByAgentIDsNoLock(ids []uuid.UUID) ([]database.WorkspaceAgentScript, error) {
59365940
scripts := make([]database.WorkspaceAgentScript, 0)
59375941
for _, script := range q.workspaceAgentScripts {
59385942
for _, id := range ids {

coderd/workspacebuilds_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ func TestWorkspaceBuildTimings(t *testing.T) {
12191219

12201220
// Tests will run in parallel. To avoid conflicts and race conditions on the
12211221
// build number, each test will have its own workspace and build.
1222-
makeBuild := func() database.WorkspaceBuild {
1222+
makeBuild := func(t *testing.T) database.WorkspaceBuild {
12231223
ws := dbgen.Workspace(t, db, database.WorkspaceTable{
12241224
OwnerID: user.ID,
12251225
OrganizationID: owner.OrganizationID,
@@ -1260,7 +1260,7 @@ func TestWorkspaceBuildTimings(t *testing.T) {
12601260
t.Parallel()
12611261

12621262
// Given: a build with no timings
1263-
build := makeBuild()
1263+
build := makeBuild(t)
12641264

12651265
// When: fetching timings for the build
12661266
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
@@ -1277,7 +1277,7 @@ func TestWorkspaceBuildTimings(t *testing.T) {
12771277
t.Parallel()
12781278

12791279
// Given: a build with provisioner timings
1280-
build := makeBuild()
1280+
build := makeBuild(t)
12811281
provisionerTimings := dbgen.ProvisionerJobTimings(t, db, build, 5)
12821282

12831283
// When: fetching timings for the build
@@ -1305,7 +1305,7 @@ func TestWorkspaceBuildTimings(t *testing.T) {
13051305
t.Parallel()
13061306

13071307
// Given: a build with agent script timings
1308-
build := makeBuild()
1308+
build := makeBuild(t)
13091309
resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{
13101310
JobID: build.JobID,
13111311
})
@@ -1342,7 +1342,7 @@ func TestWorkspaceBuildTimings(t *testing.T) {
13421342
t.Parallel()
13431343

13441344
// Given: a build with no agent scripts
1345-
build := makeBuild()
1345+
build := makeBuild(t)
13461346
resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{
13471347
JobID: build.JobID,
13481348
})
@@ -1365,7 +1365,7 @@ func TestWorkspaceBuildTimings(t *testing.T) {
13651365
t.Parallel()
13661366

13671367
// Given: a build with no agents
1368-
build := makeBuild()
1368+
build := makeBuild(t)
13691369
dbgen.WorkspaceResource(t, db, database.WorkspaceResource{
13701370
JobID: build.JobID,
13711371
})
@@ -1385,7 +1385,7 @@ func TestWorkspaceBuildTimings(t *testing.T) {
13851385
t.Parallel()
13861386

13871387
// Given: a build with an agent
1388-
build := makeBuild()
1388+
build := makeBuild(t)
13891389
resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{
13901390
JobID: build.JobID,
13911391
})
@@ -1414,7 +1414,7 @@ func TestWorkspaceBuildTimings(t *testing.T) {
14141414
t.Parallel()
14151415

14161416
// Given: a build with multiple agents
1417-
build := makeBuild()
1417+
build := makeBuild(t)
14181418
resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{
14191419
JobID: build.JobID,
14201420
})

0 commit comments

Comments
 (0)