[clang-tools-extra] c746781 - [clangd] Fix data race in BackgroundIndex test

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Sat May 9 09:19:22 PDT 2020


Author: Kadir Cetinkaya
Date: 2020-05-09T18:15:27+02:00
New Revision: c746781f5085a965cfc64bd8ddf904217b797ab8

URL: https://github.com/llvm/llvm-project/commit/c746781f5085a965cfc64bd8ddf904217b797ab8
DIFF: https://github.com/llvm/llvm-project/commit/c746781f5085a965cfc64bd8ddf904217b797ab8.diff

LOG: [clangd] Fix data race in BackgroundIndex test

MockFSProvider is not thread-safe. Make sure we don't modify it while
background index is working.

Added: 
    

Modified: 
    clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
index 934f1abb1a7c..b870a8ed5a83 100644
--- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -443,6 +443,7 @@ TEST_F(BackgroundIndexTest, NoDotsInAbsPath) {
   OverlayCDB CDB(/*Base=*/nullptr);
   BackgroundIndex Idx(Context::empty(), FS, CDB,
                       [&](llvm::StringRef) { return &MSS; });
+  ASSERT_TRUE(Idx.blockUntilIdleForTest());
 
   tooling::CompileCommand Cmd;
   FS.Files[testPath("root/A.cc")] = "";
@@ -450,14 +451,15 @@ TEST_F(BackgroundIndexTest, NoDotsInAbsPath) {
   Cmd.Directory = testPath("root/build");
   Cmd.CommandLine = {"clang++", "../A.cc"};
   CDB.setCompileCommand(testPath("root/build/../A.cc"), Cmd);
+  ASSERT_TRUE(Idx.blockUntilIdleForTest());
 
   FS.Files[testPath("root/B.cc")] = "";
   Cmd.Filename = "./B.cc";
   Cmd.Directory = testPath("root");
   Cmd.CommandLine = {"clang++", "./B.cc"};
   CDB.setCompileCommand(testPath("root/./B.cc"), Cmd);
-
   ASSERT_TRUE(Idx.blockUntilIdleForTest());
+
   for (llvm::StringRef AbsPath : MSS.AccessedPaths.keys()) {
     EXPECT_FALSE(AbsPath.contains("./")) << AbsPath;
     EXPECT_FALSE(AbsPath.contains("../")) << AbsPath;


        


More information about the cfe-commits mailing list