X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fcycle.cc;h=64d2b860355e217dc53ec59dcccea160c6654e2f;hb=73e62c470da9bb5f0b0e4a2ecf195c7259e33cf1;hp=3b0aa2410770cee3e76c63d2d57154765f94a828;hpb=7abcaebdc4c3dd11b779eaef58a7371fb82ae888;p=m6w6%2Flibmemcached diff --git a/tests/cycle.cc b/tests/cycle.cc index 3b0aa241..64d2b860 100644 --- a/tests/cycle.cc +++ b/tests/cycle.cc @@ -39,53 +39,114 @@ Test that we are cycling the servers we are creating during testing. */ -#include +#include +#include -#include +#include +#include +#include + +#include #include -#define SERVERS_TO_CREATE 5 +using namespace libtest; #ifndef __INTEL_COMPILER #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif -test_st ping[] ={ - {0, 0, 0} -}; +static test_return_t alive(memcached_st *memc) +{ + 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); -collection_st collection[] ={ - {0, 0, 0, 0} -}; + test_true(libmemcached_util_ping(memcached_server_name(instance), + memcached_server_port(instance), NULL)); + } -static server_startup_st *world_create(test_return_t *error) + return TEST_SUCCESS; +} + +static test_return_t valid(memcached_st *memc) { - server_startup_st *servers= new server_startup_st(); + test_true(memc); + test_true(memcached_is_allocated(memc)); - server_startup(servers); + 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); - *error= TEST_SUCCESS; + pid_t pid= libmemcached_util_getpid(memcached_server_name(instance), + memcached_server_port(instance), NULL); + test_true(pid != -1); + } - return servers; + return TEST_SUCCESS; } -static test_return_t world_destroy(server_startup_st *servers) +static test_return_t kill_test(memcached_st *) { - server_shutdown(servers); - delete servers; + static struct timespec global_sleep_value= { 2, 0 }; + +#ifdef WIN32 + sleep(1); +#else + nanosleep(&global_sleep_value, NULL); +#endif return TEST_SUCCESS; } +test_st ping_tests[] ={ + {"alive", true, (test_callback_fn*)alive }, + {0, 0, 0} +}; + +test_st getpid_tests[] ={ + {"valid", true, (test_callback_fn*)valid }, + {0, 0, 0} +}; +test_st kill_tests[] ={ + {"kill", true, (test_callback_fn*)kill_test }, + {0, 0, 0} +}; + +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} +}; + + +#define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT +10 +#include "tests/libmemcached_world.h" void get_world(Framework *world) { world->collections= collection; world->_create= (test_callback_create_fn*)world_create; - world->_destroy= (test_callback_fn*)world_destroy; + world->_destroy= (test_callback_destroy_fn*)world_destroy; + + 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); + + world->set_on_error((test_callback_error_fn*)world_on_error); + + world->collection_startup= (test_callback_fn*)world_container_startup; + world->collection_shutdown= (test_callback_fn*)world_container_shutdown; + + world->set_runner(&defualt_libmemcached_runner); + world->set_socket(); }