diff --git a/src/file_consumer.cc b/src/file_consumer.cc index d2797376..9a05b12e 100644 --- a/src/file_consumer.cc +++ b/src/file_consumer.cc @@ -14,14 +14,14 @@ bool operator==(const CXFileUniqueID& a, const CXFileUniqueID& b) { bool FileConsumerSharedState::Mark(const std::string& file) { std::lock_guard lock(mutex); - return files.insert(file).second; + return used_files.insert(file).second; } void FileConsumerSharedState::Reset(const std::string& file) { std::lock_guard lock(mutex); - auto it = files.find(file); - if (it != files.end()) - files.erase(it); + auto it = used_files.find(file); + if (it != used_files.end()) + used_files.erase(it); } FileConsumer::FileConsumer(FileConsumerSharedState* shared_state, diff --git a/src/file_consumer.h b/src/file_consumer.h index 6b2b2792..85cb7644 100644 --- a/src/file_consumer.h +++ b/src/file_consumer.h @@ -16,7 +16,7 @@ MAKE_HASHABLE(CXFileUniqueID, t.data[0], t.data[1], t.data[2]); bool operator==(const CXFileUniqueID& a, const CXFileUniqueID& b); struct FileConsumerSharedState { - mutable std::unordered_set files; + mutable std::unordered_set used_files; mutable std::mutex mutex; // Mark the file as used. Returns true if the file was not previously used. diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index 4da89cfd..0bcac0ad 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -625,6 +625,13 @@ TEST_SUITE("ImportPipeline") { std::unique_ptr indexer; }; + // FIXME: validate other state like timestamp_manager, etc. + // FIXME: add more interesting tests that are not the happy path + // FIXME: test + // - IndexMain_DoCreateIndexUpdate + // - IndexMain_LoadPreviousIndex + // - QueryDb_ImportMain + TEST_CASE_FIXTURE(Fixture, "index request with zero results") { indexer = IIndexer::MakeTestIndexer({IIndexer::TestEntry{"foo.cc", 0}}); @@ -635,6 +642,8 @@ TEST_SUITE("ImportPipeline") { PumpOnce(); REQUIRE(queue->index_request.Size() == 0); REQUIRE(queue->do_id_map.Size() == 0); + + REQUIRE(file_consumer_shared.used_files.empty()); } TEST_CASE_FIXTURE(Fixture, "one index request") { @@ -647,6 +656,8 @@ TEST_SUITE("ImportPipeline") { PumpOnce(); REQUIRE(queue->index_request.Size() == 0); REQUIRE(queue->do_id_map.Size() == 100); + + REQUIRE(file_consumer_shared.used_files.empty()); } TEST_CASE_FIXTURE(Fixture, "multiple index requests") { @@ -662,5 +673,7 @@ TEST_SUITE("ImportPipeline") { } REQUIRE(queue->index_request.Size() == 0); REQUIRE(queue->do_id_map.Size() == 105); + + REQUIRE(file_consumer_shared.used_files.empty()); } } diff --git a/src/utils.h b/src/utils.h index c4d991ce..55e51015 100644 --- a/src/utils.h +++ b/src/utils.h @@ -55,6 +55,11 @@ std::string StringJoin(const TValues& values) { return StringJoinMap(values, [](const std::string& entry) { return entry; }); } +template +bool ContainsValue(const TCollection& collection, const TValue& value) { + return collection.find(value) != collection.end(); +} + // Finds all files in the given folder. This is recursive. std::vector GetFilesInFolder(std::string folder, bool recursive,