O'Reilly logo

Python Unlocked by Arun Tigeraniya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing threaded applications

Key 4: Make threaded application tests like nonthreaded ones.

My experience with testing on threaded application is to perform the following actions:

  • Try to make the threaded application as nonthreaded as possible for tests. By this, I mean that group logic that is nonthreaded in one code segment. Do not try to test business logic with thread logic. Try to keep them separate.
  • Work with as little global state as possible. Functions should pass around objects that are needed to work.
  • Try to make queues of tasks to synchronize them. Instead of creating producer consumer chains yourself, first try to use queues.
  • Also note that sleep statements make test cases run slower. If you add up sleeps in the code for more than 20 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required