summaryrefslogtreecommitdiffstats
path: root/clang/unittests/DirectoryWatcher
diff options
context:
space:
mode:
authorJan Korous <jkorous@apple.com>2019-07-15 22:11:51 +0000
committerJan Korous <jkorous@apple.com>2019-07-15 22:11:51 +0000
commitc5e7a3d710097efbe86e73c6422d76744288b105 (patch)
tree2254b8c1a11f248e90aa482de77b1e101ca0f3ad /clang/unittests/DirectoryWatcher
parent5076038bb00dd5643cb4c0a881629126b359c828 (diff)
downloadbcm5719-llvm-c5e7a3d710097efbe86e73c6422d76744288b105.tar.gz
bcm5719-llvm-c5e7a3d710097efbe86e73c6422d76744288b105.zip
[DirectoryWatcher][test] Relax test assumptions
Workaround for FSEvents sometimes sending notifications for events that happened before DirectoryWatcher was created. This caused tests to be flaky on green dragon. llvm-svn: 366138
Diffstat (limited to 'clang/unittests/DirectoryWatcher')
-rw-r--r--clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp64
1 files changed, 20 insertions, 44 deletions
diff --git a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
index 9b0e1077abc..a6b48e56236 100644
--- a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -264,7 +264,14 @@ TEST(DirectoryWatcherTest, InitialScanSync) {
{{EventKind::Modified, "a"},
{EventKind::Modified, "b"},
{EventKind::Modified, "c"}},
- {}};
+ {},
+ // We have to ignore these as it's a race between the test process
+ // which is scanning the directory and kernel which is sending
+ // notification.
+ {{EventKind::Modified, "a"},
+ {EventKind::Modified, "b"},
+ {EventKind::Modified, "c"}}
+ };
auto DW = DirectoryWatcher::create(
fixture.TestWatchedDir,
@@ -288,7 +295,14 @@ TEST(DirectoryWatcherTest, InitialScanAsync) {
{{EventKind::Modified, "a"},
{EventKind::Modified, "b"},
{EventKind::Modified, "c"}},
- {}};
+ {},
+ // We have to ignore these as it's a race between the test process
+ // which is scanning the directory and kernel which is sending
+ // notification.
+ {{EventKind::Modified, "a"},
+ {EventKind::Modified, "b"},
+ {EventKind::Modified, "c"}}
+ };
auto DW = DirectoryWatcher::create(
fixture.TestWatchedDir,
@@ -332,6 +346,7 @@ TEST(DirectoryWatcherTest, ModifyFile) {
VerifyingConsumer TestConsumer{
{{EventKind::Modified, "a"}},
+ {{EventKind::Modified, "a"}},
{{EventKind::Modified, "a"}}};
auto DW = DirectoryWatcher::create(
@@ -361,7 +376,8 @@ TEST(DirectoryWatcherTest, DeleteFile) {
VerifyingConsumer TestConsumer{
{{EventKind::Modified, "a"}},
- {{EventKind::Removed, "a"}}};
+ {{EventKind::Removed, "a"}},
+ {{EventKind::Modified, "a"}}};
auto DW = DirectoryWatcher::create(
fixture.TestWatchedDir,
@@ -414,44 +430,4 @@ TEST(DirectoryWatcherTest, InvalidatedWatcher) {
} // DW is destructed here.
checkEventualResultWithTimeout(TestConsumer);
-}
-
-TEST(DirectoryWatcherTest, ChangeMetadata) {
- DirectoryWatcherTestFixture fixture;
- fixture.addFile("a");
-
- VerifyingConsumer TestConsumer{
- {{DirectoryWatcher::Event::EventKind::Modified, "a"}},
- // We don't expect any notification for file having access file changed.
- {},
- // Given the timing we are ok with receiving the duplicate event.
- {{DirectoryWatcher::Event::EventKind::Modified, "a"}}};
-
- auto DW = DirectoryWatcher::create(
- fixture.TestWatchedDir,
- [&TestConsumer](llvm::ArrayRef<DirectoryWatcher::Event> Events,
- bool IsInitial) {
- TestConsumer.consume(Events, IsInitial);
- },
- /*waitForInitialSync=*/true);
-
- { // Change access and modification time of file a.
- Expected<file_t> HopefullyTheFD = llvm::sys::fs::openNativeFileForWrite(
- fixture.getPathInWatched("a"), CD_OpenExisting, OF_None);
- if (!HopefullyTheFD) {
- llvm::outs() << HopefullyTheFD.takeError();
- }
-
- const int FD = HopefullyTheFD.get();
- const TimePoint<> NewTimePt =
- std::chrono::system_clock::now() - std::chrono::minutes(1);
-#ifndef NDEBUG
- std::error_code setTimeRes =
-#endif
- llvm::sys::fs::setLastAccessAndModificationTime(FD, NewTimePt,
- NewTimePt);
- assert(!setTimeRes);
- }
-
- checkEventualResultWithTimeout(TestConsumer);
-}
+} \ No newline at end of file
OpenPOWER on IntegriCloud