Merge in trunk. Updates to manual/update to latest libtest.
[m6w6/libmemcached] / tests / parser.cc
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Libmemcached Client and Server
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * * The names of its contributors may not be used to endorse or
21 * promote products derived from this software without specific prior
22 * written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 */
37
38 #include <config.h>
39
40 #include <vector>
41 #include <iostream>
42 #include <string>
43 #include <cerrno>
44 #include <cassert>
45
46 #include <libtest/test.hpp>
47
48 #define BUILDING_LIBMEMCACHED
49 // !NEVER use common.h, always use memcached.h in your own apps
50 #include <libmemcached/common.h>
51 #include <libmemcached/util.h>
52
53 #include <tests/parser.h>
54 #include <tests/print.h>
55
56 enum scanner_type_t
57 {
58 NIL,
59 UNSIGNED,
60 SIGNED,
61 ARRAY
62 };
63
64
65 struct scanner_string_st {
66 const char *c_str;
67 size_t size;
68 };
69
70 static inline scanner_string_st scanner_string(const char *arg, size_t arg_size)
71 {
72 scanner_string_st local= { arg, arg_size };
73 return local;
74 }
75
76 #define make_scanner_string(X) scanner_string((X), static_cast<size_t>(sizeof(X) - 1))
77
78 static struct scanner_string_st scanner_string_null= { 0, 0};
79
80 struct scanner_variable_t {
81 enum scanner_type_t type;
82 struct scanner_string_st option;
83 struct scanner_string_st result;
84 test_return_t (*check_func)(memcached_st *memc, const scanner_string_st &hostname);
85 };
86
87 // Check and make sure the first host is what we expect it to be
88 static test_return_t __check_host(memcached_st *memc, const scanner_string_st &hostname)
89 {
90 memcached_server_instance_st instance=
91 memcached_server_instance_by_position(memc, 0);
92
93 test_true(instance);
94
95 const char *first_hostname = memcached_server_name(instance);
96 test_true(first_hostname);
97 test_strcmp(first_hostname, hostname.c_str);
98
99 return TEST_SUCCESS;
100 }
101
102 // Check and make sure the prefix_key is what we expect it to be
103 static test_return_t __check_prefix_key(memcached_st *memc, const scanner_string_st &hostname)
104 {
105 memcached_server_instance_st instance=
106 memcached_server_instance_by_position(memc, 0);
107
108 test_true(instance);
109
110 const char *first_hostname = memcached_server_name(instance);
111 test_true(first_hostname);
112 test_strcmp(first_hostname, hostname.c_str);
113
114 return TEST_SUCCESS;
115 }
116
117 static test_return_t __check_IO_MSG_WATERMARK(memcached_st *memc, const scanner_string_st &value)
118 {
119 uint64_t value_number;
120
121 value_number= atoll(value.c_str);
122
123 test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK) == value_number);
124 return TEST_SUCCESS;
125 }
126
127 static test_return_t __check_REMOVE_FAILED_SERVERS(memcached_st *memc, const scanner_string_st &)
128 {
129 test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS));
130 return TEST_SUCCESS;
131 }
132
133 static test_return_t __check_NOREPLY(memcached_st *memc, const scanner_string_st &)
134 {
135 test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NOREPLY));
136 return TEST_SUCCESS;
137 }
138
139 static test_return_t __check_VERIFY_KEY(memcached_st *memc, const scanner_string_st &)
140 {
141 test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_VERIFY_KEY));
142 return TEST_SUCCESS;
143 }
144
145 static test_return_t __check_distribution_RANDOM(memcached_st *memc, const scanner_string_st &)
146 {
147 test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION) == MEMCACHED_DISTRIBUTION_RANDOM);
148 return TEST_SUCCESS;
149 }
150
151 scanner_variable_t test_server_strings[]= {
152 { ARRAY, make_scanner_string("--server=localhost"), make_scanner_string("localhost"), __check_host },
153 { ARRAY, make_scanner_string("--server=10.0.2.1"), make_scanner_string("10.0.2.1"), __check_host },
154 { ARRAY, make_scanner_string("--server=example.com"), make_scanner_string("example.com"), __check_host },
155 { ARRAY, make_scanner_string("--server=localhost:30"), make_scanner_string("localhost"), __check_host },
156 { ARRAY, make_scanner_string("--server=10.0.2.1:20"), make_scanner_string("10.0.2.1"), __check_host },
157 { ARRAY, make_scanner_string("--server=example.com:1024"), make_scanner_string("example.com"), __check_host },
158 { NIL, scanner_string_null, scanner_string_null, NULL }
159 };
160
161 scanner_variable_t test_server_strings_with_weights[]= {
162 { ARRAY, make_scanner_string("--server=10.0.2.1:30/?40"), make_scanner_string("10.0.2.1"), __check_host },
163 { ARRAY, make_scanner_string("--server=example.com:1024/?30"), make_scanner_string("example.com"), __check_host },
164 { ARRAY, make_scanner_string("--server=10.0.2.1/?20"), make_scanner_string("10.0.2.1"), __check_host },
165 { ARRAY, make_scanner_string("--server=example.com/?10"), make_scanner_string("example.com"), __check_host },
166 { NIL, scanner_string_null, scanner_string_null, NULL }
167 };
168
169 scanner_variable_t bad_test_strings[]= {
170 { ARRAY, make_scanner_string("-servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:11225"), scanner_string_null, NULL },
171 { ARRAY, make_scanner_string("-- servers=a.example.com:81,localhost:82,b.example.com"), scanner_string_null, NULL },
172 { ARRAY, make_scanner_string("--servers=localhost:+80"), scanner_string_null, NULL},
173 { ARRAY, make_scanner_string("--servers=localhost.com."), scanner_string_null, NULL},
174 { ARRAY, make_scanner_string("--server=localhost.com."), scanner_string_null, NULL},
175 { ARRAY, make_scanner_string("--server=localhost.com.:80"), scanner_string_null, NULL},
176 { NIL, scanner_string_null, scanner_string_null, NULL}
177 };
178
179 scanner_variable_t test_number_options[]= {
180 { ARRAY, make_scanner_string("--CONNECT-TIMEOUT=456"), scanner_string_null, NULL },
181 { ARRAY, make_scanner_string("--IO-BYTES-WATERMARK=456"), scanner_string_null, NULL },
182 { ARRAY, make_scanner_string("--IO-KEY-PREFETCH=456"), scanner_string_null, NULL },
183 { ARRAY, make_scanner_string("--IO-MSG-WATERMARK=456"), make_scanner_string("456"), __check_IO_MSG_WATERMARK },
184 { ARRAY, make_scanner_string("--NUMBER-OF-REPLICAS=456"), scanner_string_null, NULL },
185 { ARRAY, make_scanner_string("--POLL-TIMEOUT=456"), scanner_string_null, NULL },
186 { ARRAY, make_scanner_string("--RCV-TIMEOUT=456"), scanner_string_null, NULL },
187 { ARRAY, make_scanner_string("--REMOVE-FAILED-SERVERS=3"), scanner_string_null, __check_REMOVE_FAILED_SERVERS },
188 { ARRAY, make_scanner_string("--RETRY-TIMEOUT=456"), scanner_string_null, NULL },
189 { ARRAY, make_scanner_string("--SND-TIMEOUT=456"), scanner_string_null, NULL },
190 { ARRAY, make_scanner_string("--SOCKET-RECV-SIZE=456"), scanner_string_null, NULL },
191 { ARRAY, make_scanner_string("--SOCKET-SEND-SIZE=456"), scanner_string_null, NULL },
192 { NIL, scanner_string_null, scanner_string_null, NULL}
193 };
194
195 scanner_variable_t test_boolean_options[]= {
196 { ARRAY, make_scanner_string("--BINARY-PROTOCOL"), scanner_string_null, NULL },
197 { ARRAY, make_scanner_string("--BUFFER-REQUESTS"), scanner_string_null, NULL },
198 { ARRAY, make_scanner_string("--HASH-WITH-NAMESPACE"), scanner_string_null, NULL },
199 { ARRAY, make_scanner_string("--NOREPLY"), scanner_string_null, __check_NOREPLY },
200 { ARRAY, make_scanner_string("--RANDOMIZE-REPLICA-READ"), scanner_string_null, NULL },
201 { ARRAY, make_scanner_string("--SORT-HOSTS"), scanner_string_null, NULL },
202 { ARRAY, make_scanner_string("--SUPPORT-CAS"), scanner_string_null, NULL },
203 { ARRAY, make_scanner_string("--TCP-NODELAY"), scanner_string_null, NULL },
204 { ARRAY, make_scanner_string("--TCP-KEEPALIVE"), scanner_string_null, NULL },
205 { ARRAY, make_scanner_string("--TCP-KEEPIDLE"), scanner_string_null, NULL },
206 { ARRAY, make_scanner_string("--USE-UDP"), scanner_string_null, NULL },
207 { ARRAY, make_scanner_string("--VERIFY-KEY"), scanner_string_null, __check_VERIFY_KEY },
208 { NIL, scanner_string_null, scanner_string_null, NULL}
209 };
210
211 scanner_variable_t prefix_key_strings[]= {
212 { ARRAY, make_scanner_string("--NAMESPACE=foo"), make_scanner_string("foo"), __check_prefix_key },
213 { ARRAY, make_scanner_string("--NAMESPACE=\"foo\""), make_scanner_string("foo"), __check_prefix_key },
214 { ARRAY, make_scanner_string("--NAMESPACE=\"This_is_a_very_long_key\""), make_scanner_string("This_is_a_very_long_key"), __check_prefix_key },
215 { NIL, scanner_string_null, scanner_string_null, NULL}
216 };
217
218 scanner_variable_t distribution_strings[]= {
219 { ARRAY, make_scanner_string("--DISTRIBUTION=consistent"), scanner_string_null, NULL },
220 { ARRAY, make_scanner_string("--DISTRIBUTION=consistent,CRC"), scanner_string_null, NULL },
221 { ARRAY, make_scanner_string("--DISTRIBUTION=consistent,MD5"), scanner_string_null, NULL },
222 { ARRAY, make_scanner_string("--DISTRIBUTION=random"), scanner_string_null, __check_distribution_RANDOM },
223 { ARRAY, make_scanner_string("--DISTRIBUTION=modula"), scanner_string_null, NULL },
224 { NIL, scanner_string_null, scanner_string_null, NULL}
225 };
226
227 scanner_variable_t hash_strings[]= {
228 { ARRAY, make_scanner_string("--HASH=CRC"), scanner_string_null, NULL },
229 { ARRAY, make_scanner_string("--HASH=FNV1A_32"), scanner_string_null, NULL },
230 { ARRAY, make_scanner_string("--HASH=FNV1A_64"), scanner_string_null, NULL },
231 { ARRAY, make_scanner_string("--HASH=FNV1_32"), scanner_string_null, NULL },
232 { ARRAY, make_scanner_string("--HASH=FNV1_64"), scanner_string_null, NULL },
233 { ARRAY, make_scanner_string("--HASH=JENKINS"), scanner_string_null, NULL },
234 { ARRAY, make_scanner_string("--HASH=MD5"), scanner_string_null, NULL },
235 { ARRAY, make_scanner_string("--HASH=MURMUR"), scanner_string_null, NULL },
236 { NIL, scanner_string_null, scanner_string_null, NULL}
237 };
238
239
240 static test_return_t _test_option(scanner_variable_t *scanner, bool test_true= true)
241 {
242 (void)test_true;
243
244 for (scanner_variable_t *ptr= scanner; ptr->type != NIL; ptr++)
245 {
246 memcached_st *memc;
247 memc= memcached(ptr->option.c_str, ptr->option.size);
248 if (test_true)
249 {
250 if (not memc)
251 {
252 char buffer[2048];
253 memcached_return_t rc= libmemcached_check_configuration(ptr->option.c_str, ptr->option.size, buffer, sizeof(buffer));
254 std::cerr << "About error for " << memcached_strerror(NULL, rc) << " : " << buffer << std::endl;
255 }
256
257 test_true(memc);
258
259 if (ptr->check_func)
260 {
261 test_return_t test_rc= (*ptr->check_func)(memc, ptr->result);
262 if (test_rc != TEST_SUCCESS)
263 {
264 memcached_free(memc);
265 return test_rc;
266 }
267 }
268
269 memcached_free(memc);
270 }
271 else
272 {
273 test_false_with(memc, ptr->option.c_str);
274 }
275 }
276
277 return TEST_SUCCESS;
278 }
279
280 test_return_t server_test(memcached_st *)
281 {
282 return _test_option(test_server_strings);
283 }
284
285 test_return_t server_with_weight_test(memcached_st *)
286 {
287 return _test_option(test_server_strings_with_weights);
288 }
289
290 test_return_t servers_bad_test(memcached_st *)
291 {
292 test_return_t rc;
293 if ((rc= _test_option(bad_test_strings, false)) != TEST_SUCCESS)
294 {
295 return rc;
296 }
297
298 return TEST_SUCCESS;
299 }
300
301 test_return_t parser_number_options_test(memcached_st*)
302 {
303 return _test_option(test_number_options);
304 }
305
306 test_return_t parser_boolean_options_test(memcached_st*)
307 {
308 return _test_option(test_boolean_options);
309 }
310
311 test_return_t behavior_parser_test(memcached_st*)
312 {
313 return TEST_SUCCESS;
314 }
315
316 test_return_t parser_hash_test(memcached_st*)
317 {
318 return _test_option(hash_strings);
319 }
320
321 test_return_t parser_distribution_test(memcached_st*)
322 {
323 return _test_option(distribution_strings);
324 }
325
326 test_return_t parser_key_prefix_test(memcached_st*)
327 {
328 return _test_option(distribution_strings);
329 }
330
331 #define SUPPORT_EXAMPLE_CNF "support/example.cnf"
332
333 test_return_t memcached_create_with_options_with_filename(memcached_st*)
334 {
335 if (access(SUPPORT_EXAMPLE_CNF, R_OK))
336 return TEST_SKIPPED;
337
338 memcached_st *memc_ptr;
339 memc_ptr= memcached(test_literal_param("--CONFIGURE-FILE=\"support/example.cnf\""));
340 test_true_got(memc_ptr, "memcached() failed");
341 test_strcmp(SUPPORT_EXAMPLE_CNF, memcached_array_string(memc_ptr->configure.filename));
342 memcached_free(memc_ptr);
343
344 return TEST_SUCCESS;
345 }
346
347 test_return_t libmemcached_check_configuration_with_filename_test(memcached_st*)
348 {
349 if (access(SUPPORT_EXAMPLE_CNF, R_OK))
350 return TEST_SKIPPED;
351
352 memcached_return_t rc;
353 char buffer[BUFSIZ];
354
355 rc= libmemcached_check_configuration(test_literal_param("--CONFIGURE-FILE=\"support/example.cnf\""), buffer, sizeof(buffer));
356 test_true_got(rc == MEMCACHED_SUCCESS, (rc == MEMCACHED_ERRNO) ? strerror(errno) : memcached_strerror(NULL, rc));
357
358 rc= libmemcached_check_configuration(test_literal_param("--CONFIGURE-FILE=support/example.cnf"), buffer, sizeof(buffer));
359 test_false_with(rc == MEMCACHED_SUCCESS, memcached_strerror(NULL, rc));
360
361 rc= libmemcached_check_configuration(test_literal_param("--CONFIGURE-FILE=\"bad-path/example.cnf\""), buffer, sizeof(buffer));
362 test_true_got(rc == MEMCACHED_ERRNO, memcached_strerror(NULL, rc));
363
364 return TEST_SUCCESS;
365 }
366
367 test_return_t libmemcached_check_configuration_test(memcached_st*)
368 {
369 memcached_return_t rc;
370 char buffer[BUFSIZ];
371
372 rc= libmemcached_check_configuration(test_literal_param("--server=localhost"), buffer, sizeof(buffer));
373 test_true_got(rc == MEMCACHED_SUCCESS, buffer);
374
375 rc= libmemcached_check_configuration(test_literal_param("--dude=localhost"), buffer, sizeof(buffer));
376 test_false_with(rc == MEMCACHED_SUCCESS, buffer);
377 test_true(rc == MEMCACHED_PARSE_ERROR);
378
379 return TEST_SUCCESS;
380 }
381
382 test_return_t memcached_create_with_options_test(memcached_st*)
383 {
384 memcached_st *memc_ptr;
385 memc_ptr= memcached(test_literal_param("--server=localhost"));
386 test_true_got(memc_ptr, memcached_last_error_message(memc_ptr));
387 memcached_free(memc_ptr);
388
389 memc_ptr= memcached(test_literal_param("--dude=localhost"));
390 test_false_with(memc_ptr, memcached_last_error_message(memc_ptr));
391
392 return TEST_SUCCESS;
393 }
394
395 test_return_t test_include_keyword(memcached_st*)
396 {
397 if (access(SUPPORT_EXAMPLE_CNF, R_OK))
398 return TEST_SKIPPED;
399
400 char buffer[BUFSIZ];
401 memcached_return_t rc;
402 rc= libmemcached_check_configuration(test_literal_param("INCLUDE \"support/example.cnf\""), buffer, sizeof(buffer));
403 test_true_got(rc == MEMCACHED_SUCCESS, buffer);
404
405 return TEST_SUCCESS;
406 }
407
408 test_return_t test_end_keyword(memcached_st*)
409 {
410 char buffer[BUFSIZ];
411 memcached_return_t rc;
412 rc= libmemcached_check_configuration(test_literal_param("--server=localhost END bad keywords"), buffer, sizeof(buffer));
413 test_true_got(rc == MEMCACHED_SUCCESS, buffer);
414
415 return TEST_SUCCESS;
416 }
417
418 test_return_t test_reset_keyword(memcached_st*)
419 {
420 char buffer[BUFSIZ];
421 memcached_return_t rc;
422 rc= libmemcached_check_configuration(test_literal_param("--server=localhost reset --server=bad.com"), buffer, sizeof(buffer));
423 test_true_got(rc == MEMCACHED_SUCCESS, buffer);
424
425 return TEST_SUCCESS;
426 }
427
428 test_return_t test_error_keyword(memcached_st*)
429 {
430 char buffer[BUFSIZ];
431 memcached_return_t rc;
432 rc= libmemcached_check_configuration(test_literal_param("--server=localhost ERROR --server=bad.com"), buffer, sizeof(buffer));
433 test_true_got(rc != MEMCACHED_SUCCESS, buffer);
434
435 return TEST_SUCCESS;
436 }
437
438 #define RANDOM_STRINGS 100
439 test_return_t random_statement_build_test(memcached_st*)
440 {
441 std::vector<scanner_string_st *> option_list;
442
443 for (scanner_variable_t *ptr= test_server_strings; ptr->type != NIL; ptr++)
444 option_list.push_back(&ptr->option);
445
446 for (scanner_variable_t *ptr= test_number_options; ptr->type != NIL; ptr++)
447 option_list.push_back(&ptr->option);
448
449 for (scanner_variable_t *ptr= test_boolean_options; ptr->type != NIL; ptr++)
450 option_list.push_back(&ptr->option);
451
452 for (scanner_variable_t *ptr= prefix_key_strings; ptr->type != NIL; ptr++)
453 option_list.push_back(&ptr->option);
454
455 for (scanner_variable_t *ptr= distribution_strings; ptr->type != NIL; ptr++)
456 option_list.push_back(&ptr->option);
457
458 for (scanner_variable_t *ptr= hash_strings; ptr->type != NIL; ptr++)
459 option_list.push_back(&ptr->option);
460
461 for (uint32_t x= 0; x < RANDOM_STRINGS; x++)
462 {
463 std::string random_options;
464
465 uint32_t number_of= random() % option_list.size();
466 for (uint32_t options= 0; options < number_of; options++)
467 {
468 random_options+= option_list[random() % option_list.size()]->c_str;
469 random_options+= " ";
470 }
471
472 memcached_st *memc_ptr= memcached(random_options.c_str(), random_options.size() -1);
473 if (not memc_ptr)
474 {
475 switch (errno)
476 {
477 case EINVAL:
478 #if 0 // Testing framework is not smart enough for this just yet.
479 {
480 // We will try to find the specific error
481 char buffer[2048];
482 memcached_return_t rc= libmemcached_check_configuration(random_options.c_str(), random_options.size(), buffer, sizeof(buffer));
483 test_true_got(rc != MEMCACHED_SUCCESS, "memcached_create_with_options() failed whiled libmemcached_check_configuration() was successful");
484 std::cerr << "Error occured on " << random_options.c_str() << " : " << buffer << std::endl;
485 return TEST_FAILURE;
486 }
487 #endif
488 break;
489 case ENOMEM:
490 std::cerr << "Failed to allocate memory for memcached_create_with_options()" << std::endl;
491 memcached_free(memc_ptr);
492 return TEST_FAILURE;
493 default:
494 std::cerr << "Unknown error from memcached_create_with_options?!!" << std::endl;
495 memcached_free(memc_ptr);
496 return TEST_FAILURE;
497 }
498 }
499 memcached_free(memc_ptr);
500 }
501
502 return TEST_SUCCESS;
503 }
504
505 static memcached_return_t dump_server_information(const memcached_st *,
506 const memcached_server_st *instance,
507 void *)
508 {
509 if (strcmp(memcached_server_name(instance), "localhost"))
510 {
511 assert(not memcached_server_name(instance));
512 return MEMCACHED_FAILURE;
513 }
514
515 if (memcached_server_port(instance) < 8888 or memcached_server_port(instance) > 8892)
516 {
517 assert(not memcached_server_port(instance));
518 return MEMCACHED_FAILURE;
519 }
520
521 if (instance->weight > 5 or instance->weight < 2)
522 {
523 assert(not instance->weight);
524 return MEMCACHED_FAILURE;
525 }
526
527 return MEMCACHED_SUCCESS;
528 }
529
530
531 test_return_t test_hostname_port_weight(memcached_st *)
532 {
533 const char *server_string= "--server=localhost:8888/?2 --server=localhost:8889/?3 --server=localhost:8890/?4 --server=localhost:8891/?5 --server=localhost:8892/?3";
534 char buffer[BUFSIZ];
535
536 memcached_return_t rc;
537 test_compare_got(MEMCACHED_SUCCESS,
538 rc= libmemcached_check_configuration(server_string, strlen(server_string), buffer, sizeof(buffer)),
539 memcached_strerror(NULL, rc));
540
541 memcached_st *memc= memcached(server_string, strlen(server_string));
542 test_true(memc);
543
544 memcached_server_fn callbacks[]= { dump_server_information };
545 test_true(memcached_success(memcached_server_cursor(memc, callbacks, NULL, 1)));
546
547 memcached_free(memc);
548
549 return TEST_SUCCESS;
550 }
551
552 /*
553 By setting the timeout value to zero, we force poll() to return immediatly.
554 */
555 test_return_t regression_bug_71231153_connect(memcached_st *)
556 {
557 if (libmemcached_util_ping("10.0.2.252", 0, NULL)) // If for whatever reason someone has a host at this address, skip
558 return TEST_SKIPPED;
559
560 { // Test the connect-timeout, on a bad host we should get MEMCACHED_CONNECTION_FAILURE
561 memcached_st *memc= memcached(memcached_literal_param("--SERVER=10.0.2.252 --CONNECT-TIMEOUT=0"));
562 test_true(memc);
563 test_compare(0, memc->connect_timeout);
564 test_compare(MEMCACHED_DEFAULT_TIMEOUT, memc->poll_timeout);
565
566 memcached_return_t rc;
567 size_t value_len;
568 char *value= memcached_get(memc, memcached_literal_param("test"), &value_len, NULL, &rc);
569 test_false(value);
570 test_compare(0, value_len);
571 test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_strerror(NULL, rc));
572
573 memcached_free(memc);
574 }
575
576 return TEST_SUCCESS;
577 }
578
579 test_return_t regression_bug_71231153_poll(memcached_st *)
580 {
581 if (libmemcached_util_ping("10.0.2.252", 0, NULL)) // If for whatever reason someone has a host at this address, skip
582 return TEST_SKIPPED;
583
584 { // Test the poll timeout, on a bad host we should get MEMCACHED_CONNECTION_FAILURE
585 memcached_st *memc= memcached(memcached_literal_param("--SERVER=10.0.2.252 --POLL-TIMEOUT=0"));
586 test_true(memc);
587 test_compare(MEMCACHED_DEFAULT_CONNECT_TIMEOUT, memc->connect_timeout);
588 test_compare(0, memc->poll_timeout);
589
590 memcached_return_t rc;
591 size_t value_len;
592 char *value= memcached_get(memc, memcached_literal_param("test"), &value_len, NULL, &rc);
593 test_false(value);
594 test_compare(0, value_len);
595 test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_strerror(NULL, rc));
596
597 memcached_free(memc);
598 }
599
600 return TEST_SUCCESS;
601 }