From 7aae179faebea4b8ef685ed09179ca3d3dec9c75 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 11 May 2023 16:19:38 -0700 Subject: [PATCH] client: test discover() --- test/Makefile | 5 +++ test/testdiscover.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 test/testdiscover.cpp diff --git a/test/Makefile b/test/Makefile index 187d51a..dcaeeb3 100644 --- a/test/Makefile +++ b/test/Makefile @@ -94,6 +94,11 @@ TESTPROD_HOST += testrpc testrpc_SRCS += testrpc.cpp TESTS += testrpc +TESTPROD_HOST += testdiscover +testdiscover_SRCS += testdiscover.cpp +# very slow and dependent on host network config. +#TESTS += testdiscover + TESTPROD_HOST += testnamesrv testnamesrv_SRCS += testnamesrv.cpp TESTS += testnamesrv diff --git a/test/testdiscover.cpp b/test/testdiscover.cpp new file mode 100644 index 0000000..c4d7a97 --- /dev/null +++ b/test/testdiscover.cpp @@ -0,0 +1,89 @@ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvxs is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ +#define PVXS_ENABLE_EXPERT_API + +#include + +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include "evhelper.h" + +namespace { +using namespace pvxs; + +void testBeacon() +{ + testShow()<<__func__; + + auto serv(server::Config::isolated().build()); + auto guid(serv.config().guid); + auto cli(serv.clientConfig().build()); + + MPMCFIFO q1; + auto op1(cli.discover([&q1](const client::Discovered& evt){ + testDiag("Event"); + q1.push(evt); + }).pingAll(false).exec()); + + serv.start(); + + MPMCFIFO q2; + auto op2(cli.discover([&q2](const client::Discovered& evt){ + testDiag("Event"); + q2.push(evt); + }).pingAll(true).exec()); + + testDiag("Waiting for discoveries"); + { + auto evt(q1.pop()); + testEq(evt.event, client::Discovered::Online); + testEq(evt.guid, guid); + } + { + auto evt(q2.pop()); + testEq(evt.event, client::Discovered::Online); + testEq(evt.guid, guid); + } + + serv.stop(); + + testDiag("Wait for timeouts"); + { + auto evt(q1.pop()); + testEq(evt.event, client::Discovered::Timeout); + testEq(evt.guid, guid); + } + { + auto evt(q2.pop()); + testEq(evt.event, client::Discovered::Timeout); + testEq(evt.guid, guid); + + } +} + +} // namespace + +MAIN(testdiscover) +{ + testPlan(8); + logger_config_env(); + testSetup(); + testBeacon(); + logger_config_env(); + cleanup_for_valgrind(); + return testDone(); +}