| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706 |
- /*
- * Copyright (c) 2014, Oculus VR, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
- #include "ManyClientsOneServerNonBlockingTest.h"
- /*
- What is being done here is having 256 clients connect to one server, disconnect, connect again.
- Do this for about 10 seconds. Then allow them all to connect for one last time.
- This one has a nonblocking recieve so doesn't wait for connects or anything.
- Just rapid connecting disconnecting.
- Good ideas for changes:
- After the last check run a eightpeers like test an add the conditions
- of that test as well.
- Make sure that if we initiate the connection we get a proper message
- and if not we get a proper message. Add proper conditions.
- Randomize sending the disconnect notes
- Success conditions:
- All connected normally.
- Failure conditions:
- Doesn't reconnect normally.
- During the very first connect loop any connect returns false.
- Connect function returns false and peer is not connected to anything.
- */
- int ManyClientsOneServerNonBlockingTest::RunTest(DataStructures::List<RakString> params,bool isVerbose,bool noPauses)
- {
- const int clientNum= 256;
- RakPeerInterface *clientList[clientNum];//A list of clients
- RakPeerInterface *server;//The server
- SystemAddress currentSystem;
- //SystemAddress currentSystem;
- Packet *packet;
- destroyList.Clear(false,_FILE_AND_LINE_);
- //Initializations of the arrays
- for (int i=0;i<clientNum;i++)
- {
- clientList[i]=RakPeerInterface::GetInstance();
- destroyList.Push(clientList[i],_FILE_AND_LINE_);
- clientList[i]->Startup(1,&SocketDescriptor(), 1);
- }
- server=RakPeerInterface::GetInstance();
- destroyList.Push(server,_FILE_AND_LINE_);
- server->Startup(clientNum, &SocketDescriptor(60000,0), 1);
- server->SetMaximumIncomingConnections(clientNum);
- //Connect all the clients to the server
- for (int i=0;i<clientNum;i++)
- {
- if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
- {
- if (isVerbose)
- DebugTools::ShowError("Problem while calling connect.\n",!noPauses && isVerbose,__LINE__,__FILE__);
- return 1;//This fails the test, don't bother going on.
- }
- }
- TimeMS entryTime=GetTimeMS();//Loop entry time
- DataStructures::List< SystemAddress > systemList;
- DataStructures::List< RakNetGUID > guidList;
- if (isVerbose)
- printf("Entering disconnect loop \n");
- while(GetTimeMS()-entryTime<10000)//Run for 10 Secoonds
- {
- //Disconnect all clients IF connected to any from client side
- for (int i=0;i<clientNum;i++)
- {
- clientList[i]->GetSystemList(systemList,guidList);//Get connectionlist
- int len=systemList.Size();
- for (int j=0;j<len;j++)//Disconnect them all
- {
- clientList[i]->CloseConnection (systemList[j],true,0,LOW_PRIORITY);
- }
- }
- //RakSleep(100);
- //Connect
- for (int i=0;i<clientNum;i++)
- {
- currentSystem.SetBinaryAddress("127.0.0.1");
- currentSystem.port=60000;
- if(!CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
- {
- if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
- {
- if (isVerbose)
- DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
- return 1;//This fails the test, don't bother going on.
- }
- }
- }
- //Server receive
- packet=server->Receive();
- if (isVerbose&&packet)
- printf("For server\n");
- while(packet)
- {
- switch (packet->data[0])
- {
- case ID_REMOTE_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("Another client has disconnected.\n");
- break;
- case ID_REMOTE_CONNECTION_LOST:
- if (isVerbose)
- printf("Another client has lost the connection.\n");
- break;
- case ID_REMOTE_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("Another client has connected.\n");
- break;
- case ID_CONNECTION_REQUEST_ACCEPTED:
- if (isVerbose)
- printf("Our connection request has been accepted.\n");
- break;
- case ID_CONNECTION_ATTEMPT_FAILED:
- if (isVerbose)
- printf("A connection has failed.\n");
- break;
- case ID_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("A connection is incoming.\n");
- break;
- case ID_NO_FREE_INCOMING_CONNECTIONS:
- if (isVerbose)
- printf("The server is full.\n");
- break;
- case ID_ALREADY_CONNECTED:
- if (isVerbose)
- printf("Already connected\n");
- break;
- case ID_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("We have been disconnected.\n");
- break;
- case ID_CONNECTION_LOST:
- if (isVerbose)
- printf("Connection lost.\n");
- break;
- default:
- break;
- }
- server->DeallocatePacket(packet);
- // Stay in the loop as long as there are more packets.
- packet = server->Receive();
- }
- for (int i=0;i<clientNum;i++)//Receive for all peers
- {
- packet=clientList[i]->Receive();
- if (isVerbose&&packet)
- printf("For peer %i\n",i);
- while(packet)
- {
- switch (packet->data[0])
- {
- case ID_REMOTE_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("Another client has disconnected.\n");
- break;
- case ID_REMOTE_CONNECTION_LOST:
- if (isVerbose)
- printf("Another client has lost the connection.\n");
- break;
- case ID_REMOTE_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("Another client has connected.\n");
- break;
- case ID_CONNECTION_REQUEST_ACCEPTED:
- if (isVerbose)
- printf("Our connection request has been accepted.\n");
- break;
- case ID_CONNECTION_ATTEMPT_FAILED:
- if (isVerbose)
- printf("A connection has failed.\n");
- break;
- case ID_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("A connection is incoming.\n");
- break;
- case ID_NO_FREE_INCOMING_CONNECTIONS:
- if (isVerbose)
- printf("The server is full.\n");
- break;
- case ID_ALREADY_CONNECTED:
- if (isVerbose)
- printf("Already connected\n");
- break;
- case ID_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("We have been disconnected.\n");
- break;
- case ID_CONNECTION_LOST:
- if (isVerbose)
- printf("Connection lost.\n");
- break;
- default:
- break;
- }
- clientList[i]->DeallocatePacket(packet);
- // Stay in the loop as long as there are more packets.
- packet = clientList[i]->Receive();
- }
- }
- RakSleep(0);//If needed for testing
- }
- entryTime=GetTimeMS();
- while(GetTimeMS()-entryTime<2000)//Run for 2 Secoonds to process incoming disconnects
- {
- //Server receive
- packet=server->Receive();
- if (isVerbose&&packet)
- printf("For server\n");
- while(packet)
- {
- switch (packet->data[0])
- {
- case ID_REMOTE_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("Another client has disconnected.\n");
- break;
- case ID_REMOTE_CONNECTION_LOST:
- if (isVerbose)
- printf("Another client has lost the connection.\n");
- break;
- case ID_REMOTE_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("Another client has connected.\n");
- break;
- case ID_CONNECTION_REQUEST_ACCEPTED:
- if (isVerbose)
- printf("Our connection request has been accepted.\n");
- break;
- case ID_CONNECTION_ATTEMPT_FAILED:
- if (isVerbose)
- printf("A connection has failed.\n");
- break;
- case ID_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("A connection is incoming.\n");
- break;
- case ID_NO_FREE_INCOMING_CONNECTIONS:
- if (isVerbose)
- printf("The server is full.\n");
- break;
- case ID_ALREADY_CONNECTED:
- if (isVerbose)
- printf("Already connected\n");
- break;
- case ID_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("We have been disconnected.\n");
- break;
- case ID_CONNECTION_LOST:
- if (isVerbose)
- printf("Connection lost.\n");
- break;
- default:
- break;
- }
- server->DeallocatePacket(packet);
- // Stay in the loop as long as there are more packets.
- packet = server->Receive();
- }
- for (int i=0;i<clientNum;i++)//Receive for all peers
- {
- packet=clientList[i]->Receive();
- if (isVerbose&&packet)
- printf("For peer %i\n",i);
- while(packet)
- {
- switch (packet->data[0])
- {
- case ID_REMOTE_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("Another client has disconnected.\n");
- break;
- case ID_REMOTE_CONNECTION_LOST:
- if (isVerbose)
- printf("Another client has lost the connection.\n");
- break;
- case ID_REMOTE_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("Another client has connected.\n");
- break;
- case ID_CONNECTION_REQUEST_ACCEPTED:
- if (isVerbose)
- printf("Our connection request has been accepted.\n");
- break;
- case ID_CONNECTION_ATTEMPT_FAILED:
- if (isVerbose)
- printf("A connection has failed.\n");
- break;
- case ID_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("A connection is incoming.\n");
- break;
- case ID_NO_FREE_INCOMING_CONNECTIONS:
- if (isVerbose)
- printf("The server is full.\n");
- break;
- case ID_ALREADY_CONNECTED:
- if (isVerbose)
- printf("Already connected\n");
- break;
- case ID_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("We have been disconnected.\n");
- break;
- case ID_CONNECTION_LOST:
- if (isVerbose)
- printf("Connection lost.\n");
- break;
- default:
- break;
- }
- clientList[i]->DeallocatePacket(packet);
- // Stay in the loop as long as there are more packets.
- packet = clientList[i]->Receive();
- }
- }
- RakSleep(0);//If needed for testing
- }
- //Connect
- for (int i=0;i<clientNum;i++)
- {
- currentSystem.SetBinaryAddress("127.0.0.1");
- currentSystem.port=60000;
- if(!CommonFunctions::ConnectionStateMatchesOptions (clientList[i],currentSystem,true,true,true,true) )//Are we connected or is there a pending operation ?
- {
- if (clientList[i]->Connect("127.0.0.1", 60000, 0,0)!=CONNECTION_ATTEMPT_STARTED)
- {
- clientList[i]->GetSystemList(systemList,guidList);//Get connectionlist
- int len=systemList.Size();
- if (isVerbose)
- DebugTools::ShowError("Problem while calling connect. \n",!noPauses && isVerbose,__LINE__,__FILE__);
- return 1;//This fails the test, don't bother going on.
- }
- }
- }
- entryTime=GetTimeMS();
- while(GetTimeMS()-entryTime<5000)//Run for 5 Secoonds
- {
- //Server receive
- packet=server->Receive();
- if (isVerbose&&packet)
- printf("For server\n");
- while(packet)
- {
- switch (packet->data[0])
- {
- case ID_REMOTE_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("Another client has disconnected.\n");
- break;
- case ID_REMOTE_CONNECTION_LOST:
- if (isVerbose)
- printf("Another client has lost the connection.\n");
- break;
- case ID_REMOTE_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("Another client has connected.\n");
- break;
- case ID_CONNECTION_REQUEST_ACCEPTED:
- if (isVerbose)
- printf("Our connection request has been accepted.\n");
- break;
- case ID_CONNECTION_ATTEMPT_FAILED:
- if (isVerbose)
- printf("A connection has failed.\n");
- break;
- case ID_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("A connection is incoming.\n");
- break;
- case ID_NO_FREE_INCOMING_CONNECTIONS:
- if (isVerbose)
- printf("The server is full.\n");
- break;
- case ID_ALREADY_CONNECTED:
- if (isVerbose)
- printf("Already connected\n");
- break;
- case ID_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("We have been disconnected.\n");
- break;
- case ID_CONNECTION_LOST:
- if (isVerbose)
- printf("Connection lost.\n");
- break;
- default:
- break;
- }
- server->DeallocatePacket(packet);
- // Stay in the loop as long as there are more packets.
- packet = server->Receive();
- }
- for (int i=0;i<clientNum;i++)//Receive for all clients
- {
- packet=clientList[i]->Receive();
- if (isVerbose&&packet)
- printf("For peer %i\n",i);
- while(packet)
- {
- switch (packet->data[0])
- {
- case ID_REMOTE_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("Another client has disconnected.\n");
- break;
- case ID_REMOTE_CONNECTION_LOST:
- if (isVerbose)
- printf("Another client has lost the connection.\n");
- break;
- case ID_REMOTE_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("Another client has connected.\n");
- break;
- case ID_CONNECTION_REQUEST_ACCEPTED:
- if (isVerbose)
- printf("Our connection request has been accepted.\n");
- break;
- case ID_CONNECTION_ATTEMPT_FAILED:
- if (isVerbose)
- printf("A connection has failed.\n");
- break;
- case ID_NEW_INCOMING_CONNECTION:
- if (isVerbose)
- printf("A connection is incoming.\n");
- break;
- case ID_NO_FREE_INCOMING_CONNECTIONS:
- if (isVerbose)
- printf("The server is full.\n");
- break;
- case ID_ALREADY_CONNECTED:
- if (isVerbose)
- printf("Already connected\n");
- break;
- case ID_DISCONNECTION_NOTIFICATION:
- if (isVerbose)
- printf("We have been disconnected.\n");
- break;
- case ID_CONNECTION_LOST:
- if (isVerbose)
- printf("Connection lost.\n");
- break;
- default:
- break;
- }
- clientList[i]->DeallocatePacket(packet);
- // Stay in the loop as long as there are more packets.
- packet = clientList[i]->Receive();
- }
- }
- RakSleep(0);//If needed for testing
- }
- for (int i=0;i<clientNum;i++)
- {
- clientList[i]->GetSystemList(systemList,guidList);
- int connNum=guidList.Size();//Get the number of connections for the current peer
- if (connNum!=1)//Did we connect to all?
- {
- if (isVerbose)
- printf("Not all clients reconnected normally.\nFailed on clients number %i\n",i);
- if (isVerbose)
- DebugTools::ShowError("",!noPauses && isVerbose,__LINE__,__FILE__);
-
-
- return 2;
- }
- }
-
- if (isVerbose)
- printf("Pass\n");
- return 0;
- }
- RakString ManyClientsOneServerNonBlockingTest::GetTestName()
- {
- return "ManyClientsOneServerNonBlockingTest";
- }
- RakString ManyClientsOneServerNonBlockingTest::ErrorCodeToString(int errorCode)
- {
- switch (errorCode)
- {
- case 0:
- return "No error";
- break;
- case 1:
- return "The connect function failed.";
- break;
- case 2:
- return "Peers did not connect normally.";
- break;
- default:
- return "Undefined Error";
- }
- }
- ManyClientsOneServerNonBlockingTest::ManyClientsOneServerNonBlockingTest(void)
- {
- }
- ManyClientsOneServerNonBlockingTest::~ManyClientsOneServerNonBlockingTest(void)
- {
- }
- void ManyClientsOneServerNonBlockingTest::DestroyPeers()
- {
- int theSize=destroyList.Size();
- for (int i=0; i < theSize; i++)
- RakPeerInterface::DestroyInstance(destroyList[i]);
- }
|