Browse Source

Test: PityTest - update tests

LIB-11
heck 11 months ago
parent
commit
1df2303835
4 changed files with 70 additions and 49 deletions
  1. +24
    -21
      test/pitytest11/test/test_execmodes.cc
  2. +2
    -2
      test/pitytest11/test/test_pitytree.cc
  3. +21
    -20
      test/pitytest11/test/test_processdirs.cc
  4. +23
    -6
      test/pitytest11/test/test_swarm.cc

+ 24
- 21
test/pitytest11/test/test_execmodes.cc View File

@ -36,28 +36,31 @@ int main(int argc, char* argv[])
// 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
TestUnit root = TestUnit{ "Test Execution Model" };
root.addRef(grp1);
root.addRef(grp2);
root.run();
TestUnit suite = TestUnit("Test Execution Model");
// Groups
auto grp1 = suite.addNew<TestUnit>(
"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
{


+ 2
- 2
test/pitytest11/test/test_pitytree.cc View File

@ -130,10 +130,10 @@ int main(int argc, char *argv[])
PITYASSERT(b.getChildRefs().size() == 0, "8");
// 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;
b.addCopy(BNode("c1")).addCopy(BNode("e"));
b.addNew<BNode>("c1").addNew<BNode>("e");
std::cout << a.to_string() << std::endl;
b.getChild("c1").getChild("e").addCopy(ANode(a), "a1");


+ 21
- 20
test/pitytest11/test/test_processdirs.cc View File

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

+ 23
- 6
test/pitytest11/test/test_swarm.cc View File

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

Loading…
Cancel
Save