Skip to content

Commit a409ccf

Browse files
hawkingreiboyan-soubachov
authored andcommitted
fix data race in the suit
Signed-off-by: Weizhen Wang <[email protected]>
1 parent 3586478 commit a409ccf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

suite/suite.go

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"reflect"
88
"regexp"
99
"runtime/debug"
10+
"sync"
1011
"testing"
1112
"time"
1213

@@ -21,24 +22,31 @@ var matchMethod = flag.String("testify.m", "", "regular expression to select tes
2122
// retrieving the current *testing.T context.
2223
type Suite struct {
2324
*assert.Assertions
25+
mu sync.Mutex
2426
require *require.Assertions
2527
t *testing.T
2628
}
2729

2830
// T retrieves the current *testing.T context.
2931
func (suite *Suite) T() *testing.T {
32+
suite.mu.Lock()
33+
defer suite.mu.Unlock()
3034
return suite.t
3135
}
3236

3337
// SetT sets the current *testing.T context.
3438
func (suite *Suite) SetT(t *testing.T) {
39+
suite.mu.Lock()
40+
defer suite.mu.Unlock()
3541
suite.t = t
3642
suite.Assertions = assert.New(t)
3743
suite.require = require.New(t)
3844
}
3945

4046
// Require returns a require context for suite.
4147
func (suite *Suite) Require() *require.Assertions {
48+
suite.mu.Lock()
49+
defer suite.mu.Unlock()
4250
if suite.require == nil {
4351
suite.require = require.New(suite.T())
4452
}
@@ -51,6 +59,8 @@ func (suite *Suite) Require() *require.Assertions {
5159
// assert.Assertions with require.Assertions), this method is provided so you
5260
// can call `suite.Assert().NoError()`.
5361
func (suite *Suite) Assert() *assert.Assertions {
62+
suite.mu.Lock()
63+
defer suite.mu.Unlock()
5464
if suite.Assertions == nil {
5565
suite.Assertions = assert.New(suite.T())
5666
}

0 commit comments

Comments
 (0)