Closed shensuie closed 1 year ago
go test -v -race ./...
$ go test -v -race ./... === RUN TestGoPoolWithMutex --- PASS: TestGoPoolWithMutex (0.11s) === RUN TestGoPoolWithSpinLock --- PASS: TestGoPoolWithSpinLock (0.11s) === RUN TestGoPoolWithError --- PASS: TestGoPoolWithError (0.11s) === RUN TestGoPoolWithResult --- PASS: TestGoPoolWithResult (0.11s) === RUN TestGoPoolWithRetry ================== WARNING: DATA RACE Read at 0x00c00001c258 by goroutine 423: github.com/devchat-ai/gopool.TestGoPoolWithRetry() /workspaces/gopool/gopool_test.go:147 +0x284 testing.tRunner() /usr/local/go/src/testing/testing.go:1576 +0x216 testing.(*T).Run.func1() /usr/local/go/src/testing/testing.go:1629 +0x47 Previous write at 0x00c00001c258 by goroutine 523: github.com/devchat-ai/gopool.TestGoPoolWithRetry.func1() /workspaces/gopool/gopool_test.go:138 +0x64 github.com/devchat-ai/gopool.(*worker).executeTaskWithoutTimeout() /workspaces/gopool/worker.go:78 +0xd1 github.com/devchat-ai/gopool.(*worker).executeTask() /workspaces/gopool/worker.go:41 +0xc7 github.com/devchat-ai/gopool.(*worker).start.func1() /workspaces/gopool/worker.go:26 +0xaa Goroutine 423 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:1629 +0x805 testing.runTests.func1() /usr/local/go/src/testing/testing.go:2036 +0x8d testing.tRunner() /usr/local/go/src/testing/testing.go:1576 +0x216 testing.runTests() /usr/local/go/src/testing/testing.go:2034 +0x87c testing.(*M).Run() /usr/local/go/src/testing/testing.go:1906 +0xb44 main.main() _testmain.go:61 +0x2e9 Goroutine 523 (running) created at: github.com/devchat-ai/gopool.(*worker).start() /workspaces/gopool/worker.go:23 +0xf7 github.com/devchat-ai/gopool.NewGoPool() /workspaces/gopool/gopool.go:75 +0x54f github.com/devchat-ai/gopool.TestGoPoolWithRetry() /workspaces/gopool/gopool_test.go:134 +0xfb testing.tRunner() /usr/local/go/src/testing/testing.go:1576 +0x216 testing.(*T).Run.func1() /usr/local/go/src/testing/testing.go:1629 +0x47 ================== testing.go:1446: race detected during execution of test --- FAIL: TestGoPoolWithRetry (0.10s) === NAME testing.go:1446: race detected during execution of test FAIL FAIL github.com/devchat-ai/gopool 0.558s FAIL
get it.
I wrote a blog for this issue: 让 GPT-4 来修复 Golang “数据竞争”问题
go test -v -race ./...