jarcoal / httpmock

HTTP mocking for Golang
http://godoc.org/github.com/jarcoal/httpmock
MIT License
1.93k stars 103 forks source link

m.responders needs to be locked for thread safty #26

Closed kmulvey closed 5 years ago

kmulvey commented 7 years ago

without locking the map you will get concurrent map write panics if you have more than one test running in t.Parallel() that are setting up mocks

dlebech commented 7 years ago

@kmulvey Thanks for the PR. Two questions:

  1. Have you verified that this fix completely solves the thread-safety issue? Could you perhaps add a test for this?
  2. Initializing with Activate() is also a non-threadsafe (and global) operation so using Activate and Deactivate for setup/teardown of each testcase will still cause issues for parallel tests as far as I can tell. How are you getting around this problem?

In short, this library is not really designed to be used with parallel testing, but if this PR can help with a specific use case, it probably does not hurt to merge it. Let me know what you think.

maxatome commented 5 years ago

Locking has been introduced in March 2017