aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2019-03-03 14:09:33 +0100
committerJakob Unterwurzacher2019-03-03 14:09:33 +0100
commitcd7a6862116dc3bac11d2a67fe93f20a7afc7284 (patch)
treea075aebf92ea677f16ea89f5097b38bbb5abca27
parentcf27037f20723e934320edeff7f8aa356bdca467 (diff)
tests: fix data race in TestDirIVRace
Ironically, the test for DirIV races had a data race itself by writing to a bool without taking a lock. Found by running "./test.bash -race": WARNING: DATA RACE Write at 0x00c00001dea5 by goroutine 22: github.com/rfjakob/gocryptfs/tests/defaults.TestDirIVRace.func1() /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/defaults/diriv_test.go:39 +0x38 github.com/rfjakob/gocryptfs/tests/defaults.TestDirIVRace() /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/defaults/diriv_test.go:73 +0x65c testing.tRunner() /usr/local/go/src/testing/testing.go:865 +0x163 Previous read at 0x00c00001dea5 by goroutine 23: github.com/rfjakob/gocryptfs/tests/defaults.TestDirIVRace.func2() /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/defaults/diriv_test.go:51 +0x8b Goroutine 22 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:916 +0x699 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1157 +0xa8 testing.tRunner() /usr/local/go/src/testing/testing.go:865 +0x163 testing.runTests() /usr/local/go/src/testing/testing.go:1155 +0x523 testing.(*M).Run() /usr/local/go/src/testing/testing.go:1072 +0x2eb github.com/rfjakob/gocryptfs/tests/defaults.TestMain() /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/defaults/main_test.go:21 +0xe1 main.main() _testmain.go:76 +0x222 Goroutine 23 (running) created at: github.com/rfjakob/gocryptfs/tests/defaults.TestDirIVRace() /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/defaults/diriv_test.go:43 +0x48d testing.tRunner() /usr/local/go/src/testing/testing.go:865 +0x163 ================== --- FAIL: TestDirIVRace (0.00s) testing.go:809: race detected during execution of test FAIL
-rw-r--r--tests/defaults/diriv_test.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/defaults/diriv_test.go b/tests/defaults/diriv_test.go
index 9aba1f2..bf8f233 100644
--- a/tests/defaults/diriv_test.go
+++ b/tests/defaults/diriv_test.go
@@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"sync"
+ "sync/atomic"
"syscall"
"testing"
"time"
@@ -35,8 +36,8 @@ func TestDirIVRace(t *testing.T) {
t.Fatal(err)
}
- stop := false
- defer func() { stop = true }()
+ var stop int32
+ defer func() { atomic.StoreInt32(&stop, 1) }()
var wg sync.WaitGroup
wg.Add(1)
@@ -48,7 +49,7 @@ func TestDirIVRace(t *testing.T) {
if err2 == nil {
fd.Close()
}
- if stop {
+ if atomic.LoadInt32(&stop) != 0 {
return
}
}