summaryrefslogtreecommitdiff
path: root/test/buildtool/graph_traverser/graph_traverser.test.hpp
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/graph_traverser/graph_traverser.test.hpp
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/graph_traverser/graph_traverser.test.hpp')
-rw-r--r--test/buildtool/graph_traverser/graph_traverser.test.hpp155
1 files changed, 102 insertions, 53 deletions
diff --git a/test/buildtool/graph_traverser/graph_traverser.test.hpp b/test/buildtool/graph_traverser/graph_traverser.test.hpp
index dda1bd2d..a35c56b8 100644
--- a/test/buildtool/graph_traverser/graph_traverser.test.hpp
+++ b/test/buildtool/graph_traverser/graph_traverser.test.hpp
@@ -26,6 +26,7 @@
#include "src/buildtool/file_system/jsonfs.hpp"
#include "src/buildtool/graph_traverser/graph_traverser.hpp"
#include "src/buildtool/logging/logger.hpp"
+#include "src/buildtool/progress_reporting/progress.hpp"
#include "src/utils/cpp/json.hpp"
#include "test/utils/test_env.hpp"
@@ -146,10 +147,14 @@ inline void SetLauncher() {
SetLauncher();
auto const clargs = p.CmdLineArgs();
+ Statistics stats{};
+ Progress progress{};
GraphTraverser const gt{clargs.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const result =
gt.BuildAndStage(clargs.graph_description, clargs.artifacts);
@@ -162,8 +167,8 @@ inline void SetLauncher() {
CHECK(contents == "Hello, World!\n");
if (is_hermetic) {
- CHECK(Statistics::Instance().ActionsQueuedCounter() == 2);
- CHECK(Statistics::Instance().ActionsCachedCounter() == 0);
+ CHECK(stats.ActionsQueuedCounter() == 2);
+ CHECK(stats.ActionsCachedCounter() == 0);
}
SECTION("Executable is retrieved as executable") {
@@ -172,7 +177,9 @@ inline void SetLauncher() {
clargs_exec.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const exec_result = gt_get_exec.BuildAndStage(
clargs_exec.graph_description, clargs_exec.artifacts);
@@ -184,9 +191,8 @@ inline void SetLauncher() {
CHECK(FileSystemManager::Type(exec_path) == ObjectType::Executable);
if (is_hermetic) {
- CHECK(Statistics::Instance().ActionsQueuedCounter() ==
- 3); // One more action queued
- CHECK(Statistics::Instance().ActionsCachedCounter() ==
+ CHECK(stats.ActionsQueuedCounter() == 3); // One more action queued
+ CHECK(stats.ActionsCachedCounter() ==
1); // But that action was cached
}
}
@@ -197,10 +203,14 @@ inline void SetLauncher() {
SetLauncher();
auto const clargs = p.CmdLineArgs();
+ Statistics stats{};
+ Progress progress{};
GraphTraverser const gt{clargs.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const result =
gt.BuildAndStage(clargs.graph_description, clargs.artifacts);
@@ -209,8 +219,8 @@ inline void SetLauncher() {
CHECK(FileSystemManager::IsFile(result->output_paths.at(0)));
if (is_hermetic) {
- CHECK(Statistics::Instance().ActionsQueuedCounter() == 0);
- CHECK(Statistics::Instance().ActionsCachedCounter() == 0);
+ CHECK(stats.ActionsQueuedCounter() == 0);
+ CHECK(stats.ActionsCachedCounter() == 0);
}
}
@@ -220,10 +230,14 @@ inline void SetLauncher() {
SetLauncher();
auto const clargs = p.CmdLineArgs();
+ Statistics stats{};
+ Progress progress{};
GraphTraverser const gt{clargs.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const result =
gt.BuildAndStage(clargs.graph_description, clargs.artifacts);
@@ -236,7 +250,9 @@ inline void SetLauncher() {
clargs_full_build.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const full_build_result = gt_full_build.BuildAndStage(
clargs_full_build.graph_description, clargs_full_build.artifacts);
@@ -245,11 +261,11 @@ inline void SetLauncher() {
CHECK(FileSystemManager::IsFile(full_build_result->output_paths.at(0)));
if (is_hermetic) {
- CHECK(Statistics::Instance().ActionsQueuedCounter() == 8);
- CHECK(Statistics::Instance().ActionsCachedCounter() == 3);
+ CHECK(stats.ActionsQueuedCounter() == 8);
+ CHECK(stats.ActionsCachedCounter() == 3);
}
else {
- CHECK(Statistics::Instance().ActionsCachedCounter() > 0);
+ CHECK(stats.ActionsCachedCounter() > 0);
}
}
@@ -260,10 +276,14 @@ inline void SetLauncher() {
SetLauncher();
auto const clargs_update_cpp =
full_hello_world.CmdLineArgs("_entry_points_upload_source");
+ Statistics stats{};
+ Progress progress{};
GraphTraverser const gt_upload{clargs_update_cpp.gtargs,
full_hello_world.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const cpp_result = gt_upload.BuildAndStage(
clargs_update_cpp.graph_description, clargs_update_cpp.artifacts);
@@ -273,8 +293,8 @@ inline void SetLauncher() {
CHECK(FileSystemManager::IsFile(cpp_result->output_paths.at(0)));
if (is_hermetic) {
- CHECK(Statistics::Instance().ActionsQueuedCounter() == 0);
- CHECK(Statistics::Instance().ActionsCachedCounter() == 0);
+ CHECK(stats.ActionsQueuedCounter() == 0);
+ CHECK(stats.ActionsCachedCounter() == 0);
}
TestProject hello_world_known_cpp("hello_world_known_source");
@@ -282,7 +302,9 @@ inline void SetLauncher() {
GraphTraverser const gt{clargs.gtargs,
full_hello_world.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const result =
gt.BuildAndStage(clargs.graph_description, clargs.artifacts);
@@ -291,11 +313,11 @@ inline void SetLauncher() {
CHECK(FileSystemManager::IsFile(result->output_paths.at(0)));
if (is_hermetic) {
- CHECK(Statistics::Instance().ActionsQueuedCounter() == 2);
- CHECK(Statistics::Instance().ActionsCachedCounter() == 0);
+ CHECK(stats.ActionsQueuedCounter() == 2);
+ CHECK(stats.ActionsCachedCounter() == 0);
}
else {
- CHECK(Statistics::Instance().ActionsQueuedCounter() >= 2);
+ CHECK(stats.ActionsQueuedCounter() >= 2);
}
}
@@ -304,10 +326,14 @@ static void TestBlobsUploadedAndUsed(bool is_hermetic = true) {
auto const clargs = p.CmdLineArgs();
SetLauncher();
+ Statistics stats{};
+ Progress progress{};
GraphTraverser gt{clargs.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const result =
gt.BuildAndStage(clargs.graph_description, clargs.artifacts);
@@ -321,11 +347,11 @@ static void TestBlobsUploadedAndUsed(bool is_hermetic = true) {
CHECK(contents == "this is a test to check if blobs are uploaded");
if (is_hermetic) {
- CHECK(Statistics::Instance().ActionsQueuedCounter() == 1);
- CHECK(Statistics::Instance().ActionsCachedCounter() == 0);
+ CHECK(stats.ActionsQueuedCounter() == 1);
+ CHECK(stats.ActionsCachedCounter() == 0);
}
else {
- CHECK(Statistics::Instance().ActionsQueuedCounter() >= 1);
+ CHECK(stats.ActionsQueuedCounter() >= 1);
}
}
@@ -334,10 +360,14 @@ static void TestEnvironmentVariablesSetAndUsed(bool is_hermetic = true) {
auto const clargs = p.CmdLineArgs();
SetLauncher();
+ Statistics stats{};
+ Progress progress{};
GraphTraverser gt{clargs.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const result =
gt.BuildAndStage(clargs.graph_description, clargs.artifacts);
@@ -351,11 +381,11 @@ static void TestEnvironmentVariablesSetAndUsed(bool is_hermetic = true) {
CHECK(contents == "content from environment variable");
if (is_hermetic) {
- CHECK(Statistics::Instance().ActionsQueuedCounter() == 1);
- CHECK(Statistics::Instance().ActionsCachedCounter() == 0);
+ CHECK(stats.ActionsQueuedCounter() == 1);
+ CHECK(stats.ActionsCachedCounter() == 0);
}
else {
- CHECK(Statistics::Instance().ActionsQueuedCounter() >= 1);
+ CHECK(stats.ActionsQueuedCounter() >= 1);
}
}
@@ -364,10 +394,14 @@ static void TestTreesUsed(bool is_hermetic = true) {
auto const clargs = p.CmdLineArgs();
SetLauncher();
+ Statistics stats{};
+ Progress progress{};
GraphTraverser gt{clargs.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const result =
gt.BuildAndStage(clargs.graph_description, clargs.artifacts);
@@ -381,11 +415,11 @@ static void TestTreesUsed(bool is_hermetic = true) {
CHECK(contents == "this is a test to check if blobs are uploaded");
if (is_hermetic) {
- CHECK(Statistics::Instance().ActionsQueuedCounter() == 2);
- CHECK(Statistics::Instance().ActionsCachedCounter() == 0);
+ CHECK(stats.ActionsQueuedCounter() == 2);
+ CHECK(stats.ActionsCachedCounter() == 0);
}
else {
- CHECK(Statistics::Instance().ActionsQueuedCounter() >= 2);
+ CHECK(stats.ActionsQueuedCounter() >= 2);
}
}
@@ -394,10 +428,14 @@ static void TestNestedTreesUsed(bool is_hermetic = true) {
auto const clargs = p.CmdLineArgs();
SetLauncher();
+ Statistics stats{};
+ Progress progress{};
GraphTraverser gt{clargs.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const result =
gt.BuildAndStage(clargs.graph_description, clargs.artifacts);
@@ -411,24 +449,29 @@ static void TestNestedTreesUsed(bool is_hermetic = true) {
CHECK(contents == "this is a test to check if blobs are uploaded");
if (is_hermetic) {
- CHECK(Statistics::Instance().ActionsQueuedCounter() == 1);
- CHECK(Statistics::Instance().ActionsCachedCounter() == 0);
+ CHECK(stats.ActionsQueuedCounter() == 1);
+ CHECK(stats.ActionsCachedCounter() == 0);
}
else {
- CHECK(Statistics::Instance().ActionsQueuedCounter() >= 1);
+ CHECK(stats.ActionsQueuedCounter() >= 1);
}
}
static void TestFlakyHelloWorldDetected(bool /*is_hermetic*/ = true) {
TestProject p("flaky_hello_world");
+ Statistics stats{};
+ Progress progress{};
+
{
SetLauncher();
auto clargs = p.CmdLineArgs("_entry_points_ctimes");
GraphTraverser const gt{clargs.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
auto const result =
gt.BuildAndStage(clargs.graph_description, clargs.artifacts);
@@ -445,13 +488,15 @@ static void TestFlakyHelloWorldDetected(bool /*is_hermetic*/ = true) {
GraphTraverser const gt_output{clargs_output.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
REQUIRE(gt_output.BuildAndStage(clargs_output.graph_description,
clargs_output.artifacts));
- CHECK(Statistics::Instance().ActionsFlakyCounter() == 1);
- CHECK(Statistics::Instance().RebuiltActionComparedCounter() == 1);
- CHECK(Statistics::Instance().RebuiltActionMissingCounter() == 1);
- Statistics::Instance().Reset();
+ CHECK(stats.ActionsFlakyCounter() == 1);
+ CHECK(stats.RebuiltActionComparedCounter() == 1);
+ CHECK(stats.RebuiltActionMissingCounter() == 1);
+ stats.Reset();
// make_exe[flaky]->make_output[miss]->strip_time [miss]
auto clargs_stripped = p.CmdLineArgs("_entry_points_stripped");
@@ -460,13 +505,15 @@ static void TestFlakyHelloWorldDetected(bool /*is_hermetic*/ = true) {
clargs_stripped.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
REQUIRE(gt_stripped.BuildAndStage(clargs_stripped.graph_description,
clargs_stripped.artifacts));
- CHECK(Statistics::Instance().ActionsFlakyCounter() == 1);
- CHECK(Statistics::Instance().RebuiltActionComparedCounter() == 1);
- CHECK(Statistics::Instance().RebuiltActionMissingCounter() == 2);
- Statistics::Instance().Reset();
+ CHECK(stats.ActionsFlakyCounter() == 1);
+ CHECK(stats.RebuiltActionComparedCounter() == 1);
+ CHECK(stats.RebuiltActionMissingCounter() == 2);
+ stats.Reset();
// make_exe[flaky]->make_output[miss]->strip_time[miss]->list_ctimes [flaky]
auto clargs_ctimes = p.CmdLineArgs("_entry_points_ctimes");
@@ -474,12 +521,14 @@ static void TestFlakyHelloWorldDetected(bool /*is_hermetic*/ = true) {
GraphTraverser const gt_ctimes{clargs_ctimes.gtargs,
p.GetRepoConfig(),
RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList()};
+ RemoteExecutionConfig::DispatchList(),
+ &stats,
+ &progress};
REQUIRE(gt_ctimes.BuildAndStage(clargs_ctimes.graph_description,
clargs_ctimes.artifacts));
- CHECK(Statistics::Instance().ActionsFlakyCounter() == 2);
- CHECK(Statistics::Instance().RebuiltActionComparedCounter() == 2);
- CHECK(Statistics::Instance().RebuiltActionMissingCounter() == 2);
+ CHECK(stats.ActionsFlakyCounter() == 2);
+ CHECK(stats.RebuiltActionComparedCounter() == 2);
+ CHECK(stats.RebuiltActionMissingCounter() == 2);
}
#endif // INCLUDED_SRC_TEST_BUILDTOOL_GRAPH_GRAVERSER_GRAPH_TRAVERSER_TEST_HPP