diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-18 14:01:37 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-19 11:29:48 +0000 |
commit | 8438c509e9a5159f516fc0498998238f9de5d394 (patch) | |
tree | 0ab3f2e214c0033d6603bb25053f3950c813271e /Tests/LibCore | |
parent | 0e7a48bd7dd6b92057daf88884c9588b300a0c9d (diff) | |
download | serenity-8438c509e9a5159f516fc0498998238f9de5d394.zip |
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.
Diffstat (limited to 'Tests/LibCore')
-rw-r--r-- | Tests/LibCore/TestLibCoreFileWatcher.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Tests/LibCore/TestLibCoreFileWatcher.cpp b/Tests/LibCore/TestLibCoreFileWatcher.cpp index 2d384f1cb8..39c9163083 100644 --- a/Tests/LibCore/TestLibCoreFileWatcher.cpp +++ b/Tests/LibCore/TestLibCoreFileWatcher.cpp @@ -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); } |