summaryrefslogtreecommitdiff
path: root/test/buildtool/build_engine/target_map/result_map.test.cpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-03-07 15:44:28 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-03-11 15:59:05 +0100
commit5f6ff55e97104e46c1b5c2c94b39ea0fca35ca7c (patch)
tree9a8a70d311f2c55c20f426258455f9fb3037328a /test/buildtool/build_engine/target_map/result_map.test.cpp
parentb885deebf9fc02b9f1e849d91de93fadcfb71a73 (diff)
downloadjustbuild-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/result_map.test.cpp')
-rw-r--r--test/buildtool/build_engine/target_map/result_map.test.cpp45
1 files changed, 28 insertions, 17 deletions
diff --git a/test/buildtool/build_engine/target_map/result_map.test.cpp b/test/buildtool/build_engine/target_map/result_map.test.cpp
index bf246651..7f23942b 100644
--- a/test/buildtool/build_engine/target_map/result_map.test.cpp
+++ b/test/buildtool/build_engine/target_map/result_map.test.cpp
@@ -20,7 +20,9 @@
#include "catch2/catch_test_macros.hpp"
#include "src/buildtool/build_engine/target_map/result_map.hpp"
+#include "src/buildtool/common/statistics.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
+#include "src/buildtool/progress_reporting/progress.hpp"
namespace {
@@ -53,14 +55,17 @@ namespace {
TEST_CASE("empty map", "[result_map]") {
using BuildMaps::Target::ResultTargetMap;
ResultTargetMap map{0};
+ Statistics stats{};
+ Progress progress{};
- CHECK(map.ToResult().actions.empty());
- CHECK(map.ToResult().blobs.empty());
+ CHECK(map.ToResult(&stats, &progress).actions.empty());
+ CHECK(map.ToResult(&stats, &progress).blobs.empty());
- CHECK(map.ToJson() == R"({"actions": {}, "blobs": [], "trees": {}})"_json);
+ CHECK(map.ToJson(&stats, &progress) ==
+ R"({"actions": {}, "blobs": [], "trees": {}})"_json);
auto filename = (GetTestDir() / "test_empty.graph").string();
- map.ToFile(filename);
+ map.ToFile(filename, &stats, &progress);
std::ifstream file(filename);
nlohmann::json from_file{};
file >> from_file;
@@ -97,19 +102,22 @@ TEST_CASE("origins creation", "[result_map]") {
CreateAnalysedTarget(
{}, std::vector<ActionDescription::Ptr>{baz}, {})));
- auto result = map.ToResult();
+ Statistics stats{};
+ Progress progress{};
+ auto result = map.ToResult(&stats, &progress);
REQUIRE(result.actions.size() == 3);
CHECK(result.blobs.empty());
auto expect_foo = foo->ToJson();
auto expect_bar = bar->ToJson();
auto expect_baz = baz->ToJson();
- CHECK(map.ToJson() == nlohmann::json{{"actions",
- {{foo->Id(), expect_foo},
- {bar->Id(), expect_bar},
- {baz->Id(), expect_baz}}},
- {"blobs", nlohmann::json::array()},
- {"trees", nlohmann::json::object()}});
+ CHECK(map.ToJson(&stats, &progress) ==
+ nlohmann::json{{"actions",
+ {{foo->Id(), expect_foo},
+ {bar->Id(), expect_bar},
+ {baz->Id(), expect_baz}}},
+ {"blobs", nlohmann::json::array()},
+ {"trees", nlohmann::json::object()}});
expect_foo["origins"] =
R"([{"target": ["@", "", "", "foobar"], "config": {}, "subtask":
@@ -122,7 +130,7 @@ TEST_CASE("origins creation", "[result_map]") {
0}])"_json;
auto filename = (GetTestDir() / "test_with_origins.graph").string();
- map.ToFile(filename);
+ map.ToFile(filename, &stats, &progress);
std::ifstream file(filename);
nlohmann::json from_file{};
file >> from_file;
@@ -146,16 +154,19 @@ TEST_CASE("blobs uniqueness", "[result_map]") {
{},
CreateAnalysedTarget({}, {}, {"bar", "baz"})));
- auto result = map.ToResult();
+ Statistics stats{};
+ Progress progress{};
+ auto result = map.ToResult(&stats, &progress);
CHECK(result.actions.empty());
CHECK(result.blobs.size() == 3);
- CHECK(map.ToJson() == nlohmann::json{{"actions", nlohmann::json::object()},
- {"blobs", {"bar", "baz", "foo"}},
- {"trees", nlohmann::json::object()}});
+ CHECK(map.ToJson(&stats, &progress) ==
+ nlohmann::json{{"actions", nlohmann::json::object()},
+ {"blobs", {"bar", "baz", "foo"}},
+ {"trees", nlohmann::json::object()}});
auto filename = (GetTestDir() / "test_unique_blobs.graph").string();
- map.ToFile</*kIncludeOrigins=*/false>(filename);
+ map.ToFile</*kIncludeOrigins=*/false>(filename, &stats, &progress);
std::ifstream file(filename);
nlohmann::json from_file{};
file >> from_file;