Opened 2 years ago
Last modified 2 years ago
#8295 enhancement new
Provide a fake version of IReactorThreads and a ThreadPool that runs synchronously.
| Reported by: | Tom Prince | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | core | Keywords: | |
| Cc: | Branch: | ||
| Author: |
Description
When testing code that uses threads, one often doesn't actually care if the code is run asynchronously. Particularly if SynchronousTestCase and the synchronous deferred helpers are being used, it is preferable if the code is not run asynchronously.
Attachments (1)
Change History (4)
comment:1 Changed 2 years ago by
comment:2 Changed 2 years ago by
twisted._threads._memory already does this, after a fashion.
ThreadPool's interface is wide and confusing; it might be worthwhile to make twisted._threads public and expose its testing support rather than retrofitting the gross old interfaces even more.
Changed 2 years ago by
| Attachment: | NonThreadThings.py added |
|---|
comment:3 Changed 2 years ago by
Without meaning to disagree with Glyph's comments above in any way, I've attached some code written by ClusterHQ for testing bits of Flocker having to do with Twisted and threading. These two classes let some code that is written in a way that expects to run some code in threads all run in a single thread (as long as it is sufficiently simple). This has been helpful to test some other bis of Flocker (mostly some slightly higher-level threading helpers).
Originally licensed Apache 2, this contribution is licensed MIT to make it easier to incorporate the code into Twisted.
If it is incorporated it would be nice to update the LICENSE file. Hybrid Cluster Ltd is now ClusterHQ.

Reminder: https://glyph.twistedmatrix.com/2015/05/separate-your-fakes-and-your-inspectors.html