test_ulimit.cpp
Go to the documentation of this file.
1 /*
2  * Unit tests for XmlRpc++
3  *
4  * Copyright (C) 2017, Zoox Inc
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Author: Austin Hendrix <austin@zoox.com>
21  *
22  */
23 
24 #include "test_fixtures.h"
25 
26 #include <sys/resource.h>
27 
28 using namespace XmlRpc;
29 
31 {
32  XmlRpcClient c("localhost", port);
33  XmlRpcValue noArgs, result;
34 
35  // Call the Hello method
36  ASSERT_TRUE(c.execute("Hello", noArgs, result));
37 
38  EXPECT_FALSE(c.isFault());
39  XmlRpcValue hello("Hello");
40  EXPECT_EQ(result, hello);
41 
42  c.close();
43  result.clear();
44 
45  // Get the current open file limits and check that we have a reasonable
46  // margin. We need to reduce the limit to 8 open files to starve the server
47  // side, so we would need 9 or 10 open files for it to work correctly
48  // Ensuring that we have a hard limit of at least 64 file descriptors gives
49  // a very wide margin above that.
50  struct rlimit limit = {.rlim_cur = 0, .rlim_max = 0};
51  ASSERT_EQ(0, getrlimit(RLIMIT_NOFILE, &limit));
52  ASSERT_LT(64u, limit.rlim_max);
53  ASSERT_LT(64u, limit.rlim_cur);
54 
55  // Reduce the number of open file descriptors so that we can create a client
56  // but can't accept the connection on the server side. 32 is more than the
57  // number of currently open files, but less than minimum unused file
58  // descriptors. We expect the server to be able to accept the connection and
59  // then immediately reject it without servicing it.
60  limit.rlim_cur = 32;
61  ASSERT_EQ(0, setrlimit(RLIMIT_NOFILE, &limit));
62 
63  XmlRpcClient c2("127.0.0.1", port);
64  EXPECT_FALSE(c2.execute("Hello", noArgs, result));
65 
66  // Raise the limit and verify that clients can connect again
67  limit.rlim_cur = limit.rlim_max;
68  ASSERT_EQ(0, setrlimit(RLIMIT_NOFILE, &limit));
69  c2.close();
70  EXPECT_TRUE(c2.execute("Hello", noArgs, result));
71  EXPECT_EQ(result, hello);
72 }
73 
74 int main(int argc, char **argv)
75 {
76  ::testing::InitGoogleTest(&argc, argv);
77  return RUN_ALL_TESTS();
78 }
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:24
int main(int argc, char **argv)
Definition: test_ulimit.cpp:74
bool isFault() const
Returns true if the result of the last execute() was a fault response.
Definition: XmlRpcClient.h:65
void clear()
Erase the current value.
Definition: XmlRpcValue.h:79
virtual void close()
Close the connection.
A class to send XML RPC requests to a server and return the results.
Definition: XmlRpcClient.h:26
bool execute(const char *method, XmlRpcValue const &params, XmlRpcValue &result)
TEST_F(XmlRpcTest, Ulimit)
Definition: test_ulimit.cpp:30


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix
autogenerated on Sun Feb 3 2019 03:29:51