From cebf0135b1160f1fe88ce94033cc173f7e747bf4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 16 Oct 2020 12:28:48 +0530 Subject: [PATCH] Make test more robust by waiting for watcher thread to start --- src/calibre/test_build.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index 6d80cd53d9..df49f1ad59 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -226,11 +226,13 @@ class BuildTest(unittest.TestCase): dh = winutil.create_file( dpath, winutil.FILE_LIST_DIRECTORY, winutil.FILE_SHARE_READ, winutil.OPEN_EXISTING, winutil.FILE_FLAG_BACKUP_SEMANTICS, ) - from threading import Thread + from threading import Thread, Event + started = Event() events = [] def read_changes(): buffer = b'0' * 8192 + started.set() events.extend(winutil.read_directory_changes( dh, buffer, True, winutil.FILE_NOTIFY_CHANGE_FILE_NAME | @@ -242,6 +244,8 @@ class BuildTest(unittest.TestCase): )) t = Thread(target=read_changes, daemon=True) t.start() + started.wait(1) + t.join(0.1) testp = os.path.join(dpath, 'test') open(testp, 'w').close() t.join(4)