Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / rgw / test_http_manager.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2015 Red Hat
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation. See file COPYING.
12  *
13  */
14 #include "rgw/rgw_rados.h"
15 #include "rgw/rgw_http_client.h"
16 #include "global/global_init.h"
17 #include "common/ceph_argparse.h"
18 #include <curl/curl.h>
19 #include <gtest/gtest.h>
20
21 TEST(HTTPManager, SignalThread)
22 {
23   auto cct = g_ceph_context;
24   RGWHTTPManager http(cct);
25
26   ASSERT_EQ(0, http.set_threaded());
27
28   // default pipe buffer size according to man pipe
29   constexpr size_t max_pipe_buffer_size = 65536;
30   // each signal writes 4 bytes to the pipe
31   constexpr size_t max_pipe_signals = max_pipe_buffer_size / sizeof(uint32_t);
32   // add_request and unregister_request
33   constexpr size_t pipe_signals_per_request = 2;
34   // number of http requests to fill the pipe buffer
35   constexpr size_t max_requests = max_pipe_signals / pipe_signals_per_request;
36
37   // send one extra request to test that we don't deadlock
38   constexpr size_t num_requests = max_requests + 1;
39
40   for (size_t i = 0; i < num_requests; i++) {
41     RGWHTTPClient client{cct};
42     http.add_request(&client, "PUT", "http://127.0.0.1:80");
43   }
44 }
45
46 int main(int argc, char** argv)
47 {
48   vector<const char*> args;
49   argv_to_vec(argc, (const char **)argv, args);
50
51   auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
52                          CODE_ENVIRONMENT_UTILITY, 0);
53   common_init_finish(g_ceph_context);
54
55   curl_global_init(CURL_GLOBAL_ALL);
56   ::testing::InitGoogleTest(&argc, argv);
57   int r = RUN_ALL_TESTS();
58   curl_global_cleanup();
59   return r;
60 }