r366138 - [DirectoryWatcher][test] Relax test assumptions

Jan Korous via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 15 15:11:51 PDT 2019


Author: jkorous
Date: Mon Jul 15 15:11:51 2019
New Revision: 366138

URL: http://llvm.org/viewvc/llvm-project?rev=366138&view=rev
Log:
[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.

Modified:
    cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Modified: cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp?rev=366138&r1=366137&r2=366138&view=diff
==============================================================================
--- cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp (original)
+++ cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp Mon Jul 15 15:11:51 2019
@@ -264,7 +264,14 @@ TEST(DirectoryWatcherTest, InitialScanSy
       {{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, InitialScanAs
       {{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, InvalidatedWa
   } // 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




More information about the cfe-commits mailing list