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

Running make testrace fails with race detected during execution of test #89

Closed
rasmus-unity opened this issue Jun 25, 2018 · 8 comments
Closed

Comments

@rasmus-unity
Copy link

rasmus-unity commented Jun 25, 2018

We're running our unit tests with -race option, and when trying to introduce pact consumer tests, they fail with a race condition. Reproduced on latest master from https://github.com/pact-foundation/pact-go repo. We can probably find a way to run pact tests without race detection, but curious to know if this is an issue which should be fixed.

Software versions

  • OS: Mac OSX 10.13.5
  • Consumer Pact library: From 6c1c6ad (master branch)
  • Provider Pact library: Same repo
  • Golang Version: go version go1.9.4 darwin/amd64
  • Golang environment:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/rasmuss"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/07/fstlw6z54j53s4lndk0f4vgw0000gp/T/go-build243676548=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

Expected behaviour

Running pact tests with -race should pass

Actual behaviour

Fails with

==================
WARNING: DATA RACE
Read at 0x00c420148480 by main goroutine:
  runtime.mapaccess1_fast64()
      /usr/local/opt/go/libexec/src/runtime/hashmap_fast.go:110 +0x0
  github.com/pact-foundation/pact-go/client.(*ServiceManager).Stop()
      /Users/rasmuss/src/github.com/pact-foundation/pact-go/client/service_manager.go:65 +0x16d
  github.com/pact-foundation/pact-go/client.(*MockService).Stop()
      <autogenerated>:1 +0x51
  (...)

Previous write at 0x00c420148480 by goroutine 8:
  runtime.mapassign_fast64()
      /usr/local/opt/go/libexec/src/runtime/hashmap_fast.go:598 +0x0
  github.com/pact-foundation/pact-go/client.(*ServiceManager).addServiceMonitor()
      /Users/rasmuss/src/github.com/pact-foundation/pact-go/client/service_manager.go:41 +0x165

Goroutine 8 (running) created at:
  github.com/pact-foundation/pact-go/client.(*ServiceManager).Setup()
      /Users/rasmuss/src/github.com/pact-foundation/pact-go/client/service_manager.go:30 +0x1be
  github.com/pact-foundation/pact-go/client.(*MockService).Setup()
      <autogenerated>:1 +0x43
  github.com/pact-foundation/pact-go/dsl.newClient()
      /Users/rasmuss/src/github.com/pact-foundation/pact-go/dsl/client.go:43 +0x42
  (...)

Steps to reproduce

  1. git clone [email protected]:pact-foundation/pact-go.git
  2. cd pact-go
  3. make testrace

EDIT: Alternatively

  1. git clone [email protected]:pact-foundation/pact-go.git
  2. cd pact-go/examples/consumer/goconsumer
  3. go test -race -run TestPactConsumerLoginHandler_UserExists .

Result: Found 2 data race(s)

Relevent log files

Hope above is sufficient

@mefellows
Copy link
Member

The mock server it starts is stateful, as it needs to confirm the the expected interactions for each test are actually made, so running the pact tests in parallel is not possible, unless you create multiple instances of the pact struct on different ports.

See https://github.com/pact-foundation/pact-go/blob/master/README.md#splitting-tests-across-multiple-files for some insight into how you might be able to achieve it

@mefellows mefellows reopened this Jun 25, 2018
@mefellows
Copy link
Member

mefellows commented Jun 25, 2018

Sorry, didn't mean to hit close. Will look into it and add some documentation for others

@rasmus-unity
Copy link
Author

rasmus-unity commented Jun 25, 2018

so running the pact tests in parallel is not possible

Probably a basic question, but even if I just run a single pact test, it still fails with race condition. Or do you mean something different?

@rasmus-unity
Copy link
Author

Updated description above to include repro steps for issue when running single consumer pact test from pact-go/examples/consumer/goconsumer. Hope I understood correctly, that this should be possible?

@mefellows
Copy link
Member

That's fantastic, thanks! It should be possible to run the test, so looks like a bug we can hunt down.

@mefellows
Copy link
Member

Fix is now in master, but not in a tagged release. If you'd like to give this a go in your project @rasmus-unity that'd be great.

@rasmus-unity
Copy link
Author

@mefellows, verified it works on our test suite also. thanks for the quick fix to this!

@mefellows
Copy link
Member

Your welcome, thanks!

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

No branches or pull requests

2 participants