[bank-account] How to trigger data races

I saw a solution for the bank-account exercise in the mentoring queue that did’t use any locks but passed the tests.
I downloaded it and tried to get the tests to fail by tuning the switch interval or the number of threads in bank_account_test.py but the tests did pass every time.

Does anybody here have an idea how to provoke a data race in this exercise?

The trick is to run it on a test runner with just the right amount of load! This is a known issue which has not been tackled yet :slight_smile:

I wonder if you can use some sort of mock.patching to force a time.sleep() when the balance is checked. Though that would add a requirement that, say, a BankAccount.balance attribute is used.

A combination of thread count and sleep is currently being used in the flakey test. TBH, we’ve got a PR out to omit the test going forward. Open to some problem solving for how we get this exercise and test suite to work in a reliable way that’s “pythonic”. Or maybe something that encourages using Python’s C API or some other strategy that makes sense for Python’s concurrency model. Right now, things feel very very contrived.