ben-craig | af2d9c8 | 2015-07-16 08:11:21 -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 | |
jfarrell | e2e5e22 | 2015-08-25 14:59:40 -0400 | [diff] [blame] | 20 | #ifdef _WIN32 |
| 21 | |
ben-craig | af2d9c8 | 2015-07-16 08:11:21 -0500 | [diff] [blame] | 22 | #include <boost/test/test_tools.hpp> |
| 23 | #include <boost/test/unit_test_suite.hpp> |
| 24 | |
| 25 | #include <boost/bind.hpp> |
| 26 | #include <boost/chrono/duration.hpp> |
| 27 | #include <boost/date_time/posix_time/posix_time_duration.hpp> |
| 28 | #include <boost/thread/thread.hpp> |
| 29 | #include <thrift/transport/TPipe.h> |
| 30 | #include <thrift/transport/TPipeServer.h> |
| 31 | |
| 32 | using apache::thrift::transport::TPipeServer; |
| 33 | using apache::thrift::transport::TPipe; |
| 34 | using apache::thrift::transport::TTransport; |
| 35 | using apache::thrift::transport::TTransportException; |
| 36 | |
| 37 | BOOST_AUTO_TEST_SUITE(TPipeInterruptTest) |
| 38 | |
| 39 | // TODO: duplicate the test cases in TSocketInterruptTest for pipes, |
| 40 | // once pipes implement interruptChildren |
| 41 | |
| 42 | BOOST_AUTO_TEST_CASE(test_interrupt_before_accept) { |
| 43 | TPipeServer pipe1("TPipeInterruptTest"); |
| 44 | pipe1.listen(); |
| 45 | pipe1.interrupt(); |
| 46 | BOOST_CHECK_THROW(pipe1.accept(), TTransportException); |
| 47 | } |
| 48 | |
| 49 | static void acceptWorker(TPipeServer *pipe) { |
| 50 | try |
| 51 | { |
| 52 | for (;;) |
| 53 | { |
| 54 | boost::shared_ptr<TTransport> temp = pipe->accept(); |
| 55 | } |
| 56 | } |
| 57 | catch (...) {/*just want to make sure nothing crashes*/ } |
| 58 | } |
| 59 | |
| 60 | static void interruptWorker(TPipeServer *pipe) { |
| 61 | boost::this_thread::sleep(boost::posix_time::milliseconds(10)); |
| 62 | pipe->interrupt(); |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_CASE(stress_pipe_accept_interruption) { |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 66 | int interruptIters = 10; |
ben-craig | af2d9c8 | 2015-07-16 08:11:21 -0500 | [diff] [blame] | 67 | |
| 68 | for (int i = 0; i < interruptIters; ++i) |
| 69 | { |
| 70 | TPipeServer pipeServer("TPipeInterruptTest"); |
| 71 | pipeServer.listen(); |
| 72 | boost::thread acceptThread(boost::bind(acceptWorker, &pipeServer)); |
| 73 | boost::thread interruptThread(boost::bind(interruptWorker, &pipeServer)); |
| 74 | try |
| 75 | { |
| 76 | for (;;) |
| 77 | { |
| 78 | TPipe client("TPipeInterruptTest"); |
jfarrell | e2e5e22 | 2015-08-25 14:59:40 -0400 | [diff] [blame] | 79 | client.setConnTimeout(1); |
ben-craig | af2d9c8 | 2015-07-16 08:11:21 -0500 | [diff] [blame] | 80 | client.open(); |
| 81 | } |
| 82 | } catch (...) { /*just testing for crashes*/ } |
| 83 | interruptThread.join(); |
| 84 | acceptThread.join(); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | BOOST_AUTO_TEST_SUITE_END() |
jfarrell | e2e5e22 | 2015-08-25 14:59:40 -0400 | [diff] [blame] | 89 | #endif |