Skip to content

Commit

Permalink
Merge pull request #12 from cego/race-detector-test
Browse files Browse the repository at this point in the history
Fixed TestConcurrency *itself* when testing with the race detector
  • Loading branch information
Anders Brander authored Jan 28, 2020
2 parents c2e77b1 + bd87cfd commit 72d3705
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"reflect"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -327,6 +328,8 @@ keep latest 1
}

func TestConcurrency(t *testing.T) {
var lock sync.Mutex

tmpfile, _ := ioutil.TempFile("/dev/shm", "test.TestReadConfSyntaxError")
defer os.Remove(tmpfile.Name())

Expand All @@ -337,9 +340,13 @@ func TestConcurrency(t *testing.T) {
// This will force clean() to wait for our mainWaitGroup.Done().
mainWaitGroup.Add(1)

lock.Lock()

var cleanErr error
go func() {
cleanErr = clean(nil, []string{tmpfile.Name()})

lock.Unlock()
}()

// Give some time for the first clean() to acquire the lock.
Expand All @@ -353,6 +360,8 @@ func TestConcurrency(t *testing.T) {
// Let the first clean() exit.
mainWaitGroup.Done()

lock.Lock()

if cleanErr != nil {
t.Fatalf("clean() returned an error: %s", cleanErr.Error())
}
Expand Down

0 comments on commit 72d3705

Please sign in to comment.