[clangd] Fix data race in BackgroundIndex test

MockFSProvider is not thread-safe. Make sure we don't modify it while
background index is working.
This commit is contained in:
Kadir Cetinkaya 2020-05-09 18:14:48 +02:00
parent b05c8c5756
commit c746781f50
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
1 changed files with 3 additions and 1 deletions

View File

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