From 476a3f1797bb244a2922157eade6b6f981493328 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sat, 6 Jan 2018 16:30:41 -0800 Subject: [PATCH] Add a couple more import pipeline tests, introduce fixture. --- src/import_pipeline.cc | 80 ++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index d31014d6..6cde86e1 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -587,35 +587,79 @@ bool QueryDb_ImportMain(Config* config, } TEST_SUITE("ImportPipeline") { - TEST_CASE("hello") { + struct Fixture { + Fixture() { + QueueManager::CreateInstance(&querydb_waiter, &indexer_waiter, + &stdout_waiter); + + queue = QueueManager::instance(); + cache_manager = ICacheManager::MakeFake({}); + indexer = IIndexer::MakeTestIndexer({}); + } + + bool PumpOnce() { + return IndexMain_DoParse(&config, &working_files, &file_consumer_shared, + ×tamp_manager, &import_manager, + cache_manager.get(), indexer.get()); + } + + void MakeRequest(const std::string& path, + const std::vector& args = {}, + bool is_interactive = false, + const std::string& contents = "void foo();") { + queue->index_request.Enqueue( + Index_Request(path, args, is_interactive, contents)); + } + MultiQueueWaiter querydb_waiter; MultiQueueWaiter indexer_waiter; MultiQueueWaiter stdout_waiter; - QueueManager::CreateInstance(&querydb_waiter, &indexer_waiter, - &stdout_waiter); - auto* queue = QueueManager::instance(); - - std::string path = "foo.cc"; - std::vector args = {}; - bool is_interactive = false; - std::string contents = std::string("void foo();"); - queue->index_request.Enqueue( - Index_Request(path, args, is_interactive, contents)); + QueueManager* queue = nullptr; Config config; WorkingFiles working_files; FileConsumerSharedState file_consumer_shared; TimestampManager timestamp_manager; ImportManager import_manager; + std::unique_ptr cache_manager; + std::unique_ptr indexer; + }; - std::unique_ptr cache_manager = ICacheManager::MakeFake({}); - auto indexer = IIndexer::MakeTestIndexer({{"foo.cc", 1}}); + TEST_CASE_FIXTURE(Fixture, "index request with zero results") { + indexer = IIndexer::MakeTestIndexer({{"foo.cc", 0}}); - IndexMain_DoParse(&config, &working_files, &file_consumer_shared, - ×tamp_manager, &import_manager, cache_manager.get(), - indexer.get()); + MakeRequest("foo.cc"); + REQUIRE(queue->index_request.Size() == 1); + REQUIRE(queue->do_id_map.Size() == 0); + PumpOnce(); REQUIRE(queue->index_request.Size() == 0); - REQUIRE(queue->do_id_map.Size() == 1); + REQUIRE(queue->do_id_map.Size() == 0); } -} + + TEST_CASE_FIXTURE(Fixture, "one index request") { + indexer = IIndexer::MakeTestIndexer({{"foo.cc", 100}}); + + MakeRequest("foo.cc"); + + REQUIRE(queue->index_request.Size() == 1); + REQUIRE(queue->do_id_map.Size() == 0); + PumpOnce(); + REQUIRE(queue->index_request.Size() == 0); + REQUIRE(queue->do_id_map.Size() == 100); + } + + TEST_CASE_FIXTURE(Fixture, "multiple index requests") { + indexer = IIndexer::MakeTestIndexer({{"foo.cc", 100}, {"bar.cc", 5}}); + + MakeRequest("foo.cc"); + MakeRequest("bar.cc"); + + REQUIRE(queue->index_request.Size() == 2); + REQUIRE(queue->do_id_map.Size() == 0); + while (PumpOnce()) { + } + REQUIRE(queue->index_request.Size() == 0); + REQUIRE(queue->do_id_map.Size() == 105); + } +} \ No newline at end of file