Run deterministic world stages on the bounded Void executor
This commit is contained in:
1 parent
8d2870a6f8
commit
68f91a236a
10 files changed
+400
-81
No files matched your search
+20
-8
@@ -42,9 +42,10 @@ std::string saved_state(const World& world) {
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::unique_ptr<World> load_state(const std::string& bytes, ExecutionConfig config) {
|
||||
std::unique_ptr<World> load_state(const std::string& bytes, ExecutionConfig config,
|
||||
WorkerPoolOptions options = {}) {
|
||||
std::istringstream stream(bytes, std::ios::binary);
|
||||
auto world = World::read_save(stream, config.workers, config.mode);
|
||||
auto world = World::read_save(stream, config.workers, config.mode, std::move(options));
|
||||
require(world->worker_count() == config.workers, "load changed the requested worker count");
|
||||
return world;
|
||||
}
|
||||
@@ -53,12 +54,13 @@ std::unique_ptr<World> load_state(const std::string& bytes, ExecutionConfig conf
|
||||
// checkpoint copies are added, so reload is checked against uninterrupted work.
|
||||
class ReplayWorlds {
|
||||
public:
|
||||
explicit ReplayWorlds(const World& initial) {
|
||||
explicit ReplayWorlds(const World& initial, std::size_t capacity = 4096)
|
||||
: options_{.max_admitted = capacity} {
|
||||
const auto bytes = saved_state(initial);
|
||||
reference = load_state(bytes, execution_configs.front());
|
||||
reference = load_state(bytes, execution_configs.front(), options_);
|
||||
require(saved_state(*reference) == bytes, "loading changed the starting fixture");
|
||||
for (std::size_t i = 1; i < execution_configs.size(); ++i) {
|
||||
runs_.push_back({execution_configs[i], false, load_state(bytes, execution_configs[i])});
|
||||
runs_.push_back({execution_configs[i], false, load_state(bytes, execution_configs[i], options_)});
|
||||
}
|
||||
compare();
|
||||
}
|
||||
@@ -85,7 +87,7 @@ public:
|
||||
void checkpoint() {
|
||||
const auto bytes = saved_state(*reference);
|
||||
for (auto config : execution_configs) {
|
||||
runs_.push_back({config, true, load_state(bytes, config)});
|
||||
runs_.push_back({config, true, load_state(bytes, config, options_)});
|
||||
}
|
||||
compare();
|
||||
}
|
||||
@@ -117,6 +119,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
WorkerPoolOptions options_;
|
||||
std::vector<Run> runs_;
|
||||
};
|
||||
|
||||
@@ -125,6 +128,7 @@ struct [[= Void::Testing::name("ReplayTests")]] ReplayTests : Void::Testing::Sui
|
||||
[[= Void::Testing::tag("replay")]] Test test_one_resident_completes_work();
|
||||
[[= Void::Testing::tag("replay")]] Test test_competing_jobs_retry_unreachable_routes();
|
||||
[[= Void::Testing::tag("replay")]] Test test_recorded_colony_commands_and_loaded_delivery();
|
||||
[[= Void::Testing::tag("replay")]] Test test_recorded_colony_at_capacity_one();
|
||||
[[= Void::Testing::tag("replay")]] Test test_last_meal_has_one_winner_and_one_consumer();
|
||||
};
|
||||
|
||||
@@ -199,9 +203,9 @@ Test ReplayTests::test_competing_jobs_retry_unreachable_routes() {
|
||||
"the completed count hid an unfinished reachable job");
|
||||
}
|
||||
|
||||
Test ReplayTests::test_recorded_colony_commands_and_loaded_delivery() {
|
||||
void replay_colony_journal(std::size_t capacity) {
|
||||
const auto initial = make_first_colony(2);
|
||||
ReplayWorlds replay(*initial);
|
||||
ReplayWorlds replay(*initial, capacity);
|
||||
struct RecordedCommand {
|
||||
int attempt;
|
||||
PlayerCommand command;
|
||||
@@ -263,6 +267,14 @@ Test ReplayTests::test_recorded_colony_commands_and_loaded_delivery() {
|
||||
"rejected commands changed player sequence progress");
|
||||
}
|
||||
|
||||
Test ReplayTests::test_recorded_colony_commands_and_loaded_delivery() {
|
||||
replay_colony_journal(4096);
|
||||
}
|
||||
|
||||
Test ReplayTests::test_recorded_colony_at_capacity_one() {
|
||||
replay_colony_journal(1);
|
||||
}
|
||||
|
||||
Test ReplayTests::test_last_meal_has_one_winner_and_one_consumer() {
|
||||
World initial(97, 8, 8);
|
||||
const auto pantry = initial.add_storage({1, 1}, 1, StorageKind::Pantry);
|
||||
|
||||
Reference in new issue
Block a user