mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-15 02:17:16 +00:00
Fix event order problem
This commit is contained in:
parent
e6d2777520
commit
1210a30c31
@ -55,12 +55,14 @@ class InotifyContext:
|
||||
def join(self, path):
|
||||
return join(self.workdir, path)
|
||||
|
||||
def check_event(self, event_type, path):
|
||||
self.missing_events += 1
|
||||
def check_event(self, event_type, paths):
|
||||
if isinstance(paths, str):
|
||||
paths = [paths]
|
||||
self.missing_events += len(paths)
|
||||
for _ in range(len(paths)):
|
||||
event = self.event_to_queue[event_type].get(timeout=0.1)
|
||||
assert isinstance(event, event_type)
|
||||
assert event.src_path == path
|
||||
return event
|
||||
assert event.src_path in paths
|
||||
|
||||
def check_empty(self, event_type):
|
||||
with pytest.raises(Empty):
|
||||
@ -128,10 +130,15 @@ def test_modify(context):
|
||||
context.check_event(InotifyDirModifiedEvent, context.subdir)
|
||||
assert context.check_any()
|
||||
|
||||
def test_move(context):
|
||||
def test_file_move(context):
|
||||
rename(context.subfile, context.subfile + '_new')
|
||||
context.check_event(InotifyFileMovedEvent, context.subfile)
|
||||
assert context.check_any()
|
||||
|
||||
def test_folder_move(context):
|
||||
remove(context.subfile)
|
||||
rename(context.subdir, context.subdir + '_new')
|
||||
context.check_event(InotifyDirMovedEvent, context.subdir)
|
||||
context.check_event(InotifyFileMovedEvent, context.subfile)
|
||||
assert context.check_any()
|
||||
|
||||
def test_delete(context):
|
||||
@ -171,9 +178,8 @@ def test_exclude(context):
|
||||
context.observer.exclude = None
|
||||
|
||||
def test_stress(context):
|
||||
newfile = []
|
||||
for i in range(1024):
|
||||
newfile.append(context.create_random_file(context.subdir, '.txt'))
|
||||
for i in range(1024):
|
||||
context.check_event(InotifyFileCreatedEvent, newfile[i])
|
||||
newfiles = []
|
||||
for _ in range(1024):
|
||||
newfiles.append(context.create_random_file(context.subdir, '.txt'))
|
||||
context.check_event(InotifyFileCreatedEvent, newfiles)
|
||||
assert context.check_any()
|
||||
|
Loading…
Reference in New Issue
Block a user