From 23f6c405c8dc4c9c56af438474a1e048df1ff468 Mon Sep 17 00:00:00 2001 From: drbob Date: Sun, 13 Apr 2014 12:21:51 +0000 Subject: [PATCH] Added framework for testing a pair of GXS services. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7272 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../services/gxs/GxsPairServiceTester.cc | 64 +++++++++++++++ .../services/gxs/GxsPairServiceTester.h | 23 ++++++ .../libretroshare/services/gxs/GxsPeerNode.cc | 74 +++++++++++++++++ .../libretroshare/services/gxs/GxsPeerNode.h | 34 ++++++++ .../services/gxs/nxspair_tests.cc | 79 +++++++++++++++++++ tests/unittests/unittests.pro | 6 +- 6 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 tests/unittests/libretroshare/services/gxs/GxsPairServiceTester.cc create mode 100644 tests/unittests/libretroshare/services/gxs/GxsPairServiceTester.h create mode 100644 tests/unittests/libretroshare/services/gxs/GxsPeerNode.cc create mode 100644 tests/unittests/libretroshare/services/gxs/GxsPeerNode.h create mode 100644 tests/unittests/libretroshare/services/gxs/nxspair_tests.cc diff --git a/tests/unittests/libretroshare/services/gxs/GxsPairServiceTester.cc b/tests/unittests/libretroshare/services/gxs/GxsPairServiceTester.cc new file mode 100644 index 000000000..125307514 --- /dev/null +++ b/tests/unittests/libretroshare/services/gxs/GxsPairServiceTester.cc @@ -0,0 +1,64 @@ + +// local +#include "GxsPairServiceTester.h" +#include "GxsPeerNode.h" +#include "gxstestservice.h" + +// libretroshare +#include "serialiser/rsnxsitems.h" + +GxsPairServiceTester::GxsPairServiceTester(const RsPeerId &peerId1, const RsPeerId &peerId2, int testMode) + :SetServiceTester() +{ + // setup stuff. + addSerialType(new RsNxsSerialiser(RS_SERVICE_GXS_TYPE_TEST)); + + std::list friendList1, friendList2; + friendList1.push_back(peerId2); + friendList2.push_back(peerId1); + + GxsPeerNode *n1 = new GxsPeerNode(peerId1, friendList1, testMode); + GxsPeerNode *n2 = new GxsPeerNode(peerId2, friendList2, testMode); + + addNode(peerId1, n1); + addNode(peerId2, n2); + + startup(); + tick(); + + bringOnline(peerId1, friendList1); + bringOnline(peerId2, friendList2); +} + + +GxsPairServiceTester::~GxsPairServiceTester() +{ + return; +} + + +GxsPeerNode *GxsPairServiceTester::getGxsPeerNode(const RsPeerId &id) +{ + return (GxsPeerNode *) getPeerNode(id); +} + + +void GxsPairServiceTester::createGroup(const RsPeerId &id, const std::string &name) +{ + /* create a couple of groups */ + GxsTestService *testService = getGxsPeerNode(id)->mTestService; + RsTokenService *tokenService = testService->RsGenExchange::getTokenService(); + + RsTestGroup grp1; + grp1.mMeta.mGroupName = name; + grp1.mTestString = "testString"; + uint32_t token1; + + testService->submitTestGroup(token1, grp1); + while(tokenService->requestStatus(token1) != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE) + { + tick(); + sleep(1); + } +} + diff --git a/tests/unittests/libretroshare/services/gxs/GxsPairServiceTester.h b/tests/unittests/libretroshare/services/gxs/GxsPairServiceTester.h new file mode 100644 index 000000000..91bd661d4 --- /dev/null +++ b/tests/unittests/libretroshare/services/gxs/GxsPairServiceTester.h @@ -0,0 +1,23 @@ +#pragma once + +// from librssimulator +#include "testing/SetServiceTester.h" + +class GxsPeerNode; + +class GxsPairServiceTester: public SetServiceTester +{ +public: + + GxsPairServiceTester(const RsPeerId &peerId1, const RsPeerId &peerId2, int testMode); + ~GxsPairServiceTester(); + + void createGroup(const RsPeerId &id, const std::string &name); + + GxsPeerNode *getGxsPeerNode(const RsPeerId &id); +}; + + + + + diff --git a/tests/unittests/libretroshare/services/gxs/GxsPeerNode.cc b/tests/unittests/libretroshare/services/gxs/GxsPeerNode.cc new file mode 100644 index 000000000..9d62e7267 --- /dev/null +++ b/tests/unittests/libretroshare/services/gxs/GxsPeerNode.cc @@ -0,0 +1,74 @@ + +// from libretroshare +#include "services/p3statusservice.h" +#include "serialiser/rsstatusitems.h" +#include "gxs/rsgixs.h" +#include "gxs/rsdataservice.h" +#include "gxs/rsgxsnetservice.h" +#include "util/rsdir.h" + +// local +#include "GxsPeerNode.h" +#include "gxstestservice.h" + +GxsPeerNode::GxsPeerNode(const RsPeerId &ownId, const std::list &friends, int testMode) + :PeerNode(ownId, friends, false), + mTestMode(testMode), + mGxsDir("./gxs_unittest/" + ownId.toStdString() + "/"), + mGxsIdService(NULL), + mGxsCircles(NULL), + mTestService(NULL), + mTestDs(NULL), + mTestNs(NULL) +{ + // extract bits we need. + p3PeerMgr *peerMgr = getPeerMgr(); + p3LinkMgr *linkMgr = getLinkMgr(); + p3NetMgr *netMgr = getNetMgr(); + RsNxsNetMgr *nxsMgr = getNxsNetMgr(); + p3ServiceControl *serviceCtrl = getServiceControl(); + + // Create Service for Testing. + // Specific Testing service here. + RsDirUtil::checkCreateDirectory(mGxsDir); + + std::set filesToKeep; + RsDirUtil::cleanupDirectory(mGxsDir, filesToKeep); + + mTestDs = new RsDataService(mGxsDir, "test_db", + RS_SERVICE_GXS_TYPE_TEST, + NULL, "testPasswd"); + + mTestService = new GxsTestService(mTestDs, NULL, mGxsIdService, testMode); + + mTestNs = new RsGxsNetService( + RS_SERVICE_GXS_TYPE_TEST, mTestDs, nxsMgr, + mTestService, mTestService->getServiceInfo(), + mGxsIdService, mGxsCircles); + + AddService(mTestNs); + + //mConfigMgr->addConfiguration("posted.cfg", posted_ns); + createThread(*mTestService); + createThread(*mTestNs); + + //node->AddPqiServiceMonitor(status); +} + + +GxsPeerNode::~GxsPeerNode() +{ + mTestService->join(); + mTestNs->join(); + + delete mTestNs; + delete mTestService; + // this is deleted somewhere else? + //delete mTestDs; + + std::set filesToKeep; + RsDirUtil::cleanupDirectory(mGxsDir, filesToKeep); +} + + + diff --git a/tests/unittests/libretroshare/services/gxs/GxsPeerNode.h b/tests/unittests/libretroshare/services/gxs/GxsPeerNode.h new file mode 100644 index 000000000..235a5c965 --- /dev/null +++ b/tests/unittests/libretroshare/services/gxs/GxsPeerNode.h @@ -0,0 +1,34 @@ +#pragma once + +// from librssimulator +#include "peer/PeerNode.h" + +class RsGxsIdExchange; +class RsGxsCircleExchange; +class GxsTestService; +class RsGeneralDataService; +class RsGxsNetService; + +class GxsPeerNode: public PeerNode +{ +public: + + GxsPeerNode(const RsPeerId &ownId, const std::list &peers, int testMode); + ~GxsPeerNode(); + + uint32_t mTestMode; + std::string mGxsDir; + + // Id and Circle Interfaces. (NULL for now). + RsGxsIdExchange *mGxsIdService; + RsGxsCircleExchange *mGxsCircles; + + GxsTestService *mTestService; + RsGeneralDataService* mTestDs; + RsGxsNetService* mTestNs; +}; + + + + + diff --git a/tests/unittests/libretroshare/services/gxs/nxspair_tests.cc b/tests/unittests/libretroshare/services/gxs/nxspair_tests.cc new file mode 100644 index 000000000..78b322bee --- /dev/null +++ b/tests/unittests/libretroshare/services/gxs/nxspair_tests.cc @@ -0,0 +1,79 @@ + +#include + +// from librssimulator + +// from libretroshare +#include "serialiser/rsnxsitems.h" + +// local +#include "GxsPairServiceTester.h" +#include "gxstestservice.h" + +/* Here we want to test the most basic NXS interactions. + * we have a GXS service, with no AuthorIDs or Circles. + * + */ + +/* + * Test 1: nothing in Groups.... only sync packets. + * + * This test is rather slow - should speed it up. + */ + +TEST(libretroshare_services, GxsNxsPairExchange1) +{ + RsPeerId p1 = RsPeerId::random(); + RsPeerId p2 = RsPeerId::random(); + int testMode = 0; + + GxsPairServiceTester tester(p1, p2, testMode); + + // we only care about the transaction going one way ... + // so drop SyncGrp packets from p2 -> p1. + + SetFilter &dropFilter = tester.getDropFilter(); + dropFilter.setFilterMode(SetFilter::FILTER_PARAMS); + dropFilter.setUseSource(true); + dropFilter.addSource(p2); + { + RsNxsSyncGrp *syncGrp = new RsNxsSyncGrp(RS_SERVICE_GXS_TYPE_TEST); + dropFilter.setUseFullTypes(true); + dropFilter.addFullType(syncGrp->PacketId()); + } + + // these are currently slow operations. + tester.createGroup(p2, "group1"); + tester.createGroup(p2, "group2"); + + int counter = 0; + while((counter < 60)) + { + counter++; + tester.tick(); + sleep(1); + } + + std::cerr << "=========================================================================================="; + std::cerr << std::endl; + std::cerr << "#Packets: " << tester.getPacketCount(); + std::cerr << std::endl; + + for(int i = 0; i < tester.getPacketCount(); i++) + { + SetPacket &pkt = tester.examinePacket(i); + + std::cerr << "=========================================================================================="; + std::cerr << std::endl; + std::cerr << "Time: " << pkt.mTime; + std::cerr << " From: " << pkt.mSrcId.toStdString() << " To: " << pkt.mDestId.toStdString(); + std::cerr << std::endl; + std::cerr << "-----------------------------------------------------------------------------------------"; + std::cerr << std::endl; + pkt.mItem->print(std::cerr); + std::cerr << "=========================================================================================="; + std::cerr << std::endl; + } +} + + diff --git a/tests/unittests/unittests.pro b/tests/unittests/unittests.pro index 78dbbb847..22344af0b 100644 --- a/tests/unittests/unittests.pro +++ b/tests/unittests/unittests.pro @@ -310,9 +310,13 @@ SOURCES += libretroshare/services/status/status_test.cc \ HEADERS += libretroshare/services/gxs/rsgxstestitems.h \ libretroshare/services/gxs/gxstestservice.h \ libretroshare/services/gxs/GxsIsolatedServiceTester.h \ + libretroshare/services/gxs/GxsPeerNode.h \ + libretroshare/services/gxs/GxsPairServiceTester.h \ SOURCES += libretroshare/services/gxs/rsgxstestitems.cc \ libretroshare/services/gxs/gxstestservice.cc \ libretroshare/services/gxs/GxsIsolatedServiceTester.cc \ + libretroshare/services/gxs/GxsPeerNode.cc \ + libretroshare/services/gxs/GxsPairServiceTester.cc \ libretroshare/services/gxs/nxsbasic_test.cc \ - + libretroshare/services/gxs/nxspair_tests.cc \