mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 00:19:30 -05:00
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
This commit is contained in:
parent
6be4a464a5
commit
23f6c405c8
@ -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<RsPeerId> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
74
tests/unittests/libretroshare/services/gxs/GxsPeerNode.cc
Normal file
74
tests/unittests/libretroshare/services/gxs/GxsPeerNode.cc
Normal file
@ -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<RsPeerId> &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<std::string> 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<std::string> filesToKeep;
|
||||
RsDirUtil::cleanupDirectory(mGxsDir, filesToKeep);
|
||||
}
|
||||
|
||||
|
||||
|
34
tests/unittests/libretroshare/services/gxs/GxsPeerNode.h
Normal file
34
tests/unittests/libretroshare/services/gxs/GxsPeerNode.h
Normal file
@ -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<RsPeerId> &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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
79
tests/unittests/libretroshare/services/gxs/nxspair_tests.cc
Normal file
79
tests/unittests/libretroshare/services/gxs/nxspair_tests.cc
Normal file
@ -0,0 +1,79 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 \
|
||||
|
Loading…
Reference in New Issue
Block a user