Browse Source

Test: PityTest - update tests

master
heck 4 years ago
parent
commit
730cf29479
  1. 45
      test/test_execmodes.cc
  2. 4
      test/test_pitytree.cc
  3. 41
      test/test_processdirs.cc
  4. 29
      test/test_swarm.cc

45
test/test_execmodes.cc

@ -36,28 +36,31 @@ int main(int argc, char* argv[])
// NEW API // NEW API
{ {
// Subprocess 1
TestUnit grp1 = TestUnit{ "grp1",
do_some_work,
&ctxe,
TestUnit::ExecutionMode::PROCESS_PARALLEL };
grp1.addCopy(TestUnit("test1.1", do_some_work));
grp1.addCopy(TestUnit("test1.2", do_some_work));
// Subprocess 2
TestUnit grp2 = TestUnit{ "grp2",
do_some_work,
&ctxe,
TestUnit::ExecutionMode::PROCESS_PARALLEL };
grp2.addCopy(TestUnit("unit_2.1", do_some_work));
grp2.addCopy(TestUnit("unit_2.2", do_some_work));
// Suite // Suite
TestUnit root = TestUnit{ "Test Execution Model" }; TestUnit suite = TestUnit("Test Execution Model");
root.addRef(grp1);
root.addRef(grp2); // Groups
auto grp1 = suite.addNew<TestUnit>(
root.run(); "grp1",
do_some_work,
&ctxe,
TestUnit::ExecutionMode::PROCESS_PARALLEL);
auto grp2 = suite.addNew<TestUnit>(
"grp2",
do_some_work,
&ctxe,
TestUnit::ExecutionMode::PROCESS_PARALLEL);
// Units
grp1.addNew<TestUnit>("test1.1", do_some_work);
grp1.addNew<TestUnit>("test1.2", do_some_work);
// Units
grp2.addNew<TestUnit>("unit_2.1", do_some_work);
grp2.addNew<TestUnit>("unit_2.2", do_some_work);
suite.run();
} }
// Old API // Old API
{ {

4
test/test_pitytree.cc

@ -130,10 +130,10 @@ int main(int argc, char *argv[])
PITYASSERT(b.getChildRefs().size() == 0, "8"); PITYASSERT(b.getChildRefs().size() == 0, "8");
// Create a copy of the node in the parent node // Create a copy of the node in the parent node
b.addCopy(ANode("c")).addCopy(ANode("d")); b.addNew<ANode>("c").addNew<ANode>("d");
std::cout << a.to_string() << std::endl; std::cout << a.to_string() << std::endl;
b.addCopy(BNode("c1")).addCopy(BNode("e")); b.addNew<BNode>("c1").addNew<BNode>("e");
std::cout << a.to_string() << std::endl; std::cout << a.to_string() << std::endl;
b.getChild("c1").getChild("e").addCopy(ANode(a), "a1"); b.getChild("c1").getChild("e").addCopy(ANode(a), "a1");

41
test/test_processdirs.cc

@ -21,77 +21,78 @@ void printHomeDir(TestUnit& myself)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
PityUnit<>::debug_log_enabled = false; PityUnit<>::debug_log_enabled = false;
// Suite
TestUnit suite = TestUnit{ "test_processdirs" }; TestUnit suite = TestUnit{ "test_processdirs" };
// 1 // 1
suite suite
.addCopy(TestUnit( .addNew<TestUnit>(
"node 1", "node 1",
[](TestUnit& pity, TestContext* ctx) { [](TestUnit& pity, TestContext* ctx) {
PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/", "node 1"); PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/", "node 1");
return 0; return 0;
})) })
.addCopy(TestUnit("node 1.1", [](TestUnit& pity, TestContext* ctx) { .addNew<TestUnit>("node 1.1", [](TestUnit& pity, TestContext* ctx) {
PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/", "node 1.1"); PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/", "node 1.1");
return 0; return 0;
})); });
// 2 // 2
suite suite
.addCopy(TestUnit( .addNew<TestUnit>(
"node 2", "node 2",
[](TestUnit& pity, TestContext* ctx) { [](TestUnit& pity, TestContext* ctx) {
PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/", "node 2"); PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/", "node 2");
return 0; return 0;
})) })
.addCopy(TestUnit( .addNew<TestUnit>(
"node 2.1", "node 2.1",
[](TestUnit& pity, TestContext* ctx) { [](TestUnit& pity, TestContext* ctx) {
PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_2_1/", ""); PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_2_1/", "");
return 0; return 0;
}, },
nullptr, nullptr,
PityUnit<>::ExecutionMode::PROCESS_PARALLEL)) PityUnit<>::ExecutionMode::PROCESS_PARALLEL)
.addCopy(TestUnit("node 2.1.1", [](TestUnit& pity, TestContext* ctx) { .addNew<TestUnit>("node 2.1.1", [](TestUnit& pity, TestContext* ctx) {
PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_2_1/", ""); PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_2_1/", "");
return 0; return 0;
})); });
// 3 // 3
suite suite
.addCopy(TestUnit( .addNew<TestUnit>(
"node 3", "node 3",
[](TestUnit& pity, TestContext* ctx) { [](TestUnit& pity, TestContext* ctx) {
PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_3/", ""); PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_3/", "");
return 0; return 0;
}, },
nullptr, nullptr,
PityUnit<>::ExecutionMode::PROCESS_PARALLEL)) PityUnit<>::ExecutionMode::PROCESS_PARALLEL)
.addCopy(TestUnit( .addNew<TestUnit>(
"node 3.1", "node 3.1",
[](TestUnit& pity, TestContext* ctx) { [](TestUnit& pity, TestContext* ctx) {
PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_3/", ""); PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_3/", "");
return 0; return 0;
})) })
.addCopy(TestUnit( .addNew<TestUnit>(
"node 3.1.1", "node 3.1.1",
[](TestUnit& pity, TestContext* ctx) { [](TestUnit& pity, TestContext* ctx) {
PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_3/", ""); PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_3/", "");
return 0; return 0;
})) })
.addCopy(TestUnit( .addNew<TestUnit>(
"node 3.1.1", "node 3.1.1",
[](TestUnit& pity, TestContext* ctx) { [](TestUnit& pity, TestContext* ctx) {
PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/", ""); PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/", "");
return 0; return 0;
}, },
nullptr, nullptr,
PityUnit<>::ExecutionMode::PROCESS_PARALLEL)) PityUnit<>::ExecutionMode::PROCESS_PARALLEL)
.addCopy(TestUnit("node 3.1.1.1", [](TestUnit& pity, TestContext* ctx) { .addNew<TestUnit>("node 3.1.1.1", [](TestUnit& pity, TestContext* ctx) {
PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/", ""); PITYASSERT(pity.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/", "");
return 0; return 0;
})); });
suite.run(); suite.run();
} }

29
test/test_swarm.cc

@ -4,16 +4,24 @@ using namespace pEp;
using namespace pEp::Adapter; using namespace pEp::Adapter;
using namespace pEp::PityTest11; using namespace pEp::PityTest11;
int test_node1(PityUnit<PityPerspective>& unit, PityPerspective* ctx) using TextCTX = PityPerspective;
using TestUnit = PityUnit<TextCTX>;
int test_init(PityUnit<PityPerspective>& unit, PityPerspective* ctx)
{ {
unit.log("ModelName:" + ctx->model.getName()); unit.log("ModelName:" + ctx->model.getName());
unit.log("perspective name:" + ctx->own_name); unit.log("perspective name:" + ctx->own_name);
unit.log("perspective partner:" + ctx->cpt_name); unit.log("perspective partner:" + ctx->cpt_name);
unit.log("HOME: " + std::string(getenv("HOME"))); unit.log("HOME: " + std::string(getenv("HOME")));
return 0;
}
int test_run(PityUnit<PityPerspective>& unit, PityPerspective* ctx)
{
std::string msg = "Message from: " + unit.getPathShort(); std::string msg = "Message from: " + unit.getPathShort();
int throttle = 1000; int throttle = 10;
while (true) { int cycles = 10;
for (int i = 0; i < cycles; i++) {
Utils::sleep_millis(throttle); Utils::sleep_millis(throttle);
for (const auto& peer : ctx->peers) { for (const auto& peer : ctx->peers) {
unit.transport()->sendMsg(peer, msg); unit.transport()->sendMsg(peer, msg);
@ -26,14 +34,23 @@ int test_node1(PityUnit<PityPerspective>& unit, PityPerspective* ctx)
return 0; return 0;
} }
int test_finish(PityUnit<PityPerspective>& unit, PityPerspective* ctx)
{
unit.log("DONE");
return 0;
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int nodesCount = 3; int nodesCount = 3;
PityModel model{ "test_swarm", nodesCount }; PityModel model{ "model_swarm", nodesCount };
PitySwarm swarm{ model }; PitySwarm swarm{ "swarm1", model };
std::cout << swarm.getSwarmUnit().to_string() << std::endl;
for (int i = 0; i < nodesCount; i++) { for (int i = 0; i < nodesCount; i++) {
swarm.addTestUnit(i, "test1", &test_node1); swarm.addTestUnit(i, TestUnit("test1", &test_init));
swarm.addTestUnit(i, TestUnit("test1", &test_run));
swarm.addTestUnit(i, TestUnit("test1", &test_finish));
} }
swarm.run(); swarm.run();

Loading…
Cancel
Save