smartdispatch
smartdispatch copied to clipboard
Improve unit test for open_with_lock
Find a cleaner way to test the open_with_lock function. Right now we rely on causing race conditions using time.sleep. The procedure is as follow:
- a file is locked in the main process, launch a new process and goes to sleep for T seconds.
- the other (newly created) process tries to lock the same file which raises a warning and gets blocked.
- after T seconds, the main process wakes up, release the lock and wait for the other process to finish.
- then, the unit test looks at the stderr of the other process and confirms that a warning have indeed been raised (read: successfully waited for the lock to be removed before resuming its execution).
EDIT: Added precision about what is done right now.