pashagolub / pgxmock

pgx mock driver for golang to test database interactions
Other
368 stars 50 forks source link

[-] fix panic for double unlock for unexpected method calls #216

Closed StevenACoffman closed 1 month ago

StevenACoffman commented 1 month ago

This PR avoids many double mutex unlock panics for unexpected calls to methods.

When the call to method was not expected, prior to this PR, pgxmock would not send the proper message back, but would instead panic without giving any message as to what the problem was.

pashagolub commented 1 month ago

Cool! Thanks! Would you please add a test case checking the bug. Thanks

svennis94 commented 1 month ago

We have experienced similar behavior, specifically when running with MatchExpectationsInOrder set to false. We have a wait group that executes a couple of queries in parallel with go routines. So the order of queries is unknown, 70% of times the test succeed and the other 30% it gives the error fatal error: sync: unlock of unlocked mutex from the pgxmock package.

We have tested this change and this does tackle the panic, and since all expectations are met due to the MatchExpectationsInOrder there are no unmet expectations so the tests pass 100% of the time. It is however a hard testcase to write from our use case :sweat_smile:, since it doesn't fail all of the time.

+1 from us!

StevenACoffman commented 1 month ago

Thanks so much for merging! I was trying to circle back to write the tests, but mine were going to be way over complicated. :)

pashagolub commented 1 month ago

Yeah, this one https://github.com/pashagolub/pgxmock/pull/217 was tricky to catch