Skip to content

Commit

Permalink
Ensure fakeTB.mu protects reads & writes (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv authored Jan 12, 2025
1 parent b2b7089 commit 16c4228
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion fake_tb.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func newRecordingTB() *fakeTB {

func (tb *fakeTB) checkPanic() {
if r := recover(); r != nil {
tb.mu.Lock()
defer tb.mu.Unlock()

tb.panicked = true
tb.recovered = r
tb.recoverCallers = getCallers(skipSelf)
Expand All @@ -86,6 +89,7 @@ func (tb *fakeTB) checkPanic() {

func (tb *fakeTB) postTest() {
defer close(tb.completed)

tb.runCleanups()
}

Expand Down Expand Up @@ -154,6 +158,7 @@ func (tb *fakeTB) done() bool {

func (tb *fakeTB) Cleanup(f func()) {
callerPCs := getCallers(skipSelf)

tb.mu.Lock()
defer tb.mu.Unlock()

Expand Down Expand Up @@ -275,7 +280,7 @@ func (tb *fakeTB) Name() string {
}

func (tb *fakeTB) Setenv(key, value string) {
// Set the environment, but clear it on cleanup
// TODO: Set the environment, but clear it on cleanup
}

func (tb *fakeTB) Skip(args ...interface{}) {
Expand Down Expand Up @@ -309,6 +314,9 @@ func (tb *fakeTB) TempDir() string {
}

func (tb *fakeTB) helperFuncs() []string {
tb.mu.Lock()
defer tb.mu.Unlock()

funcs := make([]string, 0, len(tb.helpers))
for pc := range tb.helpers {
if fn := pcToFunction(pc); fn != "" {
Expand Down

0 comments on commit 16c4228

Please sign in to comment.