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 #ifndef _WIN32
27 # include <sys/resource.h>
28 #endif
29 
30 using namespace XmlRpc;
31 
33 {
34 #ifndef _WIN32
35  XmlRpcClient c("localhost", port);
36  XmlRpcValue noArgs, result;
37 
38  // Call the Hello method
39  ASSERT_TRUE(c.execute("Hello", noArgs, result));
40 
41  EXPECT_FALSE(c.isFault());
42  XmlRpcValue hello("Hello");
43  EXPECT_EQ(result, hello);
44 
45  c.close();
46  result.clear();
47 
48  // Get the current open file limits and check that we have a reasonable
49  // margin. We need to reduce the limit to 8 open files to starve the server
50  // side, so we would need 9 or 10 open files for it to work correctly
51  // Ensuring that we have a hard limit of at least 64 file descriptors gives
52  // a very wide margin above that.
53  struct rlimit limit = {.rlim_cur = 0, .rlim_max = 0};
54  ASSERT_EQ(0, getrlimit(RLIMIT_NOFILE, &limit));
55  ASSERT_LT(64u, limit.rlim_max);
56  ASSERT_LT(64u, limit.rlim_cur);
57 
58  // Reduce the number of open file descriptors so that we can create a client
59  // but can't accept the connection on the server side. 32 is more than the
60  // number of currently open files, but less than minimum unused file
61  // descriptors. We expect the server to be able to accept the connection and
62  // then immediately reject it without servicing it.
63  limit.rlim_cur = 32;
64  ASSERT_EQ(0, setrlimit(RLIMIT_NOFILE, &limit));
65 
66  XmlRpcClient c2("127.0.0.1", port);
67  EXPECT_FALSE(c2.execute("Hello", noArgs, result));
68 
69  // Raise the limit and verify that clients can connect again
70  limit.rlim_cur = limit.rlim_max;
71  ASSERT_EQ(0, setrlimit(RLIMIT_NOFILE, &limit));
72  c2.close();
73  EXPECT_TRUE(c2.execute("Hello", noArgs, result));
74  EXPECT_EQ(result, hello);
75 #endif
76 }
77 
78 int main(int argc, char **argv)
79 {
80  ::testing::InitGoogleTest(&argc, argv);
81  return RUN_ALL_TESTS();
82 }
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:24
int main(int argc, char **argv)
Definition: test_ulimit.cpp:78
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:32
bool isFault() const
Returns true if the result of the last execute() was a fault response.
Definition: XmlRpcClient.h:65


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas
autogenerated on Wed Apr 28 2021 02:23:00