Skip to content

Commit e731c34

Browse files
committed
Take into account directory updates
When watching the whole test directory we'll also get some events for the directory, and those events can come with different order depending on the OS, so we can't rely on them. We check that if a directory event comes, it is a modification. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 127e542 commit e731c34

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/test_file_watcher_integration.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111

1212
from frequenz.channels import ReceiverStoppedError, select, selected_from
13-
from frequenz.channels.file_watcher import Event, EventType, FileWatcher
13+
from frequenz.channels.file_watcher import EventType, FileWatcher
1414
from frequenz.channels.timer import SkipMissedAndDrift, Timer
1515

1616

@@ -34,11 +34,18 @@ async def test_file_watcher(tmp_path: pathlib.Path) -> None:
3434
filename.write_text(f"{selected.message}")
3535
elif selected_from(selected, file_watcher):
3636
event_type = EventType.CREATE if number_of_writes == 0 else EventType.MODIFY
37-
assert selected.message == Event(type=event_type, path=filename)
38-
number_of_writes += 1
39-
# After receiving a write 3 times, unsubscribe from the writes channel
40-
if number_of_writes == expected_number_of_writes:
41-
break
37+
event = selected.message
38+
# If we receive updates for the directory itself, they should be only
39+
# modifications, we only check that because we can have ordering issues if
40+
# we try check also the order compared to events in the file.
41+
if event.path == tmp_path:
42+
assert event.type == EventType.MODIFY
43+
elif event.path == filename:
44+
assert event.type == event_type
45+
number_of_writes += 1
46+
# After receiving a write 3 times, unsubscribe from the writes channel
47+
if number_of_writes == expected_number_of_writes:
48+
break
4249

4350
assert number_of_writes == expected_number_of_writes
4451

0 commit comments

Comments
 (0)