TEST(Bootstrap, ClientConnectionManagerTest) { // Create a single IO thread, and verify that // client connections are pooled properly TestServer server; auto factory = std::make_shared<TestPipelineFactory>(); server.childPipeline(factory); server.group(std::make_shared<IOThreadPoolExecutor>(1)); server.bind(0); auto base = EventBaseManager::get()->getEventBase(); SocketAddress address; server.getSockets()[0]->getAddress(&address); TestClient client; client.pipelineFactory(std::make_shared<TestClientPipelineFactory>()); client.connect(address); TestClient client2; client2.pipelineFactory(std::make_shared<TestClientPipelineFactory>()); client2.connect(address); base->loop(); server.stop(); CHECK(factory->pipelines == 2); }
TEST(Bootstrap, ServerAcceptGroup2Test) { // Verify that server is using the accept IO group // Check if reuse port is supported, if not, don't run this test try { EventBase base; auto serverSocket = AsyncServerSocket::newSocket(&base); serverSocket->bind(0); serverSocket->listen(0); serverSocket->startAccepting(); serverSocket->setReusePortEnabled(true); serverSocket->stopAccepting(); } catch(...) { LOG(INFO) << "Reuse port probably not supported"; return; } TestServer server; auto factory = std::make_shared<TestPipelineFactory>(); server.childPipeline(factory); server.group(std::make_shared<IOThreadPoolExecutor>(4), nullptr); server.bind(0); SocketAddress address; server.getSockets()[0]->getAddress(&address); TestClient client; client.connect(address); EventBaseManager::get()->getEventBase()->loop(); server.stop(); CHECK(factory->pipelines == 1); }
TEST(Bootstrap, ServerAcceptGroupTest) { // Verify that server is using the accept IO group TestServer server; auto factory = std::make_shared<TestPipelineFactory>(); server.childPipeline(factory); server.group(std::make_shared<IOThreadPoolExecutor>(1), nullptr); server.bind(0); SocketAddress address; server.getSockets()[0]->getAddress(&address); boost::barrier barrier(2); auto thread = std::thread([&](){ TestClient client; client.pipelineFactory(std::make_shared<TestClientPipelineFactory>()); client.connect(address); EventBaseManager::get()->getEventBase()->loop(); barrier.wait(); }); barrier.wait(); server.stop(); thread.join(); CHECK(factory->pipelines == 1); }
TEST_F(QueryTest, SendBuffer) { CUser user("user"); CIRCNetwork network(&user, "network"); CDebug::SetDebug(false); TestClient client; client.SetNick("me"); client.AcceptLogin(user); client.lines.clear(); CQuery query("query", &network); query.AddBuffer(":sender PRIVMSG {target} :{text}", "a message"); query.AddBuffer(":me PRIVMSG someone :{text}", "a self-message"); query.AddBuffer(":sender NOTICE #znc :{text}", "a notice"); client.lines.clear(); query.SendBuffer(&client); EXPECT_THAT(client.lines, ElementsAre(MatchesRegex(R"(:sender PRIVMSG me :\[\d\d:\d\d:\d\d\] a message)"), MatchesRegex(R"(:sender NOTICE #znc :\[\d\d:\d\d:\d\d\] a notice)"))); client.lines.clear(); user.SetTimestampPrepend(false); query.SendBuffer(&client); EXPECT_THAT(client.lines, ElementsAre(":sender PRIVMSG me :a message", ":sender NOTICE #znc :a notice")); client.lines.clear(); user.SetTimestampAppend(true); query.SendBuffer(&client); EXPECT_THAT(client.lines, ElementsAre(MatchesRegex(R"(:sender PRIVMSG me :a message \[\d\d:\d\d:\d\d\])"), MatchesRegex(R"(:sender NOTICE #znc :a notice \[\d\d:\d\d:\d\d\])"))); network.ClientDisconnected(&client); }
int main(int argc, char **argv) { KAboutData about("KNetworkStatusTestClient", 0, ki18n("knetworkstatustestclient"), version, ki18n(description), KAboutData::License_GPL, ki18n("(C) 2007 Will Stephenson"), KLocalizedString(), 0, "*****@*****.**"); about.addAuthor( ki18n("Will Stephenson"), KLocalizedString(), "*****@*****.**" ); KCmdLineArgs::init(argc, argv, &about); KCmdLineOptions options; KCmdLineArgs::addCmdLineOptions(options); KApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->count() == 0) { TestClient *widget = new TestClient; widget->show(); } else { int i = 0; for (; i < args->count(); i++) { TestClient *widget = new TestClient; widget->show(); } } args->clear(); return app.exec(); }
TEST(SocketSuite, splitPackets) { const int port = TEST_PORT_BASE + 1; char ipAddr[] = "127.0.0.1"; const int RECV_LENGTH = 64; TestClient client; TestServer server; ByteArray recv; // Construct server ASSERT_TRUE(server.init(port)); // Construct a client ASSERT_TRUE(client.init(&ipAddr[0], port)); pthread_t serverConnectThrd; pthread_create(&serverConnectThrd, NULL, connectServerFunc, &server); ASSERT_TRUE(client.makeConnect()); pthread_join(serverConnectThrd, NULL); pthread_t senderThrd; pthread_create(&senderThrd, NULL, spinSender, &client); ASSERT_TRUE(server.receiveBytes(recv, RECV_LENGTH)); ASSERT_EQ(RECV_LENGTH, recv.getBufferSize()); pthread_cancel(senderThrd); pthread_join(senderThrd, NULL); }
TEST(Bootstrap, SharedThreadPool) { // Check if reuse port is supported, if not, don't run this test try { EventBase base; auto serverSocket = AsyncServerSocket::newSocket(&base); serverSocket->bind(0); serverSocket->listen(0); serverSocket->startAccepting(); serverSocket->setReusePortEnabled(true); serverSocket->stopAccepting(); } catch(...) { LOG(INFO) << "Reuse port probably not supported"; return; } auto pool = std::make_shared<IOThreadPoolExecutor>(2); TestServer server; auto factory = std::make_shared<TestPipelineFactory>(); server.childPipeline(factory); server.group(pool, pool); server.bind(0); SocketAddress address; server.getSockets()[0]->getAddress(&address); TestClient client; client.pipelineFactory(std::make_shared<TestClientPipelineFactory>()); client.connect(address); TestClient client2; client2.pipelineFactory(std::make_shared<TestClientPipelineFactory>()); client2.connect(address); TestClient client3; client3.pipelineFactory(std::make_shared<TestClientPipelineFactory>()); client3.connect(address); TestClient client4; client4.pipelineFactory(std::make_shared<TestClientPipelineFactory>()); client4.connect(address); TestClient client5; client5.pipelineFactory(std::make_shared<TestClientPipelineFactory>()); client5.connect(address); EventBaseManager::get()->getEventBase()->loop(); server.stop(); CHECK(factory->pipelines == 5); }
// Utility for running tcp client in sending loop void* spinSender(void* arg) { TestClient* client = (TestClient*)arg; ByteArray send; const int DATA = 256; send.load(DATA); while(true) { client->sendBytes(send); sleep(0.1); } }
void TestServer::ReceiveMessage3(TestClient& client, BigInteger A, const BinaryData& Mc) { BinaryData Ms = m_server.VerifyClient(Mc); // Server -> Client: send Ms client.ReceiveMessage4(Ms); }
TEST(Bootstrap, ClientServerTest) { TestServer server; auto factory = std::make_shared<TestPipelineFactory>(); server.childPipeline(factory); server.bind(0); auto base = EventBaseManager::get()->getEventBase(); SocketAddress address; server.getSockets()[0]->getAddress(&address); TestClient client; client.connect(address); base->loop(); server.stop(); CHECK(factory->pipelines == 1); }
//============================================================================== // Get Data //============================================================================== QVariant ClientListModel::data(const QModelIndex& aIndex, int aRole) const { // Check Index if (aIndex.row() >= 0 && aIndex.row() < rowCount()) { // Get Model Item TestClient* item = clientList[aIndex.row()]; // Switch Role switch (aRole) { case ClientID: return item->getID(); case ClientConnected: return item->isConnected(); case ClientAdmin: return item->isAdminModeOn(); case ClientBusy: return item->isBusy(); default: break; } } return QString(""); }
TEST(Bootstrap, LoadBalanceHandler) { TestServer server; auto factory = std::make_shared<TestPipelineFactory>(); server.childPipeline(factory); auto pipelinefactory = std::make_shared<TestHandlerPipelineFactory<TestHandlerPipeline>>(); server.pipeline(pipelinefactory); server.bind(0); auto base = EventBaseManager::get()->getEventBase(); SocketAddress address; server.getSockets()[0]->getAddress(&address); TestClient client; client.pipelineFactory(std::make_shared<TestClientPipelineFactory>()); client.connect(address); base->loop(); server.stop(); CHECK(factory->pipelines == 1); CHECK(connections == 1); }
void TestServer::ReceiveMessage1(TestClient& client, const std::string& strUsername, BigInteger A) { BigInteger s(c_pszaSalt, 16); if (m_strUsername != strUsername) throw std::runtime_error("invalid user"); BigInteger PassVerifier; if (!m_bCacheClientKey || (m_CachedPassVerifier == BigInteger())) { GroupParameter gp = Helper::GetPresetGroupParameter(c_uiPresetIndex); PassVerifier = Helper::GeneratePassword(strUsername, m_strPassword, gp, s); if (m_bCacheClientKey) m_CachedPassVerifier = PassVerifier; } else PassVerifier = m_CachedPassVerifier; BigInteger b; if (m_bRandom) { boost::xint::strong_random_generator srg; b = boost::xint::integer::random_by_size(srg, 256, false, // high_bit_on false, // low_bit_on false);// can_be_negative } else b = BigInteger(c_pszaSmallB, 16); BigInteger B = m_server.GetB(PassVerifier, b); m_server.CalcSessionKey(A, s, strUsername, PassVerifier); // Server -> Client: send s, B client.ReceiveMessage2(*this, s, B); }
TEST(SocketSuite, read) { const int port = TEST_PORT_BASE; char ipAddr[] = "127.0.0.1"; TestClient client; TestServer server; ByteArray send, recv; shared_int DATA = 99; shared_int TWO_INTS = 2 * sizeof(shared_int); shared_int ONE_INTS = 1 * sizeof(shared_int); // Construct server ASSERT_TRUE(server.init(port)); // Construct a client ASSERT_TRUE(client.init(&ipAddr[0], port)); pthread_t serverConnectThrd; pthread_create(&serverConnectThrd, NULL, connectServerFunc, &server); ASSERT_TRUE(client.makeConnect()); pthread_join(serverConnectThrd, NULL); ASSERT_TRUE(send.load(DATA)); // Send just right amount ASSERT_TRUE(client.sendBytes(send)); ASSERT_TRUE(client.sendBytes(send)); sleep(2); ASSERT_TRUE(server.receiveBytes(recv, TWO_INTS)); ASSERT_EQ(TWO_INTS, recv.getBufferSize()); // Send too many bytes ASSERT_TRUE(client.sendBytes(send)); ASSERT_TRUE(client.sendBytes(send)); ASSERT_TRUE(client.sendBytes(send)); ASSERT_TRUE(server.receiveBytes(recv, TWO_INTS)); ASSERT_EQ(TWO_INTS, recv.getBufferSize()); ASSERT_TRUE(server.receiveBytes(recv, ONE_INTS)); ASSERT_EQ(ONE_INTS, recv.getBufferSize()); }
//============================================================================== // Configure Buttons //============================================================================== void TestDialog::configureButtons() { // Check Model if (clientListModel) { // Enable/Disable Buttons ui->createClientButton->setEnabled(true); // Get Test Client TestClient* client = clientListModel->getClient(currentIndex); // Enable/Disable Buttons ui->connectButton->setEnabled(client && !client->isConnected() && !client->isAdminModeOn()); ui->connectAsRootButton->setEnabled(client && (!client->isConnected() || (client->isConnected() && !client->isAdminModeOn()))); ui->disconnectButton->setEnabled(client && client->isConnected()); ui->startButton->setEnabled(client && client->isConnected() && !client->isBusy()); ui->yesButton->setEnabled(client && client->isConnected() && client->isBusy()); ui->noButton->setEnabled(client && client->isConnected() && client->isBusy()); ui->stopButton->setEnabled(client && client->isConnected() && client->isBusy()); //ui->pauseButton->setEnabled(client && client->isConnected() && client->isBusy() && !client->isSuspended()); //ui->resumeButton->setEnabled(client && client->isConnected() && client->isBusy() && client->isSuspended()); ui->clearButton->setEnabled(clientListModel->rowCount() > 0); } else { // Enable/Disable Buttons ui->createClientButton->setEnabled(false); ui->connectButton->setEnabled(false); ui->connectAsRootButton->setEnabled(false); ui->startButton->setEnabled(false); ui->yesButton->setEnabled(false); ui->noButton->setEnabled(false); ui->stopButton->setEnabled(false); ui->pauseButton->setEnabled(false); ui->resumeButton->setEnabled(false); ui->disconnectButton->setEnabled(false); ui->clearButton->setEnabled(false); } }
#include "TestClient.h" #include "TestServer.h" #include "testing.h" TEST_CASE("No erroneous transform messages on login", "") { TestServer s = TestServer::WithData("basic_rock"); s.addObject("rock", {20, 20}); TestClient c = TestClient::WithData("basic_rock"); s.waitForUsers(1); bool transformTimeReceived = c.waitForMessage(SV_TRANSFORM_TIME, 200); CHECK_FALSE(transformTimeReceived); }
TEST(DISABLED_MessageManagerSuite, tcp) { const int port = TEST_PORT_BASE + 201; char ipAddr[] = "127.0.0.1"; TestClient* client = new TestClient(); TestServer server; SimpleMessage pingRequest, pingReply; MessageManager msgManager; // MessageManager uses ros::ok, which needs ros spinner ros::AsyncSpinner spinner(0); spinner.start(); ASSERT_TRUE(pingRequest.init(StandardMsgTypes::PING, CommTypes::SERVICE_REQUEST, ReplyTypes::INVALID)); // TCP Socket testing // Construct server ASSERT_TRUE(server.init(port)); // Construct a client ASSERT_TRUE(client->init(&ipAddr[0], port)); // Connect server and client pthread_t serverConnectThrd; pthread_create(&serverConnectThrd, NULL, connectServerFunc, &server); ASSERT_TRUE(client->makeConnect()); pthread_join(serverConnectThrd, NULL); // Listen for client connection, init manager and start thread ASSERT_TRUE(msgManager.init(&server)); // TODO: The message manager is not thread safe (threads are used for testing, // but running the message manager in a thread results in errors when the // underlying connection is deconstructed before the manager //boost::thread spinSrvThrd(boost::bind(&MessageManager::spin, &msgManager)); pthread_t spinSrvThrd; pthread_create(&spinSrvThrd, NULL, spinFunc, &msgManager); // Ping the server ASSERT_TRUE(client->sendMsg(pingRequest)); ASSERT_TRUE(client->receiveMsg(pingReply)); ASSERT_TRUE(client->sendAndReceiveMsg(pingRequest, pingReply)); // Delete client and try to reconnect delete client; sleep(10); //Allow time for client to destruct and free up port client = new TestClient(); ASSERT_TRUE(client->init(&ipAddr[0], port)); ASSERT_TRUE(client->makeConnect()); ASSERT_TRUE(client->sendAndReceiveMsg(pingRequest, pingReply)); pthread_cancel(spinSrvThrd); pthread_join(spinSrvThrd, NULL); delete client; }
static void __stdcall Basics() { // we need this line here in order to create windows from the cfix // console application that runs our tests if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) return; // setup our objects TLServer_WM s; s.Start(); TestClient c; TestClient c2; char* sym = "TST"; int size = 200; double price = 100; TLMarketBasket mb; mb.Add(sym); c.Subscribe(mb); // initial tests CFIX_ASSERT(c.ticks+c.fills+c.orders==0); // Tick test TLTick k; symcp(k.sym,sym); //k.sym = sym; k.trade = price; k.size = size; s.SrvGotTick(k); // send tick CFIX_ASSERT(c.ticks==1); // test output // cout<<strcat(c.lasttick.sym,k.sym)<<endl; CFIX_ASSERT(isstrsame(c.lasttick.sym,k.sym)); CFIX_ASSERT(c.lasttick.trade==k.trade); // make sure ticks were not copied to other clients CFIX_ASSERT(c.ticks!=c2.ticks); // Fill test TLTrade f; f.symbol = sym; f.xprice = price; f.xsize = size; f.xdate = 20081220; f.xtime = 1556; f.side = true; s.SrvGotFill(f); CFIX_ASSERT(c.fills==1); CFIX_ASSERT(c.lastfill.symbol==f.symbol); CFIX_ASSERT(c.lastfill.xprice==f.xprice); // make sure fills were copiedto other clients CFIX_ASSERT(c.fills==c2.fills); // Order test TLOrder o; o.symbol = sym; o.price = price; o.size = size; s.SrvGotOrder(o); CFIX_ASSERT(c.orders==1); CFIX_ASSERT(c.lastorder.symbol==o.symbol); CFIX_ASSERT(c.lastorder.price==o.price); // make sure orders were copied to other clients CFIX_ASSERT(c.orders==c2.orders); // performance test ticks // reset ticks c.ticks = 0; // get random ticks const int MAXTICKS = 1000; vector<TLTick> ticks; for (int i = 0; i<MAXTICKS; i++) { TLTick k; symcp(k.sym,sym); k.size = size; k.trade = rand(); ticks.push_back(k); } // start timer unsigned long start = GetTickCount(); // send ticks to clients for (unsigned int i =0; i<ticks.size(); i++) s.SrvGotTick(ticks[i]); // stop timer unsigned long stop = GetTickCount(); // elapased time int elap = (stop - start); // ticks per second int rate = (MAXTICKS / elap)*1000; CFIX_LOG(L"Performance elap (ms): %i",elap); CFIX_LOG(L"Performance (ticks/sec): %i",rate); // make sure it took reasonable time CFIX_ASSERT(elap<200); }