Closed ghostiam closed 6 years ago
When testing a code that can call a function several times in parallel, we get a data race. Here is an example: https://github.com/GhostRussia/pegomockRaceBug
go test -race
================== WARNING: DATA RACE Read at 0x00c42007a210 by goroutine 8: runtime.mapaccess1() /usr/local/Cellar/go/1.9.2/libexec/src/runtime/hashmap.go:341 +0x0 github.com/GhostRussia/pegomockRaceBug/mock.(*MockRaceBug).Test1() /Users/ghost_russia/projects/golang/src/github.com/petergtz/pegomock/dsl.go:419 +0x12b Previous write at 0x00c42007a210 by goroutine 7: runtime.mapassign() /usr/local/Cellar/go/1.9.2/libexec/src/runtime/hashmap.go:521 +0x0 github.com/GhostRussia/pegomockRaceBug/mock.(*MockRaceBug).Test1() /Users/ghost_russia/projects/golang/src/github.com/petergtz/pegomock/dsl.go:420 +0x2ec Goroutine 8 (running) created at: github.com/GhostRussia/pegomockRaceBug.TestRaceBug1() /Users/ghost_russia/projects/golang/src/github.com/GhostRussia/pegomockRaceBug/racebug_test.go:15 +0xc8 testing.tRunner() /usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:746 +0x16c Goroutine 7 (finished) created at: github.com/GhostRussia/pegomockRaceBug.TestRaceBug1() /Users/ghost_russia/projects/golang/src/github.com/GhostRussia/pegomockRaceBug/racebug_test.go:15 +0xc8 testing.tRunner() /usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:746 +0x16c ==================
Maybe it's worth adding mutexes to the mock generator?
fast fix:
When testing a code that can call a function several times in parallel, we get a data race. Here is an example: https://github.com/GhostRussia/pegomockRaceBug