TEST(ThriftServer, IdleTimeoutAfterTest) { ScopedServerThread sst(getServer()); TEventBase base; std::shared_ptr<TAsyncSocket> socket( TAsyncSocket::newSocket(&base, *sst.getAddress())); auto client_channel = HeaderClientChannel::newChannel(socket); auto client_channelp = client_channel.get(); CloseChecker checker; client_channel->setCloseCallback(&checker); TestServiceAsyncClient client(std::move(client_channel)); std::string ret; client.sync_sendResponse(ret, 20); EXPECT_FALSE(checker.getClosed()); base.tryRunAfterDelay([&base](){ base.terminateLoopSoon(); }, 200); base.loopForever(); EXPECT_TRUE(checker.getClosed()); client_channelp->setCloseCallback(nullptr); }
TEST(ThriftServer, NoIdleTimeoutWhileWorkingTest) { TEventBase base; auto port = Server::get(getServer)->getAddress().getPort(); std::shared_ptr<TAsyncSocket> socket( TAsyncSocket::newSocket(&base, "127.0.0.1", port)); auto client_channel = HeaderClientChannel::newChannel(socket); CloseChecker checker; client_channel->setCloseCallback(&checker); TestServiceAsyncClient client(std::move(client_channel)); client.sync_noResponse(20); EXPECT_FALSE(checker.getClosed()); }
TEST(ThriftServer, IdleTimeoutTest) { TEventBase base; auto port = Server::get(getServer)->getAddress().getPort(); std::shared_ptr<TAsyncSocket> socket( TAsyncSocket::newSocket(&base, "127.0.0.1", port)); auto client_channel = HeaderClientChannel::newChannel(socket); CloseChecker checker; client_channel->setCloseCallback(&checker); base.runAfterDelay([&base](){ base.terminateLoopSoon(); }, 100); base.loopForever(); EXPECT_TRUE(checker.getClosed()); }
TEST(ThriftServer, IdleTimeoutTest) { ScopedServerThread sst(getServer()); TEventBase base; std::shared_ptr<TAsyncSocket> socket( TAsyncSocket::newSocket(&base, *sst.getAddress())); auto client_channel = HeaderClientChannel::newChannel(socket); CloseChecker checker; client_channel->setCloseCallback(&checker); base.tryRunAfterDelay([&base](){ base.terminateLoopSoon(); }, 100); base.loopForever(); EXPECT_TRUE(checker.getClosed()); client_channel->setCloseCallback(nullptr); }
TEST(ThriftServer, NoIdleTimeoutWhileWorkingTest) { ScopedServerThread sst(getServer()); TEventBase base; std::shared_ptr<TAsyncSocket> socket( TAsyncSocket::newSocket(&base, *sst.getAddress())); auto client_channel = HeaderClientChannel::newChannel(socket); auto client_channelp = client_channel.get(); CloseChecker checker; client_channel->setCloseCallback(&checker); TestServiceAsyncClient client(std::move(client_channel)); std::string ret; client.sync_sendResponse(ret, 20); client.sync_sendResponse(ret, 20); EXPECT_FALSE(checker.getClosed()); client_channelp->setCloseCallback(nullptr); }