]> granicus.if.org Git - clang/commitdiff
[DirectoryWatcher][test] Relax test assumptions
authorJan Korous <jkorous@apple.com>
Mon, 15 Jul 2019 22:11:51 +0000 (22:11 +0000)
committerJan Korous <jkorous@apple.com>
Mon, 15 Jul 2019 22:11:51 +0000 (22:11 +0000)
Workaround for FSEvents sometimes sending notifications for events that happened
before DirectoryWatcher was created.

This caused tests to be flaky on green dragon.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366138 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

index 9b0e1077abce06442016561c8820f44f6a14a0a5..a6b48e5623675693cf6f0dc396ea6b2077fb0bd1 100644 (file)
@@ -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,
@@ -331,6 +345,7 @@ TEST(DirectoryWatcherTest, ModifyFile) {
   fixture.addFile("a");
 
   VerifyingConsumer TestConsumer{
+      {{EventKind::Modified, "a"}},
       {{EventKind::Modified, "a"}},
       {{EventKind::Modified, "a"}}};
 
@@ -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