Skip to content

Commit

Permalink
[test] optimize message test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Jan 1, 2024
1 parent 1a45d6c commit 205b3d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions test/Functional/test-functional-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,34 @@
using namespace CGraph;

void test_functional_04() {
const int ARR_SIZE = 128;
const int RUN_TIMES = 500000;
const int HALF_ARR_SIZE = 32;
const int RUN_TIMES = 200000;
CGRAPH_CREATE_MESSAGE_TOPIC(TestGMessageParam, g_test_message_key, 100)
std::unique_ptr<TestGMessageParam> mp(new TestGMessageParam());
CGRAPH_SEND_MPARAM(TestGMessageParam, g_test_message_key, mp, GMessagePushStrategy::WAIT)

GPipelinePtr pipeline = GPipelineFactory::create();
GElementPtr arr[ARR_SIZE];
GElementPtr arr[HALF_ARR_SIZE * 2]; // 前面一半是串行的,后面一半是并行的
GElementPtrSet linearSet;

CStatus status = pipeline->registerGElement<TestRecvMessageGNode>(&arr[0]);
for (int i = 1; i < ARR_SIZE; i++) {
linearSet.insert(arr[0]);
for (int i = 1; i < HALF_ARR_SIZE; i++) {
status += pipeline->registerGElement<TestRecvMessageGNode>(&arr[i], {arr[i-1]});
linearSet.insert(arr[i]);
}

for (int j = HALF_ARR_SIZE; j < HALF_ARR_SIZE * 2; j++) {
status += pipeline->registerGElement<TestRecvMessageGNode>(&arr[j], linearSet);
}

{
UTimeCounter counter("test_functional_04");
status += pipeline->process(RUN_TIMES);
}

status += CGRAPH_RECV_MPARAM_WITH_TIMEOUT(TestGMessageParam, g_test_message_key, mp, 1)
if (mp->num_ != ARR_SIZE * RUN_TIMES) {
status += CGRAPH_RECV_MPARAM_WITH_TIMEOUT(TestGMessageParam, g_test_message_key, mp, 10)
if (mp->num_ != HALF_ARR_SIZE * RUN_TIMES * 2) {
CGRAPH_ECHO("result num is wrong, num is [%lu]", mp->num_);
}

Expand Down
4 changes: 2 additions & 2 deletions test/_Materials/TestGNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class TestRecvMessageGNode : public CGraph::GNode {
public:
CStatus run() override {
std::unique_ptr<TestGMessageParam> mp = nullptr;
CStatus status = CGRAPH_RECV_MPARAM_WITH_TIMEOUT(TestGMessageParam, g_test_message_key, mp, 1);
CStatus status = CGRAPH_RECV_MPARAM_WITH_TIMEOUT(TestGMessageParam, g_test_message_key, mp, 200);
if (status.isErr()) {
CGraph::CGRAPH_ECHO("error message is : %s", status.getInfo().c_str());
CGraph::CGRAPH_ECHO("error message is [%s]", status.getInfo().c_str());
return status;
}

Expand Down

0 comments on commit 205b3d0

Please sign in to comment.