DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.05k stars 406 forks source link

parallel testing #206

Closed marcelloh closed 4 years ago

marcelloh commented 4 years ago

It's raining expectation errors, so my question is: Is the mocking capable of handling concurrent (parallel) tests?

l3pp4rd commented 4 years ago

Hi, if you use the same db connection in separate go routines. Set the unordered matching option. You may also create separate db instances for each parallel coroutine if that is possible

marcelloh commented 4 years ago

I think, the New option gives me a new connection from the pool each time. (when I printed dsn, I saw that)

I think you mean to set this: mock.MatchExpectationsInOrder(false)

which I've tried, without success

l3pp4rd commented 4 years ago

It should be fine, maybe you are doing something wrong, if it invokes same query x times you have to expect it x times

marcelloh commented 4 years ago

I fixed it by changing the order of the commands :-)