Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | #define BOOST_TEST_MODULE TServerIntegrationTest |
cyy | 7f8aef7 | 2019-01-06 10:05:50 +0800 | [diff] [blame^] | 21 | #include <atomic> |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 22 | #include <boost/test/auto_unit_test.hpp> |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 23 | #include <boost/date_time/posix_time/ptime.hpp> |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 24 | #include <boost/foreach.hpp> |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 25 | #include <boost/format.hpp> |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 26 | #include <boost/thread.hpp> |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 27 | #include <thrift/server/TSimpleServer.h> |
| 28 | #include <thrift/server/TThreadPoolServer.h> |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 29 | #include <thrift/server/TThreadedServer.h> |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 30 | #include <memory> |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 31 | #include <thrift/protocol/TBinaryProtocol.h> |
| 32 | #include <thrift/transport/TServerSocket.h> |
| 33 | #include <thrift/transport/TSocket.h> |
| 34 | #include <thrift/transport/TTransport.h> |
| 35 | #include "gen-cpp/ParentService.h" |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 36 | #include <string> |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 37 | #include <vector> |
| 38 | |
| 39 | using apache::thrift::concurrency::Guard; |
| 40 | using apache::thrift::concurrency::Monitor; |
| 41 | using apache::thrift::concurrency::Mutex; |
| 42 | using apache::thrift::concurrency::Synchronized; |
| 43 | using apache::thrift::protocol::TBinaryProtocol; |
| 44 | using apache::thrift::protocol::TBinaryProtocolFactory; |
| 45 | using apache::thrift::protocol::TProtocol; |
| 46 | using apache::thrift::protocol::TProtocolFactory; |
| 47 | using apache::thrift::transport::TServerSocket; |
| 48 | using apache::thrift::transport::TServerTransport; |
| 49 | using apache::thrift::transport::TSocket; |
| 50 | using apache::thrift::transport::TTransport; |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 51 | using apache::thrift::transport::TTransportException; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 52 | using apache::thrift::transport::TTransportFactory; |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 53 | using apache::thrift::server::TServer; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 54 | using apache::thrift::server::TServerEventHandler; |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 55 | using apache::thrift::server::TSimpleServer; |
| 56 | using apache::thrift::server::TThreadPoolServer; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 57 | using apache::thrift::server::TThreadedServer; |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 58 | using std::dynamic_pointer_cast; |
| 59 | using std::make_shared; |
| 60 | using std::shared_ptr; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 61 | using apache::thrift::test::ParentServiceClient; |
| 62 | using apache::thrift::test::ParentServiceIf; |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 63 | using apache::thrift::test::ParentServiceIfFactory; |
| 64 | using apache::thrift::test::ParentServiceIfSingletonFactory; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 65 | using apache::thrift::test::ParentServiceProcessor; |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 66 | using apache::thrift::test::ParentServiceProcessorFactory; |
| 67 | using apache::thrift::TProcessor; |
| 68 | using apache::thrift::TProcessorFactory; |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 69 | using boost::posix_time::milliseconds; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * preServe runs after listen() is successful, when we can connect |
| 73 | */ |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 74 | class TServerReadyEventHandler : public TServerEventHandler, public Monitor { |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 75 | public: |
| 76 | TServerReadyEventHandler() : isListening_(false), accepted_(0) {} |
| 77 | virtual ~TServerReadyEventHandler() {} |
| 78 | virtual void preServe() { |
| 79 | Synchronized sync(*this); |
| 80 | isListening_ = true; |
| 81 | notify(); |
| 82 | } |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 83 | virtual void* createContext(shared_ptr<TProtocol> input, |
| 84 | shared_ptr<TProtocol> output) { |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 85 | Synchronized sync(*this); |
| 86 | ++accepted_; |
| 87 | notify(); |
| 88 | |
| 89 | (void)input; |
| 90 | (void)output; |
| 91 | return NULL; |
| 92 | } |
| 93 | bool isListening() const { return isListening_; } |
| 94 | uint64_t acceptedCount() const { return accepted_; } |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 95 | |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 96 | private: |
| 97 | bool isListening_; |
| 98 | uint64_t accepted_; |
| 99 | }; |
| 100 | |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 101 | /** |
| 102 | * Reusing another generated test, just something to serve up |
| 103 | */ |
| 104 | class ParentHandler : public ParentServiceIf { |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 105 | public: |
| 106 | ParentHandler() : generation_(0) {} |
| 107 | |
| 108 | int32_t incrementGeneration() { |
| 109 | Guard g(mutex_); |
| 110 | return ++generation_; |
| 111 | } |
| 112 | |
| 113 | int32_t getGeneration() { |
| 114 | Guard g(mutex_); |
| 115 | return generation_; |
| 116 | } |
| 117 | |
| 118 | void addString(const std::string& s) { |
| 119 | Guard g(mutex_); |
| 120 | strings_.push_back(s); |
| 121 | } |
| 122 | |
| 123 | void getStrings(std::vector<std::string>& _return) { |
| 124 | Guard g(mutex_); |
| 125 | _return = strings_; |
| 126 | } |
| 127 | |
ben-craig | fae08e7 | 2015-07-15 11:34:47 -0500 | [diff] [blame] | 128 | void getDataWait(std::string& _return, const int32_t length) { |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 129 | THRIFT_UNUSED_VARIABLE(_return); |
| 130 | THRIFT_UNUSED_VARIABLE(length); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 131 | } |
| 132 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 133 | void onewayWait() {} |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 134 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 135 | void exceptionWait(const std::string& message) { THRIFT_UNUSED_VARIABLE(message); } |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 136 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 137 | void unexpectedExceptionWait(const std::string& message) { THRIFT_UNUSED_VARIABLE(message); } |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 138 | |
| 139 | protected: |
| 140 | Mutex mutex_; |
| 141 | int32_t generation_; |
| 142 | std::vector<std::string> strings_; |
| 143 | }; |
| 144 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 145 | void autoSocketCloser(TSocket* pSock) { |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 146 | pSock->close(); |
| 147 | delete pSock; |
| 148 | } |
| 149 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 150 | template <class TServerType> |
John Sirois | 919752c | 2016-02-13 12:35:58 -0700 | [diff] [blame] | 151 | class TServerIntegrationTestFixture { |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 152 | public: |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 153 | TServerIntegrationTestFixture(const shared_ptr<TProcessorFactory>& _processorFactory) |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 154 | : pServer(new TServerType(_processorFactory, |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 155 | shared_ptr<TServerTransport>( |
John Sirois | 919752c | 2016-02-13 12:35:58 -0700 | [diff] [blame] | 156 | new TServerSocket("localhost", 0)), |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 157 | shared_ptr<TTransportFactory>(new TTransportFactory), |
| 158 | shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))), |
| 159 | pEventHandler(shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)), |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 160 | bStressDone(false), |
| 161 | bStressConnectionCount(0), |
| 162 | bStressRequestCount(0) { |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 163 | pServer->setServerEventHandler(pEventHandler); |
| 164 | } |
| 165 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 166 | TServerIntegrationTestFixture(const shared_ptr<TProcessor>& _processor) |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 167 | : pServer( |
| 168 | new TServerType(_processor, |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 169 | shared_ptr<TServerTransport>(new TServerSocket("localhost", 0)), |
| 170 | shared_ptr<TTransportFactory>(new TTransportFactory), |
| 171 | shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))), |
| 172 | pEventHandler(shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)), |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 173 | bStressDone(false), |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 174 | bStressConnectionCount(0), |
| 175 | bStressRequestCount(0) { |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 176 | pServer->setServerEventHandler(pEventHandler); |
| 177 | } |
| 178 | |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 179 | void startServer() { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 180 | pServerThread.reset(new boost::thread(std::bind(&TServerType::serve, pServer.get()))); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 181 | |
| 182 | // block until listen() completes so clients will be able to connect |
| 183 | Synchronized sync(*(pEventHandler.get())); |
| 184 | while (!pEventHandler->isListening()) { |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 185 | pEventHandler->wait(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 186 | } |
| 187 | |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 188 | BOOST_TEST_MESSAGE(" server is listening"); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | void blockUntilAccepted(uint64_t numAccepted) { |
| 192 | Synchronized sync(*(pEventHandler.get())); |
| 193 | while (pEventHandler->acceptedCount() < numAccepted) { |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 194 | pEventHandler->wait(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 195 | } |
| 196 | |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 197 | BOOST_TEST_MESSAGE(boost::format(" server has accepted %1%") % numAccepted); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void stopServer() { |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 201 | if (pServerThread) { |
| 202 | pServer->stop(); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 203 | BOOST_TEST_MESSAGE(" server stop completed"); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 204 | |
| 205 | pServerThread->join(); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 206 | BOOST_TEST_MESSAGE(" server thread joined"); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 207 | pServerThread.reset(); |
| 208 | } |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 209 | } |
| 210 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 211 | ~TServerIntegrationTestFixture() { stopServer(); } |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 212 | |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 213 | /** |
| 214 | * Performs a baseline test where some clients are opened and issue a single operation |
| 215 | * and then disconnect at different intervals. |
| 216 | * \param[in] numToMake the number of concurrent clients |
| 217 | * \param[in] expectedHWM the high water mark we expect of concurrency |
| 218 | * \param[in] purpose a description of the test for logging purposes |
| 219 | */ |
| 220 | void baseline(int64_t numToMake, int64_t expectedHWM, const std::string& purpose) { |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 221 | BOOST_TEST_MESSAGE(boost::format("Testing %1%: %2% with %3% clients, expect %4% HWM") |
| 222 | % typeid(TServerType).name() % purpose % numToMake % expectedHWM); |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 223 | |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 224 | startServer(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 225 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 226 | std::vector<shared_ptr<TSocket> > holdSockets; |
| 227 | std::vector<shared_ptr<boost::thread> > holdThreads; |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 228 | |
| 229 | for (int64_t i = 0; i < numToMake; ++i) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 230 | shared_ptr<TSocket> pClientSock(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 231 | autoSocketCloser); |
| 232 | holdSockets.push_back(pClientSock); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 233 | shared_ptr<TProtocol> pClientProtocol(new TBinaryProtocol(pClientSock)); |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 234 | ParentServiceClient client(pClientProtocol); |
| 235 | pClientSock->open(); |
| 236 | client.incrementGeneration(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 237 | holdThreads.push_back(shared_ptr<boost::thread>( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 238 | new boost::thread(std::bind(&TServerIntegrationTestFixture::delayClose, |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 239 | this, |
| 240 | pClientSock, |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 241 | milliseconds(10 * numToMake))))); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | BOOST_CHECK_EQUAL(expectedHWM, pServer->getConcurrentClientCountHWM()); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 245 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 246 | BOOST_FOREACH (shared_ptr<boost::thread> pThread, holdThreads) { pThread->join(); } |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 247 | holdThreads.clear(); |
| 248 | holdSockets.clear(); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 249 | |
| 250 | stopServer(); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Helper method used to close a connection after a delay. |
| 255 | * \param[in] toClose the connection to close |
| 256 | * \param[in] after the delay to impose |
| 257 | */ |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 258 | void delayClose(shared_ptr<TTransport> toClose, boost::posix_time::time_duration after) { |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 259 | boost::this_thread::sleep(after); |
| 260 | toClose->close(); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * \returns the server port number |
| 265 | */ |
| 266 | int getServerPort() { |
| 267 | TServerSocket* pSock = dynamic_cast<TServerSocket*>(pServer->getServerTransport().get()); |
James E. King, III | 533405e | 2017-10-28 18:25:45 -0400 | [diff] [blame] | 268 | if (!pSock) { throw std::logic_error("how come?"); } |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 269 | return pSock->getPort(); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Performs a stress test by spawning threads that connect, do a number of operations |
| 274 | * and disconnect, then a random delay, then do it over again. This is done for a fixed |
| 275 | * period of time to test for concurrency correctness. |
| 276 | * \param[in] numToMake the number of concurrent clients |
| 277 | */ |
| 278 | void stress(int64_t numToMake, const boost::posix_time::time_duration& duration) { |
| 279 | BOOST_TEST_MESSAGE(boost::format("Stress testing %1% with %2% clients for %3% seconds") |
| 280 | % typeid(TServerType).name() % numToMake % duration.total_seconds()); |
| 281 | |
| 282 | startServer(); |
| 283 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 284 | std::vector<shared_ptr<boost::thread> > holdThreads; |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 285 | for (int64_t i = 0; i < numToMake; ++i) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 286 | holdThreads.push_back(shared_ptr<boost::thread>( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 287 | new boost::thread(std::bind(&TServerIntegrationTestFixture::stressor, this)))); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | boost::this_thread::sleep(duration); |
| 291 | bStressDone = true; |
| 292 | |
| 293 | BOOST_TEST_MESSAGE(boost::format(" serviced %1% connections (HWM %2%) totaling %3% requests") |
| 294 | % bStressConnectionCount % pServer->getConcurrentClientCountHWM() % bStressRequestCount); |
| 295 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 296 | BOOST_FOREACH (shared_ptr<boost::thread> pThread, holdThreads) { pThread->join(); } |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 297 | holdThreads.clear(); |
| 298 | |
| 299 | BOOST_CHECK(bStressRequestCount > 0); |
| 300 | |
| 301 | stopServer(); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Helper method to stress the system |
| 306 | */ |
| 307 | void stressor() { |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 308 | while (!bStressDone) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 309 | shared_ptr<TSocket> pSocket(new TSocket("localhost", getServerPort()), autoSocketCloser); |
| 310 | shared_ptr<TProtocol> pProtocol(new TBinaryProtocol(pSocket)); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 311 | ParentServiceClient client(pProtocol); |
| 312 | pSocket->open(); |
cyy | 7f8aef7 | 2019-01-06 10:05:50 +0800 | [diff] [blame^] | 313 | bStressConnectionCount.fetch_add(1, std::memory_order_relaxed); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 314 | for (int i = 0; i < rand() % 1000; ++i) { |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 315 | client.incrementGeneration(); |
cyy | 7f8aef7 | 2019-01-06 10:05:50 +0800 | [diff] [blame^] | 316 | bStressRequestCount.fetch_add(1, std::memory_order_relaxed); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 317 | } |
| 318 | } |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 319 | } |
| 320 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 321 | shared_ptr<TServerType> pServer; |
| 322 | shared_ptr<TServerReadyEventHandler> pEventHandler; |
| 323 | shared_ptr<boost::thread> pServerThread; |
cyy | 7f8aef7 | 2019-01-06 10:05:50 +0800 | [diff] [blame^] | 324 | std::atomic<bool> bStressDone; |
| 325 | std::atomic<int64_t> bStressConnectionCount; |
| 326 | std::atomic<int64_t> bStressRequestCount; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 327 | }; |
| 328 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 329 | template <class TServerType> |
| 330 | class TServerIntegrationProcessorFactoryTestFixture |
| 331 | : public TServerIntegrationTestFixture<TServerType> { |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 332 | public: |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 333 | TServerIntegrationProcessorFactoryTestFixture() |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 334 | : TServerIntegrationTestFixture<TServerType>(make_shared<ParentServiceProcessorFactory>( |
| 335 | make_shared<ParentServiceIfSingletonFactory>( |
| 336 | make_shared<ParentHandler>()))) {} |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 337 | }; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 338 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 339 | template <class TServerType> |
| 340 | class TServerIntegrationProcessorTestFixture : public TServerIntegrationTestFixture<TServerType> { |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 341 | public: |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 342 | TServerIntegrationProcessorTestFixture() |
| 343 | : TServerIntegrationTestFixture<TServerType>( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 344 | make_shared<ParentServiceProcessor>(make_shared<ParentHandler>())) {} |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | BOOST_AUTO_TEST_SUITE(constructors) |
| 348 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 349 | BOOST_FIXTURE_TEST_CASE(test_simple_factory, |
| 350 | TServerIntegrationProcessorFactoryTestFixture<TSimpleServer>) { |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 351 | baseline(3, 1, "factory"); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 352 | } |
| 353 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 354 | BOOST_FIXTURE_TEST_CASE(test_simple, TServerIntegrationProcessorTestFixture<TSimpleServer>) { |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 355 | baseline(3, 1, "processor"); |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 356 | } |
| 357 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 358 | BOOST_FIXTURE_TEST_CASE(test_threaded_factory, |
| 359 | TServerIntegrationProcessorFactoryTestFixture<TThreadedServer>) { |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 360 | baseline(10, 10, "factory"); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 361 | } |
| 362 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 363 | BOOST_FIXTURE_TEST_CASE(test_threaded, TServerIntegrationProcessorTestFixture<TThreadedServer>) { |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 364 | baseline(10, 10, "processor"); |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 365 | } |
| 366 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 367 | BOOST_FIXTURE_TEST_CASE(test_threaded_bound, |
| 368 | TServerIntegrationProcessorTestFixture<TThreadedServer>) { |
| 369 | pServer->setConcurrentClientLimit(4); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 370 | baseline(10, 4, "limit by server framework"); |
| 371 | } |
| 372 | |
| 373 | BOOST_FIXTURE_TEST_CASE(test_threaded_stress, |
| 374 | TServerIntegrationProcessorFactoryTestFixture<TThreadedServer>) { |
| 375 | stress(10, boost::posix_time::seconds(3)); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 376 | } |
| 377 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 378 | BOOST_FIXTURE_TEST_CASE(test_threadpool_factory, |
| 379 | TServerIntegrationProcessorFactoryTestFixture<TThreadPoolServer>) { |
| 380 | pServer->getThreadManager()->threadFactory( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 381 | shared_ptr<apache::thrift::concurrency::ThreadFactory>( |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 382 | new apache::thrift::concurrency::PlatformThreadFactory)); |
| 383 | pServer->getThreadManager()->start(); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 384 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 385 | // thread factory has 4 threads as a default |
| 386 | // thread factory however is a bad way to limit concurrent clients |
| 387 | // as accept() will be called to grab a 5th client socket, in this case |
| 388 | // and then the thread factory will block adding the thread to manage |
| 389 | // that client. |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 390 | baseline(10, 5, "limit by thread manager"); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 391 | } |
| 392 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 393 | BOOST_FIXTURE_TEST_CASE(test_threadpool, |
| 394 | TServerIntegrationProcessorTestFixture<TThreadPoolServer>) { |
| 395 | pServer->getThreadManager()->threadFactory( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 396 | shared_ptr<apache::thrift::concurrency::ThreadFactory>( |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 397 | new apache::thrift::concurrency::PlatformThreadFactory)); |
| 398 | pServer->getThreadManager()->start(); |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 399 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 400 | // thread factory has 4 threads as a default |
| 401 | // thread factory however is a bad way to limit concurrent clients |
| 402 | // as accept() will be called to grab a 5th client socket, in this case |
| 403 | // and then the thread factory will block adding the thread to manage |
| 404 | // that client. |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 405 | baseline(10, 5, "limit by thread manager"); |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 408 | BOOST_FIXTURE_TEST_CASE(test_threadpool_bound, |
| 409 | TServerIntegrationProcessorTestFixture<TThreadPoolServer>) { |
| 410 | pServer->getThreadManager()->threadFactory( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 411 | shared_ptr<apache::thrift::concurrency::ThreadFactory>( |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 412 | new apache::thrift::concurrency::PlatformThreadFactory)); |
| 413 | pServer->getThreadManager()->start(); |
| 414 | pServer->setConcurrentClientLimit(4); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 415 | |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 416 | baseline(10, 4, "server framework connection limit"); |
| 417 | } |
| 418 | |
| 419 | BOOST_FIXTURE_TEST_CASE(test_threadpool_stress, |
| 420 | TServerIntegrationProcessorTestFixture<TThreadPoolServer>) { |
| 421 | pServer->getThreadManager()->threadFactory( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 422 | shared_ptr<apache::thrift::concurrency::ThreadFactory>( |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 423 | new apache::thrift::concurrency::PlatformThreadFactory)); |
| 424 | pServer->getThreadManager()->start(); |
| 425 | |
| 426 | stress(10, boost::posix_time::seconds(3)); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | BOOST_AUTO_TEST_SUITE_END() |
| 430 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 431 | BOOST_FIXTURE_TEST_SUITE(TServerIntegrationTest, |
| 432 | TServerIntegrationProcessorTestFixture<TThreadedServer>) |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 433 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 434 | BOOST_AUTO_TEST_CASE(test_stop_with_interruptable_clients_connected) { |
| 435 | // This tests THRIFT-2441 new behavior: stopping the server disconnects clients |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 436 | BOOST_TEST_MESSAGE("Testing stop with interruptable clients"); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 437 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 438 | startServer(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 439 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 440 | shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 441 | autoSocketCloser); |
| 442 | pClientSock1->open(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 443 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 444 | shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 445 | autoSocketCloser); |
| 446 | pClientSock2->open(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 447 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 448 | // Ensure they have been accepted |
| 449 | blockUntilAccepted(2); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 450 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 451 | // The test fixture destructor will force the sockets to disconnect |
| 452 | // Prior to THRIFT-2441, pServer->stop() would hang until clients disconnected |
| 453 | stopServer(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 454 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 455 | // extra proof the server end disconnected the clients |
| 456 | uint8_t buf[1]; |
| 457 | BOOST_CHECK_EQUAL(0, pClientSock1->read(&buf[0], 1)); // 0 = disconnected |
| 458 | BOOST_CHECK_EQUAL(0, pClientSock2->read(&buf[0], 1)); // 0 = disconnected |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 459 | } |
| 460 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 461 | BOOST_AUTO_TEST_CASE(test_stop_with_uninterruptable_clients_connected) { |
| 462 | // This tests pre-THRIFT-2441 behavior: stopping the server blocks until clients |
| 463 | // disconnect. |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 464 | BOOST_TEST_MESSAGE("Testing stop with uninterruptable clients"); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 465 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 466 | dynamic_pointer_cast<TServerSocket>(pServer->getServerTransport()) |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 467 | ->setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 468 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 469 | startServer(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 470 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 471 | shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 472 | autoSocketCloser); |
| 473 | pClientSock1->open(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 474 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 475 | shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 476 | autoSocketCloser); |
| 477 | pClientSock2->open(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 478 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 479 | // Ensure they have been accepted |
| 480 | blockUntilAccepted(2); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 481 | |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 482 | boost::thread t1(std::bind(&TServerIntegrationTestFixture::delayClose, |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 483 | this, |
| 484 | pClientSock1, |
| 485 | milliseconds(250))); |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 486 | boost::thread t2(std::bind(&TServerIntegrationTestFixture::delayClose, |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 487 | this, |
| 488 | pClientSock2, |
| 489 | milliseconds(250))); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 490 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 491 | // Once the clients disconnect the server will stop |
| 492 | stopServer(); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 493 | BOOST_CHECK(pServer->getConcurrentClientCountHWM() > 0); |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 494 | t1.join(); |
| 495 | t2.join(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 496 | } |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 497 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 498 | BOOST_AUTO_TEST_CASE(test_concurrent_client_limit) { |
| 499 | startServer(); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 500 | BOOST_TEST_MESSAGE("Testing the concurrent client limit"); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 501 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 502 | BOOST_CHECK_EQUAL(INT64_MAX, pServer->getConcurrentClientLimit()); |
| 503 | pServer->setConcurrentClientLimit(2); |
| 504 | BOOST_CHECK_EQUAL(0, pServer->getConcurrentClientCount()); |
| 505 | BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientLimit()); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 506 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 507 | shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 508 | autoSocketCloser); |
| 509 | pClientSock1->open(); |
| 510 | blockUntilAccepted(1); |
| 511 | BOOST_CHECK_EQUAL(1, pServer->getConcurrentClientCount()); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 512 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 513 | shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 514 | autoSocketCloser); |
| 515 | pClientSock2->open(); |
| 516 | blockUntilAccepted(2); |
| 517 | BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCount()); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 518 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 519 | // a third client cannot connect until one of the other two closes |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 520 | boost::thread t2(std::bind(&TServerIntegrationTestFixture::delayClose, |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 521 | this, |
| 522 | pClientSock2, |
| 523 | milliseconds(250))); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 524 | shared_ptr<TSocket> pClientSock3(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 525 | autoSocketCloser); |
| 526 | pClientSock2->open(); |
| 527 | blockUntilAccepted(2); |
| 528 | BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCount()); |
| 529 | BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCountHWM()); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 530 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 531 | stopServer(); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 532 | BOOST_CHECK(pServer->getConcurrentClientCountHWM() > 0); |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 533 | t2.join(); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 534 | } |
| 535 | |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 536 | BOOST_AUTO_TEST_SUITE_END() |