diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-03-07 15:44:28 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-03-11 15:59:05 +0100 |
commit | 5f6ff55e97104e46c1b5c2c94b39ea0fca35ca7c (patch) | |
tree | 9a8a70d311f2c55c20f426258455f9fb3037328a /test/buildtool/build_engine/target_map/target_map.test.cpp | |
parent | b885deebf9fc02b9f1e849d91de93fadcfb71a73 (diff) | |
download | justbuild-5f6ff55e97104e46c1b5c2c94b39ea0fca35ca7c.tar.gz |
just: Replace singletons for progress tracking and statistics...
...with regular instances that have controlled life-times.
This avoids race conditions in tracking and reporting the results
of analysis and build, as the serve endpoint can orchestrate
multiple builds at the same time asynchronously. As a bonus
side-effect this also ensures the correctness of the progress
reporting per orchestrated build.
Diffstat (limited to 'test/buildtool/build_engine/target_map/target_map.test.cpp')
-rw-r--r-- | test/buildtool/build_engine/target_map/target_map.test.cpp | 69 |
1 files changed, 44 insertions, 25 deletions
diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp index dd7c19a9..5918dac9 100644 --- a/test/buildtool/build_engine/target_map/target_map.test.cpp +++ b/test/buildtool/build_engine/target_map/target_map.test.cpp @@ -23,8 +23,10 @@ #include "src/buildtool/build_engine/base_maps/targets_file_map.hpp" #include "src/buildtool/build_engine/expression/expression.hpp" #include "src/buildtool/build_engine/target_map/target_map.hpp" +#include "src/buildtool/common/statistics.hpp" #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/progress_reporting/progress.hpp" #include "src/buildtool/storage/storage.hpp" #include "test/utils/hermeticity/local.hpp" @@ -82,8 +84,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "simple targets", "[target_map]") { auto rule_map = BuildMaps::Base::CreateRuleMap(&rule_file_map, &expr_map, &repo_config); BuildMaps::Target::ResultTargetMap result_map{0}; - auto absent_target_map = - BuildMaps::Target::CreateAbsentTargetMap(&result_map, &repo_config, 0); + Statistics stats{}; + auto absent_target_map = BuildMaps::Target::CreateAbsentTargetMap( + &result_map, &repo_config, &stats, 0); auto target_map = BuildMaps::Target::CreateTargetMap(&source, &targets_file_map, @@ -92,7 +95,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "simple targets", "[target_map]") { &absent_target_map, &result_map, &repo_config, - Storage::Instance().TargetCache()); + Storage::Instance().TargetCache(), + &stats); AnalysedTargetPtr result; bool error{false}; @@ -431,8 +435,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, auto rule_map = BuildMaps::Base::CreateRuleMap(&rule_file_map, &expr_map, &repo_config); BuildMaps::Target::ResultTargetMap result_map{0}; - auto absent_target_map = - BuildMaps::Target::CreateAbsentTargetMap(&result_map, &repo_config, 0); + Statistics stats{}; + auto absent_target_map = BuildMaps::Target::CreateAbsentTargetMap( + &result_map, &repo_config, &stats, 0); auto target_map = BuildMaps::Target::CreateTargetMap(&source, &targets_file_map, @@ -441,7 +446,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, &absent_target_map, &result_map, &repo_config, - Storage::Instance().TargetCache()); + Storage::Instance().TargetCache(), + &stats); std::vector<AnalysedTargetPtr> result; bool error{false}; @@ -480,7 +486,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, CHECK(error_msg == "NONE"); CHECK(result[0]->Artifacts() == result[1]->Artifacts()); CHECK(result[0]->Artifacts() != result[2]->Artifacts()); - auto analysis_result = result_map.ToResult(); + Progress progress{}; + auto analysis_result = result_map.ToResult(&stats, &progress); CHECK(analysis_result.actions.size() == 2); } @@ -502,8 +509,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, auto rule_map = BuildMaps::Base::CreateRuleMap(&rule_file_map, &expr_map, &repo_config); BuildMaps::Target::ResultTargetMap result_map{0}; - auto absent_target_map = - BuildMaps::Target::CreateAbsentTargetMap(&result_map, &repo_config, 0); + Statistics stats{}; + auto absent_target_map = BuildMaps::Target::CreateAbsentTargetMap( + &result_map, &repo_config, &stats, 0); auto target_map = BuildMaps::Target::CreateTargetMap(&source, &targets_file_map, @@ -512,7 +520,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, &absent_target_map, &result_map, &repo_config, - Storage::Instance().TargetCache()); + Storage::Instance().TargetCache(), + &stats); AnalysedTargetPtr result; bool error{false}; @@ -584,8 +593,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "built-in rules", "[target_map]") { auto rule_map = BuildMaps::Base::CreateRuleMap(&rule_file_map, &expr_map, &repo_config); BuildMaps::Target::ResultTargetMap result_map{0}; - auto absent_target_map = - BuildMaps::Target::CreateAbsentTargetMap(&result_map, &repo_config, 0); + Statistics stats{}; + auto absent_target_map = BuildMaps::Target::CreateAbsentTargetMap( + &result_map, &repo_config, &stats, 0); auto target_map = BuildMaps::Target::CreateTargetMap(&source, &targets_file_map, @@ -594,7 +604,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "built-in rules", "[target_map]") { &absent_target_map, &result_map, &repo_config, - Storage::Instance().TargetCache()); + Storage::Instance().TargetCache(), + &stats); AnalysedTargetPtr result; bool error{false}; std::string error_msg; @@ -776,8 +787,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "target reference", "[target_map]") { auto rule_map = BuildMaps::Base::CreateRuleMap(&rule_file_map, &expr_map, &repo_config); BuildMaps::Target::ResultTargetMap result_map{0}; - auto absent_target_map = - BuildMaps::Target::CreateAbsentTargetMap(&result_map, &repo_config, 0); + Statistics stats{}; + auto absent_target_map = BuildMaps::Target::CreateAbsentTargetMap( + &result_map, &repo_config, &stats, 0); auto target_map = BuildMaps::Target::CreateTargetMap(&source, &targets_file_map, @@ -786,7 +798,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "target reference", "[target_map]") { &absent_target_map, &result_map, &repo_config, - Storage::Instance().TargetCache()); + Storage::Instance().TargetCache(), + &stats); AnalysedTargetPtr result; bool error{false}; @@ -901,8 +914,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "trees", "[target_map]") { auto rule_map = BuildMaps::Base::CreateRuleMap(&rule_file_map, &expr_map, &repo_config); BuildMaps::Target::ResultTargetMap result_map{0}; - auto absent_target_map = - BuildMaps::Target::CreateAbsentTargetMap(&result_map, &repo_config, 0); + Statistics stats{}; + auto absent_target_map = BuildMaps::Target::CreateAbsentTargetMap( + &result_map, &repo_config, &stats, 0); auto target_map = BuildMaps::Target::CreateTargetMap(&source, &targets_file_map, @@ -911,7 +925,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "trees", "[target_map]") { &absent_target_map, &result_map, &repo_config, - Storage::Instance().TargetCache()); + Storage::Instance().TargetCache(), + &stats); AnalysedTargetPtr result; bool error{false}; @@ -992,8 +1007,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, auto rule_map = BuildMaps::Base::CreateRuleMap(&rule_file_map, &expr_map, &repo_config); BuildMaps::Target::ResultTargetMap result_map{0}; - auto absent_target_map = - BuildMaps::Target::CreateAbsentTargetMap(&result_map, &repo_config, 0); + Statistics stats{}; + auto absent_target_map = BuildMaps::Target::CreateAbsentTargetMap( + &result_map, &repo_config, &stats, 0); auto target_map = BuildMaps::Target::CreateTargetMap(&source, &targets_file_map, @@ -1002,7 +1018,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, &absent_target_map, &result_map, &repo_config, - Storage::Instance().TargetCache()); + Storage::Instance().TargetCache(), + &stats); AnalysedTargetPtr result; bool error{false}; @@ -1140,8 +1157,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "wrong arguments", "[target_map]") { auto rule_map = BuildMaps::Base::CreateRuleMap(&rule_file_map, &expr_map, &repo_config); BuildMaps::Target::ResultTargetMap result_map{0}; - auto absent_target_map = - BuildMaps::Target::CreateAbsentTargetMap(&result_map, &repo_config, 0); + Statistics stats{}; + auto absent_target_map = BuildMaps::Target::CreateAbsentTargetMap( + &result_map, &repo_config, &stats, 0); auto target_map = BuildMaps::Target::CreateTargetMap(&source, &targets_file_map, @@ -1150,7 +1168,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "wrong arguments", "[target_map]") { &absent_target_map, &result_map, &repo_config, - Storage::Instance().TargetCache()); + Storage::Instance().TargetCache(), + &stats); AnalysedTargetPtr result; bool error{false}; |