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 |
| 21 | #include <boost/test/auto_unit_test.hpp> |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 22 | #include <boost/atomic.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> |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 30 | #include <thrift/stdcxx.h> |
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; |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 58 | using apache::thrift::stdcxx::dynamic_pointer_cast; |
| 59 | using apache::thrift::stdcxx::make_shared; |
| 60 | using apache::thrift::stdcxx::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() { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 180 | pServerThread.reset(new boost::thread(apache::thrift::stdcxx::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>( |
| 238 | new boost::thread(apache::thrift::stdcxx::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()); |
| 268 | return pSock->getPort(); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Performs a stress test by spawning threads that connect, do a number of operations |
| 273 | * and disconnect, then a random delay, then do it over again. This is done for a fixed |
| 274 | * period of time to test for concurrency correctness. |
| 275 | * \param[in] numToMake the number of concurrent clients |
| 276 | */ |
| 277 | void stress(int64_t numToMake, const boost::posix_time::time_duration& duration) { |
| 278 | BOOST_TEST_MESSAGE(boost::format("Stress testing %1% with %2% clients for %3% seconds") |
| 279 | % typeid(TServerType).name() % numToMake % duration.total_seconds()); |
| 280 | |
| 281 | startServer(); |
| 282 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 283 | std::vector<shared_ptr<boost::thread> > holdThreads; |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 284 | for (int64_t i = 0; i < numToMake; ++i) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 285 | holdThreads.push_back(shared_ptr<boost::thread>( |
| 286 | new boost::thread(apache::thrift::stdcxx::bind(&TServerIntegrationTestFixture::stressor, this)))); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | boost::this_thread::sleep(duration); |
| 290 | bStressDone = true; |
| 291 | |
| 292 | BOOST_TEST_MESSAGE(boost::format(" serviced %1% connections (HWM %2%) totaling %3% requests") |
| 293 | % bStressConnectionCount % pServer->getConcurrentClientCountHWM() % bStressRequestCount); |
| 294 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 295 | BOOST_FOREACH (shared_ptr<boost::thread> pThread, holdThreads) { pThread->join(); } |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 296 | holdThreads.clear(); |
| 297 | |
| 298 | BOOST_CHECK(bStressRequestCount > 0); |
| 299 | |
| 300 | stopServer(); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Helper method to stress the system |
| 305 | */ |
| 306 | void stressor() { |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 307 | while (!bStressDone) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 308 | shared_ptr<TSocket> pSocket(new TSocket("localhost", getServerPort()), autoSocketCloser); |
| 309 | shared_ptr<TProtocol> pProtocol(new TBinaryProtocol(pSocket)); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 310 | ParentServiceClient client(pProtocol); |
| 311 | pSocket->open(); |
| 312 | bStressConnectionCount.fetch_add(1, boost::memory_order_relaxed); |
| 313 | for (int i = 0; i < rand() % 1000; ++i) { |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 314 | client.incrementGeneration(); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 315 | bStressRequestCount.fetch_add(1, boost::memory_order_relaxed); |
| 316 | } |
| 317 | } |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 318 | } |
| 319 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 320 | shared_ptr<TServerType> pServer; |
| 321 | shared_ptr<TServerReadyEventHandler> pEventHandler; |
| 322 | shared_ptr<boost::thread> pServerThread; |
James E. King, III | 237a394 | 2017-08-12 13:04:55 -0700 | [diff] [blame] | 323 | boost::atomic<bool> bStressDone; |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 324 | boost::atomic_int64_t bStressConnectionCount; |
| 325 | boost::atomic_int64_t bStressRequestCount; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 326 | }; |
| 327 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 328 | template <class TServerType> |
| 329 | class TServerIntegrationProcessorFactoryTestFixture |
| 330 | : public TServerIntegrationTestFixture<TServerType> { |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 331 | public: |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 332 | TServerIntegrationProcessorFactoryTestFixture() |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 333 | : TServerIntegrationTestFixture<TServerType>(make_shared<ParentServiceProcessorFactory>( |
| 334 | make_shared<ParentServiceIfSingletonFactory>( |
| 335 | make_shared<ParentHandler>()))) {} |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 336 | }; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 337 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 338 | template <class TServerType> |
| 339 | class TServerIntegrationProcessorTestFixture : public TServerIntegrationTestFixture<TServerType> { |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 340 | public: |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 341 | TServerIntegrationProcessorTestFixture() |
| 342 | : TServerIntegrationTestFixture<TServerType>( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 343 | make_shared<ParentServiceProcessor>(make_shared<ParentHandler>())) {} |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 344 | }; |
| 345 | |
| 346 | BOOST_AUTO_TEST_SUITE(constructors) |
| 347 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 348 | BOOST_FIXTURE_TEST_CASE(test_simple_factory, |
| 349 | TServerIntegrationProcessorFactoryTestFixture<TSimpleServer>) { |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 350 | baseline(3, 1, "factory"); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 351 | } |
| 352 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 353 | BOOST_FIXTURE_TEST_CASE(test_simple, TServerIntegrationProcessorTestFixture<TSimpleServer>) { |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 354 | baseline(3, 1, "processor"); |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 357 | BOOST_FIXTURE_TEST_CASE(test_threaded_factory, |
| 358 | TServerIntegrationProcessorFactoryTestFixture<TThreadedServer>) { |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 359 | baseline(10, 10, "factory"); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 360 | } |
| 361 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 362 | BOOST_FIXTURE_TEST_CASE(test_threaded, TServerIntegrationProcessorTestFixture<TThreadedServer>) { |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 363 | baseline(10, 10, "processor"); |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 364 | } |
| 365 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 366 | BOOST_FIXTURE_TEST_CASE(test_threaded_bound, |
| 367 | TServerIntegrationProcessorTestFixture<TThreadedServer>) { |
| 368 | pServer->setConcurrentClientLimit(4); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 369 | baseline(10, 4, "limit by server framework"); |
| 370 | } |
| 371 | |
| 372 | BOOST_FIXTURE_TEST_CASE(test_threaded_stress, |
| 373 | TServerIntegrationProcessorFactoryTestFixture<TThreadedServer>) { |
| 374 | stress(10, boost::posix_time::seconds(3)); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 375 | } |
| 376 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 377 | BOOST_FIXTURE_TEST_CASE(test_threadpool_factory, |
| 378 | TServerIntegrationProcessorFactoryTestFixture<TThreadPoolServer>) { |
| 379 | pServer->getThreadManager()->threadFactory( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 380 | shared_ptr<apache::thrift::concurrency::ThreadFactory>( |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 381 | new apache::thrift::concurrency::PlatformThreadFactory)); |
| 382 | pServer->getThreadManager()->start(); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 383 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 384 | // thread factory has 4 threads as a default |
| 385 | // thread factory however is a bad way to limit concurrent clients |
| 386 | // as accept() will be called to grab a 5th client socket, in this case |
| 387 | // and then the thread factory will block adding the thread to manage |
| 388 | // that client. |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 389 | baseline(10, 5, "limit by thread manager"); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 390 | } |
| 391 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 392 | BOOST_FIXTURE_TEST_CASE(test_threadpool, |
| 393 | TServerIntegrationProcessorTestFixture<TThreadPoolServer>) { |
| 394 | pServer->getThreadManager()->threadFactory( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 395 | shared_ptr<apache::thrift::concurrency::ThreadFactory>( |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 396 | new apache::thrift::concurrency::PlatformThreadFactory)); |
| 397 | pServer->getThreadManager()->start(); |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 398 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 399 | // thread factory has 4 threads as a default |
| 400 | // thread factory however is a bad way to limit concurrent clients |
| 401 | // as accept() will be called to grab a 5th client socket, in this case |
| 402 | // and then the thread factory will block adding the thread to manage |
| 403 | // that client. |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 404 | baseline(10, 5, "limit by thread manager"); |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 405 | } |
| 406 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 407 | BOOST_FIXTURE_TEST_CASE(test_threadpool_bound, |
| 408 | TServerIntegrationProcessorTestFixture<TThreadPoolServer>) { |
| 409 | pServer->getThreadManager()->threadFactory( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 410 | shared_ptr<apache::thrift::concurrency::ThreadFactory>( |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 411 | new apache::thrift::concurrency::PlatformThreadFactory)); |
| 412 | pServer->getThreadManager()->start(); |
| 413 | pServer->setConcurrentClientLimit(4); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 414 | |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 415 | baseline(10, 4, "server framework connection limit"); |
| 416 | } |
| 417 | |
| 418 | BOOST_FIXTURE_TEST_CASE(test_threadpool_stress, |
| 419 | TServerIntegrationProcessorTestFixture<TThreadPoolServer>) { |
| 420 | pServer->getThreadManager()->threadFactory( |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 421 | shared_ptr<apache::thrift::concurrency::ThreadFactory>( |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 422 | new apache::thrift::concurrency::PlatformThreadFactory)); |
| 423 | pServer->getThreadManager()->start(); |
| 424 | |
| 425 | stress(10, boost::posix_time::seconds(3)); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | BOOST_AUTO_TEST_SUITE_END() |
| 429 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 430 | BOOST_FIXTURE_TEST_SUITE(TServerIntegrationTest, |
| 431 | TServerIntegrationProcessorTestFixture<TThreadedServer>) |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 432 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 433 | BOOST_AUTO_TEST_CASE(test_stop_with_interruptable_clients_connected) { |
| 434 | // This tests THRIFT-2441 new behavior: stopping the server disconnects clients |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 435 | BOOST_TEST_MESSAGE("Testing stop with interruptable clients"); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 436 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 437 | startServer(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 438 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 439 | shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 440 | autoSocketCloser); |
| 441 | pClientSock1->open(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 442 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 443 | shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 444 | autoSocketCloser); |
| 445 | pClientSock2->open(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 446 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 447 | // Ensure they have been accepted |
| 448 | blockUntilAccepted(2); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 449 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 450 | // The test fixture destructor will force the sockets to disconnect |
| 451 | // Prior to THRIFT-2441, pServer->stop() would hang until clients disconnected |
| 452 | stopServer(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 453 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 454 | // extra proof the server end disconnected the clients |
| 455 | uint8_t buf[1]; |
| 456 | BOOST_CHECK_EQUAL(0, pClientSock1->read(&buf[0], 1)); // 0 = disconnected |
| 457 | BOOST_CHECK_EQUAL(0, pClientSock2->read(&buf[0], 1)); // 0 = disconnected |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 458 | } |
| 459 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 460 | BOOST_AUTO_TEST_CASE(test_stop_with_uninterruptable_clients_connected) { |
| 461 | // This tests pre-THRIFT-2441 behavior: stopping the server blocks until clients |
| 462 | // disconnect. |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 463 | BOOST_TEST_MESSAGE("Testing stop with uninterruptable clients"); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 464 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 465 | dynamic_pointer_cast<TServerSocket>(pServer->getServerTransport()) |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 466 | ->setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 467 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 468 | startServer(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 469 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 470 | shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 471 | autoSocketCloser); |
| 472 | pClientSock1->open(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 473 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 474 | shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 475 | autoSocketCloser); |
| 476 | pClientSock2->open(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 477 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 478 | // Ensure they have been accepted |
| 479 | blockUntilAccepted(2); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 480 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 481 | boost::thread t1(apache::thrift::stdcxx::bind(&TServerIntegrationTestFixture::delayClose, |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 482 | this, |
| 483 | pClientSock1, |
| 484 | milliseconds(250))); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 485 | boost::thread t2(apache::thrift::stdcxx::bind(&TServerIntegrationTestFixture::delayClose, |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 486 | this, |
| 487 | pClientSock2, |
| 488 | milliseconds(250))); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 489 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 490 | // Once the clients disconnect the server will stop |
| 491 | stopServer(); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 492 | BOOST_CHECK(pServer->getConcurrentClientCountHWM() > 0); |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 493 | t1.join(); |
| 494 | t2.join(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 495 | } |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 496 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 497 | BOOST_AUTO_TEST_CASE(test_concurrent_client_limit) { |
| 498 | startServer(); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 499 | BOOST_TEST_MESSAGE("Testing the concurrent client limit"); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 500 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 501 | BOOST_CHECK_EQUAL(INT64_MAX, pServer->getConcurrentClientLimit()); |
| 502 | pServer->setConcurrentClientLimit(2); |
| 503 | BOOST_CHECK_EQUAL(0, pServer->getConcurrentClientCount()); |
| 504 | BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientLimit()); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 505 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 506 | shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 507 | autoSocketCloser); |
| 508 | pClientSock1->open(); |
| 509 | blockUntilAccepted(1); |
| 510 | BOOST_CHECK_EQUAL(1, pServer->getConcurrentClientCount()); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 511 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 512 | shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 513 | autoSocketCloser); |
| 514 | pClientSock2->open(); |
| 515 | blockUntilAccepted(2); |
| 516 | BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCount()); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 517 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 518 | // a third client cannot connect until one of the other two closes |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 519 | boost::thread t2(apache::thrift::stdcxx::bind(&TServerIntegrationTestFixture::delayClose, |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 520 | this, |
| 521 | pClientSock2, |
| 522 | milliseconds(250))); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 523 | shared_ptr<TSocket> pClientSock3(new TSocket("localhost", getServerPort()), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 524 | autoSocketCloser); |
| 525 | pClientSock2->open(); |
| 526 | blockUntilAccepted(2); |
| 527 | BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCount()); |
| 528 | BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCountHWM()); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 529 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 530 | stopServer(); |
Jim King | 5a3f855 | 2016-04-05 12:17:51 -0400 | [diff] [blame] | 531 | BOOST_CHECK(pServer->getConcurrentClientCountHWM() > 0); |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 532 | t2.join(); |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 533 | } |
| 534 | |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 535 | BOOST_AUTO_TEST_SUITE_END() |