Update spec/m4/etc.
[awesomized/libmemcached] / tests / cycle.cc
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Cycle the Gearmand server
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37
38 /*
39 Test that we are cycling the servers we are creating during testing.
40 */
41
42 #include <mem_config.h>
43 #include <libtest/test.hpp>
44
45 using namespace libtest;
46 #include <libmemcached-1.0/memcached.h>
47
48 static test_return_t server_startup_single_TEST(void *obj)
49 {
50 server_startup_st *servers= (server_startup_st*)obj;
51 test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), 0, NULL, false));
52 test_compare(true, servers->shutdown());
53
54
55 return TEST_SUCCESS;
56 }
57
58 static test_return_t server_startup_multiple_TEST(void *obj)
59 {
60 test_skip(true, jenkins_is_caller());
61
62 server_startup_st *servers= (server_startup_st*)obj;
63 for (size_t x= 0; x < 10; x++)
64 {
65 test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), 0, NULL, false));
66 }
67 test_compare(true, servers->shutdown());
68
69 return TEST_SUCCESS;
70 }
71
72 static test_return_t shutdown_and_remove_TEST(void *obj)
73 {
74 server_startup_st *servers= (server_startup_st*)obj;
75 servers->clear();
76
77 return TEST_SUCCESS;
78 }
79
80 test_st server_startup_TESTS[] ={
81 {"server_startup(1)", false, (test_callback_fn*)server_startup_single_TEST },
82 {"server_startup(10)", false, (test_callback_fn*)server_startup_multiple_TEST },
83 {"shutdown_and_remove()", false, (test_callback_fn*)shutdown_and_remove_TEST },
84 {"server_startup(10)", false, (test_callback_fn*)server_startup_multiple_TEST },
85 {0, 0, 0}
86 };
87
88 #if 0
89 static test_return_t collection_INIT(void *object)
90 {
91 server_startup_st *servers= (server_startup_st*)object;
92 test_zero(servers->count());
93 test_compare(true, server_startup(*servers, "memcached", libtest::default_port(), 0, NULL));
94
95 return TEST_SUCCESS;
96 }
97 #endif
98
99 static test_return_t validate_sanity_INIT(void *object)
100 {
101 server_startup_st *servers= (server_startup_st*)object;
102
103 test_zero(servers->count());
104
105 return TEST_SUCCESS;
106 }
107
108 static test_return_t collection_FINAL(void *object)
109 {
110 server_startup_st *servers= (server_startup_st*)object;
111 servers->clear();
112
113 return TEST_SUCCESS;
114 }
115
116 collection_st collection[] ={
117 {"server_startup()", validate_sanity_INIT, collection_FINAL, server_startup_TESTS },
118 {0, 0, 0, 0}
119 };
120
121 static void *world_create(server_startup_st& servers, test_return_t& error)
122 {
123 if (jenkins_is_caller())
124 {
125 error= TEST_SKIPPED;
126 return NULL;
127 }
128
129 if (libtest::has_memcached() == false)
130 {
131 error= TEST_SKIPPED;
132 return NULL;
133 }
134
135 return &servers;
136 }
137
138 void get_world(libtest::Framework* world)
139 {
140 world->collections(collection);
141 world->create(world_create);
142 }
143