123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
-
- #include "hello_test.h"
- #include "../server/WinServer.h"
- TEST_F(HelloTest, winServerInCoroutine)
- {
- funcInCoroutine([&]()
- {
- auto comm = getCommunicator();
- WinServer ws;
- startServer(ws, WIN_CONFIG());
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = comm->stringToProxy<HelloPrx>(obj);
- string out;
- prx->testHello(0, _buffer, out);
- ASSERT_TRUE(_buffer == out);
- stopServer(ws);
- },
- true);
- }
- TEST_F(HelloTest, winServerGlobalInCoroutine)
- {
- auto comm = getCommunicator();
- WinServer ws;
- startServer(ws, WIN_CONFIG());
- string obj = getObj(ws.getConfig(), "WinAdapter");
- {
- std::thread cor_call([&]()
- {
- auto scheduler = TC_CoroutineScheduler::create();
- //设置到协程中
- ServantProxyThreadData::getData()->_sched = scheduler;
- scheduler->go([&]()
- {
- scheduler->setNoCoroutineCallback([=](TC_CoroutineScheduler* s)
- {
- s->terminate();
- });
- HelloPrx prx = comm->stringToProxy<HelloPrx>(obj);
- string out;
- prx->testHello(0, _buffer, out);
- ASSERT_TRUE(_buffer == out);
- });
- scheduler->run();
- });
- cor_call.join();
- }
- stopServer(ws);
- }
- TEST_F(HelloTest, winServer)
- {
- shared_ptr<Communicator> c = getCommunicator();
- WinServer ws;
- startServer(ws, WIN_CONFIG(), (TC_EpollServer::SERVER_OPEN_COROUTINE)0);
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = c->stringToProxy<HelloPrx>(obj);
- string out;
- prx->testHello(0, _buffer, out);
- stopServer(ws);
- }
- TEST_F(HelloTest, winServerAsync)
- {
- shared_ptr<Communicator> c = getCommunicator();
- for(int i = 0; i <= TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO; i++)
- {
- WinServer ws;
- startServer(ws, WIN_CONFIG(), (TC_EpollServer::SERVER_OPEN_COROUTINE)i);
- atomic<int> callback_count{ 0 };
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = c->stringToProxy<HelloPrx>(obj);
- //发起远程调用
- for (int j = 0; j < _count; ++j)
- {
- HelloPrxCallbackPtr p = new ClientHelloCallback(TC_Common::now2us(), j, _count, _buffer,
- callback_count);
- prx->async_testHello(p, j, _buffer);
- }
- waitForFinish(callback_count, _count);
- ASSERT_TRUE(callback_count == _count);
- stopServer(ws);
- }
- }
- TEST_F(HelloTest, winServerHandleDestroy)
- {
- int i = 1;//TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO;
- for(i = 0; i <= TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO; i++)
- {
- g_handleDestroy = 0;
- WinServer ws;
- startServer(ws, WIN_CONFIG(), (TC_EpollServer::SERVER_OPEN_COROUTINE) i);
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = ws.getCommunicator()->stringToProxy<HelloPrx>(obj);
- string out;
- prx->testHello(0, _buffer, out);
- ASSERT_TRUE(_buffer == out);
- stopServer(ws);
- ASSERT_TRUE(g_handleDestroy == TC_Common::strto<int>(ws.getConfig().get("/tars/application/server/WinAdapter<threads>")));
- }
- }
- TEST_F(HelloTest, winServerFdLeak)
- {
- int i = 0;
- //先跑一边, 把需要分配的句柄都分配完
- for (i = 0; i <= TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO; i++)
- {
- WinServer ws;
- startServer(ws, WIN_CONFIG(), (TC_EpollServer::SERVER_OPEN_COROUTINE)i);
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = ws.getCommunicator()->stringToProxy<HelloPrx>(obj);
- string out;
- //网络通信器有多个, 就要调用多次
- prx->testHello(0, _buffer, out);
- ASSERT_TRUE(_buffer == out);
- prx->testHello(0, _buffer, out);
- ASSERT_TRUE(_buffer == out);
- stopServer(ws);
- }
- //第二遍检查句柄是否泄漏
- for (i = 0; i <= TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO; i++)
- {
- int ofdCount = getFdCounts();
- {
- WinServer ws;
- startServer(ws, WIN_CONFIG(), (TC_EpollServer::SERVER_OPEN_COROUTINE)i);
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = ws.getCommunicator()->stringToProxy<HelloPrx>(obj);
- string out;
- //网络通信器有多个, 就要调用多次
- prx->testHello(0, _buffer, out);
- ASSERT_TRUE(_buffer == out);
- prx->testHello(0, _buffer, out);
- ASSERT_TRUE(_buffer == out);
- stopServer(ws);
- }
- // TC_Common::sleep(1000);
- int nfdCount = getFdCounts();
- //linux下才有效
- LOG_CONSOLE_DEBUG << "old fd count:" << ofdCount << ", new fd count:" << nfdCount << endl;
- // ASSERT_TRUE(ofdCount == nfdCount);
- }
- }
- TEST_F(HelloTest, winServerRestart)
- {
- int i = 0;//TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO;
- for(i = 0; i <= TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO; i++)
- {
- WinServer ws;
- int count = 10;
- while(count-->0)
- {
- startServer(ws, WIN_CONFIG(), (TC_EpollServer::SERVER_OPEN_COROUTINE)i);
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = ws.getCommunicator()->stringToProxy<HelloPrx>(obj);
- string out;
- prx->testHello(0, _buffer, out);
- ASSERT_TRUE(_buffer == out);
- stopServer(ws);
- }
- }
- }
- TEST_F(HelloTest, winLog)
- {
- WinServer ws;
- startServer(ws, WIN_CONFIG());
- string log1 = ServerConfig::Application + FILE_SEP + ServerConfig::ServerName + FILE_SEP + ServerConfig::Application + "." + ServerConfig::ServerName + ".test1.log";
- string log2 = ServerConfig::Application + FILE_SEP + ServerConfig::ServerName + FILE_SEP + ServerConfig::Application + "." + ServerConfig::ServerName + ".test2.log";
- TC_File::removeFile(log1, false);
- TC_File::removeFile(log2, false);
- ASSERT_TRUE(!TC_File::isFileExist(log1));
- ASSERT_TRUE(!TC_File::isFileExist(log2));
- TLOGEXDEBUG("test1", "test log"<< endl);
- TLOGEXDEBUG("test2", "test log"<< endl);
- LOG_CONSOLE_DEBUG << log1 << endl;
-
- ASSERT_TRUE(TC_File::isFileExist(log1));
- ASSERT_TRUE(TC_File::isFileExist(log2));
- stopServer(ws);
- }
- TEST_F(HelloTest, winServerCo)
- {
- {
- WinServer ws;
- startServer(ws, WIN_CONFIG(), TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD);
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = ws.getCommunicator()->stringToProxy<HelloPrx>(obj);
- string out;
- bool co = prx->testCoro(_buffer, out);
- EXPECT_FALSE(co);
- stopServer(ws);
- }
- {
- WinServer ws;
- startServer(ws, WIN_CONFIG(), TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO);
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = ws.getCommunicator()->stringToProxy<HelloPrx>(obj);
- string out;
- bool co = prx->testCoro(_buffer, out);
- EXPECT_TRUE(co);
- stopServer(ws);
- }
- {
- WinServer ws;
- startServer(ws, WIN_CONFIG(), TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD);
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = ws.getCommunicator()->stringToProxy<HelloPrx>(obj);
- string out;
- bool co = prx->testCoro(_buffer, out);
- EXPECT_FALSE(co);
- stopServer(ws);
- }
- {
- WinServer ws;
- startServer(ws, WIN_CONFIG(), TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO);
- string obj = getObj(ws.getConfig(), "WinAdapter");
- HelloPrx prx = ws.getCommunicator()->stringToProxy<HelloPrx>(obj);
- string out;
- bool co = prx->testCoro(_buffer, out);
- EXPECT_TRUE(co);
- stopServer(ws);
- }
- }
- TEST_F(HelloTest, winServerHashTag)
- {
- WinServer ws;
- startServer(ws, WIN_CONFIG(), TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD);
- string obj = getObj(ws.getConfig(), "WinAdapter");
- size_t pos = obj.find_first_of("@");
- if(pos != string::npos) {
- obj = obj.substr(0, pos) + "#9999" + obj.substr(pos);
- }else{
- obj += "#9999";
- }
- HelloPrx prx = ws.getCommunicator()->stringToProxy<HelloPrx>(obj);
- string out;
- bool co = prx->testCoro(_buffer, out);
- EXPECT_FALSE(co);
- stopServer(ws);
- }
|