Skip to content

Commit ee79d1e

Browse files
committed
fix data race on background log with xmany tests
1 parent 92761da commit ee79d1e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

internal/xtest/manytimes.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ func TestManyTimes(t testing.TB, test TestFunc, opts ...TestManyTimesOption) {
3838
}
3939

4040
start := time.Now()
41+
var testMutex sync.Mutex
4142
for {
4243
testCounter++
4344
// run test, then check stopAfter for guarantee run test least once
44-
runTest(t, test)
45+
runTest(t, test, &testMutex)
4546

4647
if time.Since(start) > options.stopAfter || t.Failed() {
4748
return
@@ -60,11 +61,12 @@ func TestManyTimesWithName(t *testing.T, name string, test TestFunc) {
6061

6162
type TestFunc func(t testing.TB)
6263

63-
func runTest(t testing.TB, test TestFunc) {
64+
func runTest(t testing.TB, test TestFunc, testMutex *sync.Mutex) {
6465
t.Helper()
6566

6667
tw := &testWrapper{
6768
TB: t,
69+
m: testMutex,
6870
}
6971

7072
defer tw.doCleanup()
@@ -75,7 +77,7 @@ func runTest(t testing.TB, test TestFunc) {
7577
type testWrapper struct {
7678
testing.TB
7779

78-
m sync.Mutex
80+
m *sync.Mutex
7981
logs []logRecord
8082
cleanup []func()
8183
}

0 commit comments

Comments
 (0)