LibCore: Make the FileWatcher test resilient against outside events

The test currently watches /tmp, which the OS can create/modify files
under at any time outside of our control. So just ignore events that we
aren't interested in.

Also test removing an item from the FileWatcher.
This commit is contained in:
Timothy Flynn 2023-01-18 14:01:37 -05:00 committed by Linus Groh
parent 0e7a48bd7d
commit 8438c509e9
Notes: sideshowbarker 2024-07-17 06:28:38 +09:00

View File

@ -26,12 +26,16 @@ TEST_CASE(file_watcher_child_events)
int event_count = 0;
file_watcher->on_change = [&](Core::FileWatcherEvent const& event) {
// Ignore path events under /tmp that can occur for anything else the OS is
// doing to create/delete files there.
if (event.event_path != "/tmp/testfile"sv)
return;
if (event_count == 0) {
EXPECT_EQ(event.event_path, "/tmp/testfile");
EXPECT(has_flag(event.type, Core::FileWatcherEvent::Type::ChildCreated));
} else if (event_count == 1) {
EXPECT_EQ(event.event_path, "/tmp/testfile");
EXPECT(has_flag(event.type, Core::FileWatcherEvent::Type::ChildDeleted));
EXPECT(MUST(file_watcher->remove_watch("/tmp/"sv)));
event_loop.quit(0);
}