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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
22 #include <boost/test/test_tools.hpp>
23 #include <boost/test/unit_test_suite.hpp>
25 #include <boost/chrono/duration.hpp>
26 #include <boost/date_time/posix_time/posix_time_duration.hpp>
27 #include <boost/thread/thread.hpp>
28 #include <thrift/transport/TPipe.h>
29 #include <thrift/transport/TPipeServer.h>
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 using namespace apache::thrift
;
38 BOOST_AUTO_TEST_SUITE(TPipeInterruptTest
)
40 // TODO: duplicate the test cases in TSocketInterruptTest for pipes,
41 // once pipes implement interruptChildren
43 BOOST_AUTO_TEST_CASE(test_interrupt_before_accept
) {
44 TPipeServer
pipe1("TPipeInterruptTest");
47 BOOST_CHECK_THROW(pipe1
.accept(), TTransportException
);
50 static void acceptWorker(TPipeServer
*pipe
) {
55 std::shared_ptr
<TTransport
> temp
= pipe
->accept();
58 catch (...) {/*just want to make sure nothing crashes*/ }
61 static void interruptWorker(TPipeServer
*pipe
) {
62 boost::this_thread::sleep(boost::posix_time::milliseconds(10));
66 BOOST_AUTO_TEST_CASE(stress_pipe_accept_interruption
) {
67 int interruptIters
= 10;
69 for (int i
= 0; i
< interruptIters
; ++i
)
71 TPipeServer
pipeServer("TPipeInterruptTest");
73 boost::thread
acceptThread(std::bind(acceptWorker
, &pipeServer
));
74 boost::thread
interruptThread(std::bind(interruptWorker
, &pipeServer
));
79 TPipe
client("TPipeInterruptTest");
80 client
.setConnTimeout(1);
83 } catch (...) { /*just testing for crashes*/ }
84 interruptThread
.join();
89 BOOST_AUTO_TEST_SUITE_END()