From 3decac58fc8def71e3dbd103f40ef1f63eb5a7e6 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Tue, 13 Jun 2023 11:53:49 +0200 Subject: [PATCH] test: Add data transfer and checks to protocol tests --- test/helper/devices/TestPull.h | 22 +++++++++++++++++++--- test/helper/devices/TestPush.h | 8 ++++++-- test/helper/devices/TestRep.h | 34 ++++++++++++++++++++++++++-------- test/helper/devices/TestReq.h | 9 +++++++-- 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/test/helper/devices/TestPull.h b/test/helper/devices/TestPull.h index 93e81a78..c369c5a2 100644 --- a/test/helper/devices/TestPull.h +++ b/test/helper/devices/TestPull.h @@ -28,10 +28,26 @@ class Pull : public Device auto Run() -> void override { - auto msg = NewMessage(); + int counter = 0; - if (Receive(msg, "data") >= 0) - { + auto msg1 = NewMessageFor("data", 0); + + if (Receive(msg1, "data") >= 0) { + ++counter; + } + + auto msg2 = NewMessageFor("data", 0); + + auto ret = Receive(msg2, "data"); + if (ret >= 0) { + auto content = std::string{static_cast(msg2->GetData()), msg2->GetSize()}; + LOG(info) << "Transferred " << static_cast(ret) << " bytes, msg size: " << msg2->GetSize() << ", content: " << content; + if (msg2->GetSize() == static_cast(ret) && content == "testdata1234") { + ++counter; + } + } + + if (counter == 2) { LOG(info) << "PUSH-PULL test successfull"; } }; diff --git a/test/helper/devices/TestPush.h b/test/helper/devices/TestPush.h index 5352360f..3ee3f33c 100644 --- a/test/helper/devices/TestPush.h +++ b/test/helper/devices/TestPush.h @@ -25,8 +25,12 @@ class Push : public Device auto Run() -> void override { - auto msg = NewMessage(); - Send(msg, "data"); + // empty message + auto msg1 = NewMessageFor("data", 0); + Send(msg1, "data"); + // message with short text data + auto msg2(NewSimpleMessageFor("data", 0, "testdata1234")); + Send(msg2, "data"); }; }; diff --git a/test/helper/devices/TestRep.h b/test/helper/devices/TestRep.h index 781a17f7..0615f349 100644 --- a/test/helper/devices/TestRep.h +++ b/test/helper/devices/TestRep.h @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2015-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2015-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -24,22 +24,40 @@ class Rep : public Device std::this_thread::sleep_for(std::chrono::milliseconds(200)); } + bool check(signed long ret, const fair::mq::MessagePtr& msg) + { + auto content = std::string{static_cast(msg->GetData()), msg->GetSize()}; + LOG(info) << "Transferred " << static_cast(ret) << " bytes, msg size: " << msg->GetSize() << ", content: " << content; + return msg->GetSize() == static_cast(ret) && content == "request"; + } + auto Run() -> void override { - auto request1 = NewMessage(); - if (Receive(request1, "data") >= 0) { + int counter = 0; + auto req1 = NewMessage(); + auto ret1 = Receive(req1, "data"); + if (ret1 >= 0) { LOG(info) << "Received request 1"; - auto reply = NewMessage(); + if (check(ret1, req1)) { + ++counter; + } + auto reply = NewSimpleMessageFor("data", 0, "reply"); Send(reply, "data"); } - auto request2 = NewMessage(); - if (Receive(request2, "data") >= 0) { + auto req2 = NewMessage(); + auto ret2 = Receive(req2, "data"); + if (ret2 >= 0) { LOG(info) << "Received request 2"; - auto reply = NewMessage(); + if (check(ret2, req2)) { + ++counter; + } + auto reply = NewSimpleMessageFor("data", 0, "reply"); Send(reply, "data"); } - LOG(info) << "REQ-REP test successfull"; + if (counter == 2) { + LOG(info) << "REQ-REP test successfull"; + } }; }; diff --git a/test/helper/devices/TestReq.h b/test/helper/devices/TestReq.h index a4b9ec50..2c55d7f4 100644 --- a/test/helper/devices/TestReq.h +++ b/test/helper/devices/TestReq.h @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2015-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2015-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -26,12 +26,17 @@ class Req : public Device auto Run() -> void override { - auto request = NewMessage(); + auto request = NewSimpleMessageFor("data", 0, "request"); Send(request, "data"); auto reply = NewMessage(); if (Receive(reply, "data") >= 0) { LOG(info) << "received reply"; + auto content = std::string{static_cast(reply->GetData()), reply->GetSize()}; + LOG(info) << "Transferred reply of size: " << reply->GetSize() << ", content: " << content; + if (content != "reply") { + ChangeStateOrThrow(Transition::ErrorFound); + } } }; };