X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ffailure.cc;h=95c8fb6ad8cfb8f482414a8b8d6afeb682547427;hb=25efe3485198149616820ab4e52d2f18f0abe5a7;hp=185f9c71d9647de0920c5672928bbfb20477853f;hpb=969fea8e7bed82c109685ec3976cf7b0ec514ae9;p=m6w6%2Flibmemcached diff --git a/tests/failure.cc b/tests/failure.cc index 185f9c71..95c8fb6a 100644 --- a/tests/failure.cc +++ b/tests/failure.cc @@ -39,7 +39,7 @@ /* C++ interface test */ -#include +#include #include #include @@ -63,6 +63,8 @@ Framework *global_framework= NULL; static test_return_t shutdown_servers(memcached_st *memc) { + test_skip_valgrind(); + test_compare(memcached_server_count(memc), 1U); // Disable a single server, just the first @@ -71,6 +73,23 @@ static test_return_t shutdown_servers(memcached_st *memc) return TEST_SUCCESS; } +static test_return_t add_shutdown_servers(memcached_st *memc) +{ + test_skip_valgrind(); + + while (memcached_server_count(memc) < 2) + { + const char *argv[1]= { "add_shutdown_server" }; + test_true(global_framework->servers().start_socket_server("memcached", libtest::default_port(), 1, argv)); + test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "localhost", libtest::default_port())); + } + + // Disable a single server, just the first + global_framework->servers().shutdown(0); + + return TEST_SUCCESS; +} + static test_return_t restart_servers(memcached_st *) { // Restart the servers @@ -79,6 +98,7 @@ static test_return_t restart_servers(memcached_st *) return TEST_SUCCESS; } +#include "libmemcached/instance.h" static test_return_t cull_TEST(memcached_st *memc) { uint32_t count= memcached_server_count(memc); @@ -115,6 +135,8 @@ static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_TEST(memcached_st *me static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_to_success_TEST(memcached_st *memc) { + return TEST_SKIPPED; + test_compare_got(MEMCACHED_CONNECTION_FAILURE, memcached_set(memc, test_literal_param("foo"), @@ -131,56 +153,83 @@ static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_to_success_TEST(memca global_framework->servers().restart(); + int limit= 5; memcached_return_t ret; do { - sleep(3); + libtest::dream(3, 0); ret= memcached_set(memc, test_literal_param("foo"), NULL, 0, time_t(0), uint32_t(0)); - } while (ret == MEMCACHED_SERVER_TEMPORARILY_DISABLED); + } while (ret == MEMCACHED_SERVER_TEMPORARILY_DISABLED and --limit); + + test_true(limit); test_compare_got(MEMCACHED_SUCCESS, ret, memcached_last_error_message(memc)); return TEST_SUCCESS; } +static test_return_t MEMCACHED_SERVER_MARKED_DEAD_TEST(memcached_st *memc) +{ + return TEST_SKIPPED; + + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 30)); + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS, true)); + + memcached_return_t ret; + do { + ret= memcached_set(memc, + test_literal_param("foo"), + NULL, 0, time_t(0), uint32_t(0)); + } while (ret == MEMCACHED_SUCCESS or ret == MEMCACHED_CONNECTION_FAILURE); + test_compare(MEMCACHED_SERVER_TEMPORARILY_DISABLED, ret); + + int limit= 5; + do { + libtest::dream(3, 0); + ret= memcached_set(memc, test_literal_param("foo"), NULL, 0, time_t(0), uint32_t(0)); + } while ((ret == MEMCACHED_SERVER_TEMPORARILY_DISABLED or ret == MEMCACHED_SUCCESS) and --limit); + + test_true(limit); + + test_compare_got(MEMCACHED_SERVER_MARKED_DEAD, ret, memcached_last_error_message(memc)); + + return TEST_SUCCESS; +} + test_st cull_TESTS[] ={ { "cull servers", true, (test_callback_fn*)cull_TEST }, { 0, 0, 0 } }; test_st server_temporarily_disabled_TESTS[] ={ - { "memcached_set(MEMCACHED_SERVER_TEMPORARILY_DISABLED)", true, (test_callback_fn*)MEMCACHED_SERVER_TEMPORARILY_DISABLED_TEST }, { "memcached_set(MEMCACHED_SERVER_TEMPORARILY_DISABLED -> MEMCACHED_SUCCESS)", true, (test_callback_fn*)MEMCACHED_SERVER_TEMPORARILY_DISABLED_to_success_TEST }, + { "memcached_set(MEMCACHED_SERVER_TEMPORARILY_DISABLED)", true, (test_callback_fn*)MEMCACHED_SERVER_TEMPORARILY_DISABLED_TEST }, + { 0, 0, 0 } +}; + +test_st server_permanently_disabled_TESTS[] ={ + { "memcached_set(MEMCACHED_SERVER_MARKED_DEAD)", true, (test_callback_fn*)MEMCACHED_SERVER_MARKED_DEAD_TEST }, { 0, 0, 0 } }; collection_st collection[] ={ { "cull", (test_callback_fn*)shutdown_servers, (test_callback_fn*)restart_servers, cull_TESTS }, { "server failed", (test_callback_fn*)shutdown_servers, (test_callback_fn*)restart_servers, server_temporarily_disabled_TESTS }, + { "server eject", (test_callback_fn*)add_shutdown_servers, (test_callback_fn*)restart_servers, server_permanently_disabled_TESTS }, { 0, 0, 0, 0 } }; -#define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT +10 -#include "libmemcached_world.h" +#include "tests/libmemcached_world.h" void get_world(Framework *world) { - world->servers().set_count(1); - - world->collections= collection; - - world->_create= (test_callback_create_fn*)world_create; - world->_destroy= (test_callback_destroy_fn*)world_destroy; + world->servers().set_servers_to_run(1); - world->item._startup= (test_callback_fn*)world_test_startup; - world->item.set_pre((test_callback_fn*)world_pre_run); - world->item.set_flush((test_callback_fn*)world_flush); - world->item.set_post((test_callback_fn*)world_post_run); - world->_on_error= (test_callback_error_fn*)world_on_error; + world->collections(collection); - world->collection_startup= (test_callback_fn*)world_container_startup; - world->collection_shutdown= (test_callback_fn*)world_container_shutdown; + world->create((test_callback_create_fn*)world_create); + world->destroy((test_callback_destroy_fn*)world_destroy); - world->set_runner(&defualt_libmemcached_runner); + world->set_runner(new LibmemcachedRunner); global_framework= world; }