stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
23.22k stars 1.59k forks source link

mock - get call count/list in thread safe way #964

Open nbaztec opened 4 years ago

nbaztec commented 4 years ago

What Currently retrieving the calls via mock.Calls results in a data race condition when the test is using multiple go routines.

Expected A thread-safe way to obtain the call count/list.

Use Case A poller object uses a mocked client that is called in an infinite polling loop until a private flag is set on the poller object to exit it. Testing that upon setting the private flag, the infinite loop is no longer invoking the mocked client's method. This would be trivial to do if we'd have access to the call-count after the flag is set, and if the call count stays the same after 1 second.

earonesty commented 2 years ago

See: https://github.com/AtakamaLLC/tsmock