mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
Tests: Make TestLibCoreFileWatcher
more reliable
This test could fail when `/tmp/testfile` already exists. There also shouldn't be a need to wait so long for this test, except for on MacOS, where the `FileWatcher` implementation is apparently less reliable.
This commit is contained in:
parent
506e490793
commit
08b7e83f95
Notes:
github-actions[bot]
2024-11-25 13:31:08 +00:00
Author: https://github.com/yyny Commit: https://github.com/LadybirdBrowser/ladybird/commit/08b7e83f95f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2539
1 changed files with 19 additions and 11 deletions
|
@ -15,12 +15,21 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifdef AK_OS_MACOS
|
||||||
|
constexpr int TIMEOUT_PER_STEP_IN_MS = 500;
|
||||||
|
#else
|
||||||
|
constexpr int TIMEOUT_PER_STEP_IN_MS = 50;
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST_CASE(file_watcher_child_events)
|
TEST_CASE(file_watcher_child_events)
|
||||||
{
|
{
|
||||||
auto event_loop = Core::EventLoop();
|
auto event_loop = Core::EventLoop();
|
||||||
auto maybe_file_watcher = Core::FileWatcher::create();
|
auto maybe_file_watcher = Core::FileWatcher::create();
|
||||||
EXPECT_NE(maybe_file_watcher.is_error(), true);
|
EXPECT_NE(maybe_file_watcher.is_error(), true);
|
||||||
|
|
||||||
|
// Ensure the testfile does not already exist.
|
||||||
|
(void)Core::System::unlink("/tmp/testfile"sv);
|
||||||
|
|
||||||
auto file_watcher = maybe_file_watcher.release_value();
|
auto file_watcher = maybe_file_watcher.release_value();
|
||||||
auto watch_result = file_watcher->add_watch("/tmp/",
|
auto watch_result = file_watcher->add_watch("/tmp/",
|
||||||
Core::FileWatcherEvent::Type::ChildCreated
|
Core::FileWatcherEvent::Type::ChildCreated
|
||||||
|
@ -46,19 +55,18 @@ TEST_CASE(file_watcher_child_events)
|
||||||
event_count++;
|
event_count++;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto timer1 = Core::Timer::create_single_shot(500, [&] {
|
auto timer1 = Core::Timer::create_single_shot(1 * TIMEOUT_PER_STEP_IN_MS, [&] {
|
||||||
int rc = creat("/tmp/testfile", 0777);
|
int rc = creat("/tmp/testfile", 0777);
|
||||||
EXPECT_NE(rc, -1);
|
EXPECT_NE(rc, -1);
|
||||||
});
|
});
|
||||||
timer1->start();
|
timer1->start();
|
||||||
|
|
||||||
auto timer2 = Core::Timer::create_single_shot(1000, [&] {
|
auto timer2 = Core::Timer::create_single_shot(2 * TIMEOUT_PER_STEP_IN_MS, [&] {
|
||||||
int rc = unlink("/tmp/testfile");
|
MUST(Core::System::unlink("/tmp/testfile"sv));
|
||||||
EXPECT_NE(rc, -1);
|
|
||||||
});
|
});
|
||||||
timer2->start();
|
timer2->start();
|
||||||
|
|
||||||
auto catchall_timer = Core::Timer::create_single_shot(2000, [&] {
|
auto catchall_timer = Core::Timer::create_single_shot(3 * TIMEOUT_PER_STEP_IN_MS, [&] {
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
});
|
});
|
||||||
catchall_timer->start();
|
catchall_timer->start();
|
||||||
|
@ -94,13 +102,13 @@ TEST_CASE(contents_changed)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto timer1 = Core::Timer::create_single_shot(500, [&] { write_file("line2\n"sv); });
|
auto timer1 = Core::Timer::create_single_shot(1 * TIMEOUT_PER_STEP_IN_MS, [&] { write_file("line2\n"sv); });
|
||||||
timer1->start();
|
timer1->start();
|
||||||
|
|
||||||
auto timer2 = Core::Timer::create_single_shot(1000, [&] { write_file("line3\n"sv); });
|
auto timer2 = Core::Timer::create_single_shot(2 * TIMEOUT_PER_STEP_IN_MS, [&] { write_file("line3\n"sv); });
|
||||||
timer2->start();
|
timer2->start();
|
||||||
|
|
||||||
auto catchall_timer = Core::Timer::create_single_shot(2000, [&] {
|
auto catchall_timer = Core::Timer::create_single_shot(3 * TIMEOUT_PER_STEP_IN_MS, [&] {
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
});
|
});
|
||||||
catchall_timer->start();
|
catchall_timer->start();
|
||||||
|
@ -139,19 +147,19 @@ TEST_CASE(symbolic_link)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto timer1 = Core::Timer::create_single_shot(500, [&] {
|
auto timer1 = Core::Timer::create_single_shot(1 * TIMEOUT_PER_STEP_IN_MS, [&] {
|
||||||
MUST(Core::System::unlink(test_file.string()));
|
MUST(Core::System::unlink(test_file.string()));
|
||||||
MUST(Core::System::symlink(test_link1.string(), test_file.string()));
|
MUST(Core::System::symlink(test_link1.string(), test_file.string()));
|
||||||
});
|
});
|
||||||
timer1->start();
|
timer1->start();
|
||||||
|
|
||||||
auto timer2 = Core::Timer::create_single_shot(1000, [&] {
|
auto timer2 = Core::Timer::create_single_shot(2 * TIMEOUT_PER_STEP_IN_MS, [&] {
|
||||||
MUST(Core::System::unlink(test_file.string()));
|
MUST(Core::System::unlink(test_file.string()));
|
||||||
MUST(Core::System::symlink(test_link2.string(), test_file.string()));
|
MUST(Core::System::symlink(test_link2.string(), test_file.string()));
|
||||||
});
|
});
|
||||||
timer2->start();
|
timer2->start();
|
||||||
|
|
||||||
auto catchall_timer = Core::Timer::create_single_shot(2000, [&] {
|
auto catchall_timer = Core::Timer::create_single_shot(3 * TIMEOUT_PER_STEP_IN_MS, [&] {
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
});
|
});
|
||||||
catchall_timer->start();
|
catchall_timer->start();
|
||||||
|
|
Loading…
Reference in a new issue