goburrow / cache

Mango Cache 🥭 - Partial implementation of Guava Cache in Go (golang).
BSD 3-Clause "New" or "Revised" License
574 stars 48 forks source link

Data races in tests #2

Closed davecheney closed 7 years ago

davecheney commented 7 years ago
% go test -race
==================
WARNING: DATA RACE
Read at 0x00c42010a000 by goroutine 10:
  github.com/goburrow/cache.TestMaximumSize()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:62 +0x47d
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228

Previous write at 0x00c42010a000 by goroutine 11:
  runtime.mapassign()
      /home/dfc/go/src/runtime/hashmap.go:485 +0x0
  github.com/goburrow/cache.(*slruCache).hit()
      /home/dfc/src/github.com/goburrow/cache/lru.go:168 +0x234
  github.com/goburrow/cache.(*localCache).hit()
      /home/dfc/src/github.com/goburrow/cache/local.go:226 +0x113
  github.com/goburrow/cache.(*localCache).processEntries()
      /home/dfc/src/github.com/goburrow/cache/local.go:167 +0x20c

Goroutine 10 (running) created at:
  testing.(*T).Run()
      /home/dfc/go/src/testing/testing.go:716 +0x53c
  testing.runTests.func1()
      /home/dfc/go/src/testing/testing.go:900 +0xaa
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228
  testing.runTests()
      /home/dfc/go/src/testing/testing.go:906 +0x4ac
  testing.(*M).Run()
      /home/dfc/go/src/testing/testing.go:841 +0x1c3
  main.main()
      github.com/goburrow/cache/_test/_testmain.go:86 +0x20f

Goroutine 11 (running) created at:
  github.com/goburrow/cache.(*localCache).init()
      /home/dfc/src/github.com/goburrow/cache/local.go:70 +0x2be
  github.com/goburrow/cache.New()
      /home/dfc/src/github.com/goburrow/cache/local.go:318 +0x1ed
  github.com/goburrow/cache.TestMaximumSize()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:46 +0x1b0
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228
==================
--- FAIL: TestMaximumSize (0.22s)
    testing.go:632: race detected during execution of test
==================
WARNING: DATA RACE
Write at 0x0000006f3a58 by goroutine 21:
  github.com/goburrow/cache.TestExpireAfterAccess()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:216 +0x1b2
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228

Previous read at 0x0000006f3a58 by goroutine 9:
  github.com/goburrow/cache.(*localCache).hit()
      /home/dfc/src/github.com/goburrow/cache/local.go:225 +0x72
  github.com/goburrow/cache.(*localCache).processEntries()
      /home/dfc/src/github.com/goburrow/cache/local.go:167 +0x20c

Goroutine 21 (running) created at:
  testing.(*T).Run()
      /home/dfc/go/src/testing/testing.go:716 +0x53c
  testing.runTests.func1()
      /home/dfc/go/src/testing/testing.go:900 +0xaa
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228
  testing.runTests()
      /home/dfc/go/src/testing/testing.go:906 +0x4ac
  testing.(*M).Run()
      /home/dfc/go/src/testing/testing.go:841 +0x1c3
  main.main()
      github.com/goburrow/cache/_test/_testmain.go:86 +0x20f

Goroutine 9 (finished) created at:
  github.com/goburrow/cache.(*localCache).init()
      /home/dfc/src/github.com/goburrow/cache/local.go:70 +0x2be
  github.com/goburrow/cache.New()
      /home/dfc/src/github.com/goburrow/cache/local.go:318 +0x1ed
  github.com/goburrow/cache.TestCache()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:23 +0x1bb
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228
==================
==================
WARNING: DATA RACE
Write at 0x00c42010e198 by goroutine 21:
  github.com/goburrow/cache.(*slruCache).remove()
      /home/dfc/src/github.com/goburrow/cache/lru.go:248 +0x525
  github.com/goburrow/cache.(*localCache).remove()
      /home/dfc/src/github.com/goburrow/cache/local.go:216 +0x61
  github.com/goburrow/cache.(*localCache).expireEntries.func1()
      /home/dfc/src/github.com/goburrow/cache/local.go:306 +0x157
  github.com/goburrow/cache.(*slruCache).walk()
      /home/dfc/src/github.com/goburrow/cache/lru.go:269 +0x5a
  github.com/goburrow/cache.(*localCache).expireEntries()
      /home/dfc/src/github.com/goburrow/cache/local.go:309 +0x23f
  github.com/goburrow/cache.TestExpireAfterAccess()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:239 +0x5ec
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228

Previous read at 0x00c42010e198 by goroutine 22:
  github.com/goburrow/cache.(*localCache).expireEntries.func1()
      /home/dfc/src/github.com/goburrow/cache/local.go:296 +0x220
  github.com/goburrow/cache.(*slruCache).walk()
      /home/dfc/src/github.com/goburrow/cache/lru.go:269 +0x5a
  github.com/goburrow/cache.(*localCache).expireEntries()
      /home/dfc/src/github.com/goburrow/cache/local.go:309 +0x23f
  github.com/goburrow/cache.(*localCache).postWriteCleanup()
      /home/dfc/src/github.com/goburrow/cache/local.go:284 +0x57
  github.com/goburrow/cache.(*localCache).processEntries()
      /home/dfc/src/github.com/goburrow/cache/local.go:165 +0x1c1

Goroutine 21 (running) created at:
  testing.(*T).Run()
      /home/dfc/go/src/testing/testing.go:716 +0x53c
  testing.runTests.func1()
      /home/dfc/go/src/testing/testing.go:900 +0xaa
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228
  testing.runTests()
      /home/dfc/go/src/testing/testing.go:906 +0x4ac
  testing.(*M).Run()
      /home/dfc/go/src/testing/testing.go:841 +0x1c3
  main.main()
      github.com/goburrow/cache/_test/_testmain.go:86 +0x20f

Goroutine 22 (running) created at:
  github.com/goburrow/cache.(*localCache).init()
      /home/dfc/src/github.com/goburrow/cache/local.go:70 +0x2be
  github.com/goburrow/cache.NewLoadingCache()
      /home/dfc/src/github.com/goburrow/cache/local.go:330 +0x221
  github.com/goburrow/cache.TestExpireAfterAccess()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:220 +0x290
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228
==================
==================
WARNING: DATA RACE
Write at 0x00c42010e1b8 by goroutine 21:
  github.com/goburrow/cache.(*slruCache).remove()
      /home/dfc/src/github.com/goburrow/cache/lru.go:248 +0x61d
  github.com/goburrow/cache.(*localCache).remove()
      /home/dfc/src/github.com/goburrow/cache/local.go:216 +0x61
  github.com/goburrow/cache.(*localCache).expireEntries.func1()
      /home/dfc/src/github.com/goburrow/cache/local.go:306 +0x157
  github.com/goburrow/cache.(*slruCache).walk()
      /home/dfc/src/github.com/goburrow/cache/lru.go:269 +0x5a
  github.com/goburrow/cache.(*localCache).expireEntries()
      /home/dfc/src/github.com/goburrow/cache/local.go:309 +0x23f
  github.com/goburrow/cache.TestExpireAfterAccess()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:239 +0x5ec
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228

Previous read at 0x00c42010e1b8 by goroutine 22:
  github.com/goburrow/cache.(*localCache).expireEntries.func1()
      /home/dfc/src/github.com/goburrow/cache/local.go:296 +0x82
  github.com/goburrow/cache.(*slruCache).walk()
      /home/dfc/src/github.com/goburrow/cache/lru.go:269 +0x5a
  github.com/goburrow/cache.(*localCache).expireEntries()
      /home/dfc/src/github.com/goburrow/cache/local.go:309 +0x23f
  github.com/goburrow/cache.(*localCache).postWriteCleanup()
      /home/dfc/src/github.com/goburrow/cache/local.go:284 +0x57
  github.com/goburrow/cache.(*localCache).processEntries()
      /home/dfc/src/github.com/goburrow/cache/local.go:165 +0x1c1

Goroutine 21 (running) created at:
  testing.(*T).Run()
      /home/dfc/go/src/testing/testing.go:716 +0x53c
  testing.runTests.func1()
      /home/dfc/go/src/testing/testing.go:900 +0xaa
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228
  testing.runTests()
      /home/dfc/go/src/testing/testing.go:906 +0x4ac
  testing.(*M).Run()
      /home/dfc/go/src/testing/testing.go:841 +0x1c3
  main.main()
      github.com/goburrow/cache/_test/_testmain.go:86 +0x20f

Goroutine 22 (running) created at:
  github.com/goburrow/cache.(*localCache).init()
      /home/dfc/src/github.com/goburrow/cache/local.go:70 +0x2be
  github.com/goburrow/cache.NewLoadingCache()
      /home/dfc/src/github.com/goburrow/cache/local.go:330 +0x221
  github.com/goburrow/cache.TestExpireAfterAccess()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:220 +0x290
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228
==================
--- FAIL: TestExpireAfterAccess (0.00s)
    testing.go:632: race detected during execution of test
==================
WARNING: DATA RACE
Read at 0x00c42008ea88 by goroutine 24:
  github.com/goburrow/cache.TestRefreshAfterWrite.func5()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:285 +0x4e
  github.com/goburrow/cache.(*localCache).hit()
      /home/dfc/src/github.com/goburrow/cache/local.go:225 +0x7e
  github.com/goburrow/cache.(*localCache).processEntries()
      /home/dfc/src/github.com/goburrow/cache/local.go:167 +0x20c

Previous write at 0x00c42008ea88 by goroutine 23:
  github.com/goburrow/cache.TestRefreshAfterWrite()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:284 +0x9b0
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228

Goroutine 24 (running) created at:
  github.com/goburrow/cache.(*localCache).init()
      /home/dfc/src/github.com/goburrow/cache/local.go:70 +0x2be
  github.com/goburrow/cache.NewLoadingCache()
      /home/dfc/src/github.com/goburrow/cache/local.go:330 +0x221
  github.com/goburrow/cache.TestRefreshAfterWrite()
      /home/dfc/src/github.com/goburrow/cache/local_test.go:260 +0x33e
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228

Goroutine 23 (running) created at:
  testing.(*T).Run()
      /home/dfc/go/src/testing/testing.go:716 +0x53c
  testing.runTests.func1()
      /home/dfc/go/src/testing/testing.go:900 +0xaa
  testing.tRunner()
      /home/dfc/go/src/testing/testing.go:679 +0x228
  testing.runTests()
      /home/dfc/go/src/testing/testing.go:906 +0x4ac
  testing.(*M).Run()
      /home/dfc/go/src/testing/testing.go:841 +0x1c3
  main.main()
      github.com/goburrow/cache/_test/_testmain.go:86 +0x20f
==================
--- FAIL: TestRefreshAfterWrite (0.00s)
    testing.go:632: race detected during execution of test
FAIL
FAIL    github.com/goburrow/cache   0.388s
nqv commented 7 years ago

Thanks, I'll take a look.

nqv commented 7 years ago

I've fixed the races, also will refactor/improve those tests when possible. Thank you again.