Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute go test -race failed #4

Closed
shensuie opened this issue Aug 10, 2023 · 2 comments · Fixed by #5
Closed

execute go test -race failed #4

shensuie opened this issue Aug 10, 2023 · 2 comments · Fixed by #5

Comments

@shensuie
Copy link

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
@daniel-hutao
Copy link
Contributor

get it.

@daniel-hutao daniel-hutao changed the title 无法通过 -race 测试 execute go test -race failed Aug 10, 2023
@daniel-hutao
Copy link
Contributor

I wrote a blog for this issue: 让 GPT-4 来修复 Golang “数据竞争”问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants