Django unit testing: How to test concurrent database operations?

Actually, testing whether a concurrent technique works is nearly impossible. It's so very easy to miss one small race-condition. The only real way is to prove your code, however, that's a lot of work ;)


What are some techniques for testing concurrent database operations with Django?

Actually, Django isn't an issue here.

Your library for optimistic concurrency control must be testable on it's own as a stand-alone unit.

Outside Django; using just unittest.

You'll need to test with multi-threaded (and multi-processing) test drivers. Outside Django.

Once you're sure that works, you can then test inside Django, just to be sure the API's work.

Once you're sure all of that works, you should write a simple urllib2 test driver that executes numerous concurrent transactions against a separate Django server. We wrote a little harness that fires up a Django server, runs the tests using urllib2, and then kills the Django server.

More fundamentally, you'll need some kind of pretty formal proof that your idea works. This is far, far more important than any testing.