Testing: add --shard i/n for CI splits
This commit is contained in:
1 parent
546628c5b9
commit
3990c77155
2 files changed
+31
No files matched your search
@@ -97,6 +97,9 @@ namespace Void::Testing
|
|||||||
bool show_help{false};
|
bool show_help{false};
|
||||||
bool allow_empty{false};
|
bool allow_empty{false};
|
||||||
bool fail_fast{false};
|
bool fail_fast{false};
|
||||||
|
/// CI sharding: 1-based shard index and shard count (1/1 = no split).
|
||||||
|
unsigned shard_index{1};
|
||||||
|
unsigned shard_count{1};
|
||||||
unsigned repeat{1};
|
unsigned repeat{1};
|
||||||
unsigned random_seed{0};
|
unsigned random_seed{0};
|
||||||
unsigned parallel_threads{0}; // 0 = sequential
|
unsigned parallel_threads{0}; // 0 = sequential
|
||||||
|
|||||||
@@ -189,6 +189,23 @@ namespace Void::Testing
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (arg == "--shard") {
|
||||||
|
std::string val;
|
||||||
|
if (need_val(arg, i, val)) {
|
||||||
|
const auto slash = val.find('/');
|
||||||
|
unsigned index = 0;
|
||||||
|
unsigned count = 0;
|
||||||
|
if (slash == std::string::npos ||
|
||||||
|
!parse_unsigned_strict(val.substr(0, slash), index) ||
|
||||||
|
!parse_unsigned_strict(val.substr(slash + 1), count) ||
|
||||||
|
count == 0 || index == 0 || index > count) {
|
||||||
|
config.parse_error =
|
||||||
|
std::format("Invalid --shard value: {} (expected i/n, 1 <= i <= n)", val);
|
||||||
|
} else {
|
||||||
|
config.shard_index = index;
|
||||||
|
config.shard_count = count;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (arg == "--help") {
|
} else if (arg == "--help") {
|
||||||
config.show_help = true;
|
config.show_help = true;
|
||||||
} else if (arg == "--list") {
|
} else if (arg == "--list") {
|
||||||
@@ -227,6 +244,7 @@ namespace Void::Testing
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::size_t selected_index = 0;
|
||||||
for (const auto& test : tests) {
|
for (const auto& test : tests) {
|
||||||
if (!config.suite_filter.empty() &&
|
if (!config.suite_filter.empty() &&
|
||||||
test.suite != config.suite_filter) {
|
test.suite != config.suite_filter) {
|
||||||
@@ -249,6 +267,14 @@ namespace Void::Testing
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Deterministic round-robin sharding over the selected order.
|
||||||
|
if (config.shard_count > 1 &&
|
||||||
|
(selected_index % config.shard_count) !=
|
||||||
|
(config.shard_index - 1)) {
|
||||||
|
++selected_index;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++selected_index;
|
||||||
result.push_back(test);
|
result.push_back(test);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -550,6 +576,8 @@ namespace Void::Testing
|
|||||||
<< Void::Testing::Detail::Color::apply(dim, "Do not fail when selection matches zero tests") << "\n"
|
<< Void::Testing::Detail::Color::apply(dim, "Do not fail when selection matches zero tests") << "\n"
|
||||||
<< " " << opt("--fail-fast")
|
<< " " << opt("--fail-fast")
|
||||||
<< Void::Testing::Detail::Color::apply(dim, "Stop after the first failing test (sequential runs)") << "\n"
|
<< Void::Testing::Detail::Color::apply(dim, "Stop after the first failing test (sequential runs)") << "\n"
|
||||||
|
<< " " << opt("--shard <i>/<n>")
|
||||||
|
<< Void::Testing::Detail::Color::apply(dim, "Run only shard i of n (for CI splits)") << "\n"
|
||||||
<< " " << opt("--help")
|
<< " " << opt("--help")
|
||||||
<< Void::Testing::Detail::Color::apply(dim, "Show this help message") << "\n"
|
<< Void::Testing::Detail::Color::apply(dim, "Show this help message") << "\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
|
|||||||
Reference in new issue
Block a user