X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fcycle.cc;h=fe4ca1b37016180dc860924f7f37bd2dea28ee74;hb=23bbe3972dada1e21493437ba64be129e86b59fc;hp=04b00f704d37edb47fd8b0666edc7b980a2c8558;hpb=28602fd2f5f1c758b50cd82d4545da8e6c55f5c7;p=m6w6%2Flibmemcached diff --git a/tests/cycle.cc b/tests/cycle.cc index 04b00f70..fe4ca1b3 100644 --- a/tests/cycle.cc +++ b/tests/cycle.cc @@ -1,6 +1,6 @@ /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: * - * Libmemcached library + * Cycle the Gearmand server * * Copyright (C) 2011 Data Differential, http://datadifferential.com/ * @@ -42,111 +42,88 @@ #include #include -#include -#include -#include - -#include - - -#include - using namespace libtest; +#include -#define SERVERS_TO_CREATE 5 - -#ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif - -static test_return_t alive(memcached_st *memc) +static test_return_t server_startup_single_TEST(void *obj) { - test_true(memc); - test_true(memcached_is_allocated(memc)); - for (uint32_t x= 0; x < memcached_server_count(memc); ++x) - { - memcached_server_instance_st instance= memcached_server_instance_by_position(memc, x); - test_true(instance); + server_startup_st *servers= (server_startup_st*)obj; + test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), 0, NULL, false)); + test_compare(true, servers->shutdown()); - test_true(libmemcached_util_ping(memcached_server_name(instance), - memcached_server_port(instance), NULL)); - } return TEST_SUCCESS; } -static test_return_t valid(memcached_st *memc) +static test_return_t server_startup_multiple_TEST(void *obj) { - test_true(memc); - test_true(memcached_is_allocated(memc)); - - for (uint32_t x= 0; x < memcached_server_count(memc); ++x) + server_startup_st *servers= (server_startup_st*)obj; + for (size_t x= 0; x < 10; x++) { - memcached_server_instance_st instance= memcached_server_instance_by_position(memc, x); - test_true(instance); - - pid_t pid= libmemcached_util_getpid(memcached_server_name(instance), - memcached_server_port(instance), NULL); - test_true(pid != -1); + test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), 0, NULL, false)); } + test_compare(true, servers->shutdown()); return TEST_SUCCESS; } -static test_return_t kill_test(memcached_st *) +static test_return_t shutdown_and_remove_TEST(void *obj) { - static struct timespec global_sleep_value= { 2, 0 }; - -#ifdef WIN32 - sleep(1); -#else - nanosleep(&global_sleep_value, NULL); -#endif + server_startup_st *servers= (server_startup_st*)obj; + servers->clear(); return TEST_SUCCESS; } -test_st ping_tests[] ={ - {"alive", true, (test_callback_fn*)alive }, +test_st server_startup_TESTS[] ={ + {"server_startup(1)", false, (test_callback_fn*)server_startup_single_TEST }, + {"server_startup(10)", false, (test_callback_fn*)server_startup_multiple_TEST }, + {"shutdown_and_remove()", false, (test_callback_fn*)shutdown_and_remove_TEST }, + {"server_startup(10)", false, (test_callback_fn*)server_startup_multiple_TEST }, {0, 0, 0} }; -test_st getpid_tests[] ={ - {"valid", true, (test_callback_fn*)valid }, - {0, 0, 0} -}; +#if 0 +static test_return_t collection_INIT(void *object) +{ + server_startup_st *servers= (server_startup_st*)object; + test_zero(servers->count()); + test_compare(true, server_startup(*servers, "memcached", libtest::default_port(), 0, NULL)); -test_st kill_tests[] ={ - {"kill", true, (test_callback_fn*)kill_test }, - {0, 0, 0} -}; + return TEST_SUCCESS; +} +#endif -collection_st collection[] ={ - {"libmemcached_util_ping()", 0, 0, ping_tests}, - {"libmemcached_util_getpid()", 0, 0, getpid_tests}, - {"kill", 0, 0, kill_tests}, - {0, 0, 0, 0} -}; +static test_return_t validate_sanity_INIT(void *object) +{ + server_startup_st *servers= (server_startup_st*)object; + test_zero(servers->count()); -#include "tests/libmemcached_world.h" + return TEST_SUCCESS; +} -void get_world(Framework *world) +static test_return_t collection_FINAL(void *object) { - world->collections= collection; - - world->_create= (test_callback_create_fn*)world_create; - world->_destroy= (test_callback_destroy_fn*)world_destroy; + server_startup_st *servers= (server_startup_st*)object; + servers->clear(); - world->item.set_startup((test_callback_fn*)world_test_startup); - world->item.set_pre((test_callback_fn*)world_pre_run); - world->item.set_post((test_callback_fn*)world_post_run); + return TEST_SUCCESS; +} - world->set_on_error((test_callback_error_fn*)world_on_error); +collection_st collection[] ={ + {"server_startup()", validate_sanity_INIT, collection_FINAL, server_startup_TESTS }, + {0, 0, 0, 0} +}; - world->collection_startup= (test_callback_fn*)world_container_startup; - world->collection_shutdown= (test_callback_fn*)world_container_shutdown; +static void *world_create(server_startup_st& servers, test_return_t& ) +{ + return &servers; +} - world->set_runner(&defualt_libmemcached_runner); +void get_world(Framework *world) +{ + world->collections(collection); + world->create(world_create); }