mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-20 15:40:57 +00:00
Validate no files are consumed by import pipeline
This commit is contained in:
parent
299e687d37
commit
8a7dfb017f
@ -14,14 +14,14 @@ bool operator==(const CXFileUniqueID& a, const CXFileUniqueID& b) {
|
||||
|
||||
bool FileConsumerSharedState::Mark(const std::string& file) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
return files.insert(file).second;
|
||||
return used_files.insert(file).second;
|
||||
}
|
||||
|
||||
void FileConsumerSharedState::Reset(const std::string& file) {
|
||||
std::lock_guard<std::mutex> 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,
|
||||
|
@ -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<std::string> files;
|
||||
mutable std::unordered_set<std::string> used_files;
|
||||
mutable std::mutex mutex;
|
||||
|
||||
// Mark the file as used. Returns true if the file was not previously used.
|
||||
|
@ -625,6 +625,13 @@ TEST_SUITE("ImportPipeline") {
|
||||
std::unique_ptr<IIndexer> 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());
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,11 @@ std::string StringJoin(const TValues& values) {
|
||||
return StringJoinMap(values, [](const std::string& entry) { return entry; });
|
||||
}
|
||||
|
||||
template <typename TCollection, typename TValue>
|
||||
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<std::string> GetFilesInFolder(std::string folder,
|
||||
bool recursive,
|
||||
|
Loading…
Reference in New Issue
Block a user