Skip to content

Commit e771994

Browse files
dmitshurgopherbot
authored andcommitted
internal/task: synchronize map access in FakeGerrit test helper
As https://ci.chromium.org/b/8729261949578211409 showed, MailDLCL and CreateAutoSubmitVersionCL can call CreateAutoSubmitChange at the same time. Guard map access with a mutex. For golang/go#70655. Fixes golang/go#70694. Change-Id: Ib22d647458af18669a35acf5f45d6f0a1959eb81 Reviewed-on: https://go-review.googlesource.com/c/build/+/634355 Reviewed-by: Carlos Amedee <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent 3a86a17 commit e771994

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/task/fakes.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ func NewFakeGerrit(t *testing.T, repos ...*FakeRepo) *FakeGerrit {
113113
}
114114

115115
type FakeGerrit struct {
116-
repos map[string]*FakeRepo // Repo name → repo.
117-
changes map[string]string // Change ID → commit hash.
118116
serverURL string
117+
repos map[string]*FakeRepo // Repo name → repo.
118+
changesMu sync.Mutex
119+
changes map[string]string // Change ID → commit hash.
119120
}
120121

121122
type FakeRepo struct {
@@ -342,13 +343,17 @@ func (g *FakeGerrit) CreateAutoSubmitChange(_ *wf.TaskContext, input gerrit.Chan
342343
return "", err
343344
}
344345
commit := repo.CommitOnBranch(input.Branch, contents)
346+
g.changesMu.Lock()
345347
changeID := fmt.Sprintf("%s~%d", repo.name, len(g.changes)+1)
346348
g.changes[changeID] = commit
349+
g.changesMu.Unlock()
347350
return changeID, nil
348351
}
349352

350353
func (g *FakeGerrit) Submitted(ctx context.Context, changeID, baseCommit string) (string, bool, error) {
354+
g.changesMu.Lock()
351355
commit, ok := g.changes[changeID]
356+
g.changesMu.Unlock()
352357
return commit, ok, nil
353358
}
354359

0 commit comments

Comments
 (0)