MCPcopy Create free account
hub / github.com/ElementsProject/elements / TestInterleavedScenarios

Function TestInterleavedScenarios

src/test/txrequest_tests.cpp:683–727  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

681}
682
683void TestInterleavedScenarios()
684{
685 // Create a list of functions which add tests to scenarios.
686 std::vector<std::function<void(Scenario&)>> builders;
687 // Add instances of every test, for every configuration.
688 for (int n = 0; n < 64; ++n) {
689 builders.emplace_back([n](Scenario& scenario){ BuildWtxidTest(scenario, n); });
690 builders.emplace_back([n](Scenario& scenario){ BuildRequestOrderTest(scenario, n & 3); });
691 builders.emplace_back([n](Scenario& scenario){ BuildSingleTest(scenario, n & 31); });
692 builders.emplace_back([n](Scenario& scenario){ BuildPriorityTest(scenario, n & 31); });
693 builders.emplace_back([n](Scenario& scenario){ BuildBigPriorityTest(scenario, (n & 7) + 1); });
694 builders.emplace_back([](Scenario& scenario){ BuildTimeBackwardsTest(scenario); });
695 builders.emplace_back([](Scenario& scenario){ BuildWeirdRequestsTest(scenario); });
696 }
697 // Randomly shuffle all those functions.
698 Shuffle(builders.begin(), builders.end(), g_insecure_rand_ctx);
699
700 Runner runner;
701 auto starttime = RandomTime1y();
702 // Construct many scenarios, and run (up to) 10 randomly-chosen tests consecutively in each.
703 while (builders.size()) {
704 // Introduce some variation in the start time of each scenario, so they don't all start off
705 // concurrently, but get a more random interleaving.
706 auto scenario_start = starttime + RandomTime8s() + RandomTime8s() + RandomTime8s();
707 Scenario scenario(runner, scenario_start);
708 for (int j = 0; builders.size() && j < 10; ++j) {
709 builders.back()(scenario);
710 builders.pop_back();
711 }
712 }
713 // Sort all the actions from all those scenarios chronologically, resulting in the actions from
714 // distinct scenarios to become interleaved. Use stable_sort so that actions from one scenario
715 // aren't reordered w.r.t. each other.
716 std::stable_sort(runner.actions.begin(), runner.actions.end(), [](const Action& a1, const Action& a2) {
717 return a1.first < a2.first;
718 });
719
720 // Run all actions from all scenarios, in order.
721 for (auto& action : runner.actions) {
722 action.second();
723 }
724
725 BOOST_CHECK_EQUAL(runner.txrequest.Size(), 0U);
726 BOOST_CHECK(runner.expired.empty());
727}
728
729} // namespace
730

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 15

BuildWtxidTestFunction · 0.85
BuildRequestOrderTestFunction · 0.85
BuildSingleTestFunction · 0.85
BuildPriorityTestFunction · 0.85
BuildBigPriorityTestFunction · 0.85
BuildTimeBackwardsTestFunction · 0.85
BuildWeirdRequestsTestFunction · 0.85
RandomTime1yFunction · 0.85
RandomTime8sFunction · 0.85
emplace_backMethod · 0.80
ShuffleFunction · 0.50
beginMethod · 0.45

Tested by

no test coverage detected