mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Make test more robust by waiting for watcher thread to start
This commit is contained in:
parent
6c82706281
commit
cebf0135b1
@ -226,11 +226,13 @@ class BuildTest(unittest.TestCase):
|
|||||||
dh = winutil.create_file(
|
dh = winutil.create_file(
|
||||||
dpath, winutil.FILE_LIST_DIRECTORY, winutil.FILE_SHARE_READ, winutil.OPEN_EXISTING, winutil.FILE_FLAG_BACKUP_SEMANTICS,
|
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 = []
|
events = []
|
||||||
|
|
||||||
def read_changes():
|
def read_changes():
|
||||||
buffer = b'0' * 8192
|
buffer = b'0' * 8192
|
||||||
|
started.set()
|
||||||
events.extend(winutil.read_directory_changes(
|
events.extend(winutil.read_directory_changes(
|
||||||
dh, buffer, True,
|
dh, buffer, True,
|
||||||
winutil.FILE_NOTIFY_CHANGE_FILE_NAME |
|
winutil.FILE_NOTIFY_CHANGE_FILE_NAME |
|
||||||
@ -242,6 +244,8 @@ class BuildTest(unittest.TestCase):
|
|||||||
))
|
))
|
||||||
t = Thread(target=read_changes, daemon=True)
|
t = Thread(target=read_changes, daemon=True)
|
||||||
t.start()
|
t.start()
|
||||||
|
started.wait(1)
|
||||||
|
t.join(0.1)
|
||||||
testp = os.path.join(dpath, 'test')
|
testp = os.path.join(dpath, 'test')
|
||||||
open(testp, 'w').close()
|
open(testp, 'w').close()
|
||||||
t.join(4)
|
t.join(4)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user