From c746781f5085a965cfc64bd8ddf904217b797ab8 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Sat, 9 May 2020 18:14:48 +0200 Subject: [PATCH] [clangd] Fix data race in BackgroundIndex test MockFSProvider is not thread-safe. Make sure we don't modify it while background index is working. --- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp index 934f1ab..b870a8e 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; -- 2.7.4