blob: 80e4c1fea0bcd84c8485a17e39766d5b66971a2e [file] [log] [blame]
ben-craigaf2d9c82015-07-16 08:11:21 -05001/*
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
jfarrelle2e5e222015-08-25 14:59:40 -040020#ifdef _WIN32
21
ben-craigaf2d9c82015-07-16 08:11:21 -050022#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
32using apache::thrift::transport::TPipeServer;
33using apache::thrift::transport::TPipe;
34using apache::thrift::transport::TTransport;
35using apache::thrift::transport::TTransportException;
36
37BOOST_AUTO_TEST_SUITE(TPipeInterruptTest)
38
39// TODO: duplicate the test cases in TSocketInterruptTest for pipes,
40// once pipes implement interruptChildren
41
42BOOST_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
49static 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
60static void interruptWorker(TPipeServer *pipe) {
61 boost::this_thread::sleep(boost::posix_time::milliseconds(10));
62 pipe->interrupt();
63}
64
65BOOST_AUTO_TEST_CASE(stress_pipe_accept_interruption) {
James E. King, IIIdf899132016-11-12 15:16:30 -050066 int interruptIters = 10;
ben-craigaf2d9c82015-07-16 08:11:21 -050067
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");
jfarrelle2e5e222015-08-25 14:59:40 -040079 client.setConnTimeout(1);
ben-craigaf2d9c82015-07-16 08:11:21 -050080 client.open();
81 }
82 } catch (...) { /*just testing for crashes*/ }
83 interruptThread.join();
84 acceptThread.join();
85 }
86}
87
88BOOST_AUTO_TEST_SUITE_END()
jfarrelle2e5e222015-08-25 14:59:40 -040089#endif