diff --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp index 0c9455f..22638ee 100644 --- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp +++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp @@ -451,123 +451,6 @@ TEST_F(TUSchedulerTests, InvalidationUnchanged) { EXPECT_EQ(1, Actions.load()) << "All actions should run"; } -TEST_F(TUSchedulerTests, ManyUpdates) { - const int FilesCount = 3; - const int UpdatesPerFile = 10; - - std::mutex Mut; - int TotalASTReads = 0; - int TotalPreambleReads = 0; - int TotalUpdates = 0; - llvm::StringMap LatestDiagVersion; - - // Run TUScheduler and collect some stats. - { - auto Opts = optsForTest(); - Opts.UpdateDebounce = DebouncePolicy::fixed(std::chrono::milliseconds(50)); - TUScheduler S(CDB, Opts, captureDiags()); - - std::vector Files; - for (int I = 0; I < FilesCount; ++I) { - std::string Name = "foo" + std::to_string(I) + ".cpp"; - Files.push_back(testPath(Name)); - this->FS.Files[Files.back()] = ""; - } - - StringRef Contents1 = R"cpp(int a;)cpp"; - StringRef Contents2 = R"cpp(int main() { return 1; })cpp"; - StringRef Contents3 = R"cpp(int a; int b; int sum() { return a + b; })cpp"; - - StringRef AllContents[] = {Contents1, Contents2, Contents3}; - const int AllContentsSize = 3; - - // Scheduler may run tasks asynchronously, but should propagate the - // context. We stash a nonce in the context, and verify it in the task. - static Key NonceKey; - int Nonce = 0; - - for (int FileI = 0; FileI < FilesCount; ++FileI) { - for (int UpdateI = 0; UpdateI < UpdatesPerFile; ++UpdateI) { - auto Contents = AllContents[(FileI + UpdateI) % AllContentsSize]; - - auto File = Files[FileI]; - auto Inputs = getInputs(File, Contents.str()); - { - WithContextValue WithNonce(NonceKey, ++Nonce); - Inputs.Version = std::to_string(UpdateI); - updateWithDiags( - S, File, Inputs, WantDiagnostics::Auto, - [File, Nonce, Version(Inputs.Version), &Mut, &TotalUpdates, - &LatestDiagVersion](std::vector) { - EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce)); - EXPECT_EQ(File, boundPath()); - - std::lock_guard Lock(Mut); - ++TotalUpdates; - EXPECT_EQ(File, *TUScheduler::getFileBeingProcessedInContext()); - // Make sure Diags are for a newer version. - auto It = LatestDiagVersion.try_emplace(File, -1); - const int PrevVersion = It.first->second; - int CurVersion; - ASSERT_TRUE(llvm::to_integer(Version, CurVersion, 10)); - EXPECT_LT(PrevVersion, CurVersion); - It.first->getValue() = CurVersion; - }); - } - { - WithContextValue WithNonce(NonceKey, ++Nonce); - S.runWithAST( - "CheckAST", File, - [File, Inputs, Nonce, &Mut, - &TotalASTReads](Expected AST) { - EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce)); - EXPECT_EQ(File, boundPath()); - - ASSERT_TRUE((bool)AST); - EXPECT_EQ(AST->Inputs.Contents, Inputs.Contents); - EXPECT_EQ(AST->Inputs.Version, Inputs.Version); - EXPECT_EQ(AST->AST.version(), Inputs.Version); - - std::lock_guard Lock(Mut); - ++TotalASTReads; - EXPECT_EQ(File, *TUScheduler::getFileBeingProcessedInContext()); - }); - } - - { - WithContextValue WithNonce(NonceKey, ++Nonce); - S.runWithPreamble( - "CheckPreamble", File, TUScheduler::Stale, - [File, Inputs, Nonce, &Mut, - &TotalPreambleReads](Expected Preamble) { - EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce)); - EXPECT_EQ(File, boundPath()); - - ASSERT_TRUE((bool)Preamble); - EXPECT_EQ(Preamble->Contents, Inputs.Contents); - - std::lock_guard Lock(Mut); - ++TotalPreambleReads; - EXPECT_EQ(File, *TUScheduler::getFileBeingProcessedInContext()); - }); - } - } - } - ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10))); - } // TUScheduler destructor waits for all operations to finish. - - std::lock_guard Lock(Mut); - // Updates might get coalesced in preamble thread and result in dropping - // diagnostics for intermediate snapshots. - EXPECT_GE(TotalUpdates, FilesCount); - EXPECT_LE(TotalUpdates, FilesCount * UpdatesPerFile); - // We should receive diags for last update. - for (const auto &Entry : LatestDiagVersion) - EXPECT_EQ(Entry.second, UpdatesPerFile - 1); - EXPECT_EQ(TotalASTReads, FilesCount * UpdatesPerFile); - EXPECT_EQ(TotalPreambleReads, FilesCount * UpdatesPerFile); -} - TEST_F(TUSchedulerTests, EvictedAST) { std::atomic BuiltASTCounter(0); auto Opts = optsForTest();