From bb98ce33936edc0dc914652c0227f95727518b16 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 7 Jan 2020 22:16:14 +0100 Subject: [PATCH] tests: fix failure tests --- libmemcached/do.cc | 4 +-- libtest/server.cc | 11 +------- libtest/server_container.cc | 7 ++++- tests/failure.cc | 52 ++++++++++++++++++------------------- 4 files changed, 34 insertions(+), 40 deletions(-) diff --git a/libmemcached/do.cc b/libmemcached/do.cc index 9ba513f2..daf1a115 100644 --- a/libmemcached/do.cc +++ b/libmemcached/do.cc @@ -93,10 +93,10 @@ memcached_return_t memcached_vdo(memcached_instance_st* instance, bool sent_success= memcached_io_writev(instance, vector, count, with_flush); if (sent_success == false) { - assert(memcached_last_error(instance->root) == MEMCACHED_SUCCESS); + //assert(memcached_last_error(instance->root) == MEMCACHED_SUCCESS); if (memcached_last_error(instance->root) == MEMCACHED_SUCCESS) { - assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS); + //assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS); return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT); } else diff --git a/libtest/server.cc b/libtest/server.cc index d024d054..7f3a2d1e 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -130,8 +130,7 @@ Server::~Server() bool Server::check() { _app.slurp(); - _app.check(); - return true; + return _app.check(); } bool Server::validate() @@ -197,14 +196,6 @@ bool Server::has_pid() const bool Server::start() { - // If we find that we already have a pid then kill it. - if (has_pid() == true) - { -#if 0 - fatal_message("has_pid() failed, programer error"); -#endif - } - if (getenv("YATL_GDB_SERVER")) { _app.use_gdb(true); diff --git a/libtest/server_container.cc b/libtest/server_container.cc index 4e73a0e9..2179fd14 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -153,7 +153,12 @@ void server_startup_st::restart() { for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) { - (*iter)->start(); + Server *server = *iter; + + if (server->check()) { + server->kill(); + } + server->start(); } } diff --git a/tests/failure.cc b/tests/failure.cc index f572cce6..64b2fa7f 100644 --- a/tests/failure.cc +++ b/tests/failure.cc @@ -63,33 +63,26 @@ libtest::Framework *global_framework= NULL; static test_return_t shutdown_servers(memcached_st *memc) { - return TEST_SKIPPED; - - test_skip_valgrind(); - test_compare(memcached_server_count(memc), 1U); // Disable a single server, just the first - global_framework->servers().shutdown(0); + test_true(global_framework->servers().shutdown(0)); return TEST_SUCCESS; } static test_return_t add_shutdown_servers(memcached_st *memc) { - return TEST_SKIPPED; - - 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(), argv)); - test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "localhost", libtest::default_port())); + const char *argv[2]= { "add_shutdown_server", NULL }; + in_port_t port = libtest::default_port(); + test_true(global_framework->servers().start_socket_server("memcached", port, argv)); + test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "localhost", port)); } // Disable a single server, just the first - global_framework->servers().shutdown(0); + test_true(global_framework->servers().shutdown(0)); return TEST_SUCCESS; } @@ -105,6 +98,8 @@ static test_return_t restart_servers(memcached_st *) #include "libmemcached/instance.hpp" static test_return_t cull_TEST(memcached_st *memc) { + shutdown_servers(memc); + uint32_t count= memcached_server_count(memc); // Do not do this in your code, it is not supported. @@ -114,11 +109,13 @@ static test_return_t cull_TEST(memcached_st *memc) uint32_t new_count= memcached_server_count(memc); test_compare(count, new_count); - return TEST_SUCCESS; + return restart_servers(memc); } static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_TEST(memcached_st *memc) { + shutdown_servers(memc); + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 30)); test_compare_got(MEMCACHED_CONNECTION_FAILURE, memcached_set(memc, @@ -134,12 +131,12 @@ static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_TEST(memcached_st *me test_compare(MEMCACHED_SERVER_TEMPORARILY_DISABLED, memcached_set(memc, test_literal_param("foo"), NULL, 0, time_t(0), uint32_t(0))); - return TEST_SUCCESS; + return restart_servers(memc); } static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_to_success_TEST(memcached_st *memc) { - return TEST_SKIPPED; + shutdown_servers(memc); test_compare_got(MEMCACHED_CONNECTION_FAILURE, memcached_set(memc, @@ -157,10 +154,10 @@ static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_to_success_TEST(memca global_framework->servers().restart(); - int limit= 5; + int limit= 10; memcached_return_t ret; do { - libtest::dream(3, 0); + libtest::dream(1, 0); ret= memcached_set(memc, test_literal_param("foo"), NULL, 0, time_t(0), uint32_t(0)); } while (ret == MEMCACHED_SERVER_TEMPORARILY_DISABLED and --limit); @@ -168,14 +165,15 @@ static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_to_success_TEST(memca test_compare_got(MEMCACHED_SUCCESS, ret, memcached_last_error_message(memc)); - return TEST_SUCCESS; + return restart_servers(memc); } static test_return_t MEMCACHED_SERVER_MARKED_DEAD_TEST(memcached_st *memc) { - return TEST_SKIPPED; + add_shutdown_servers(memc); - test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 30)); + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, 2)); + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 1)); test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS, true)); memcached_return_t ret; @@ -186,9 +184,9 @@ static test_return_t MEMCACHED_SERVER_MARKED_DEAD_TEST(memcached_st *memc) } while (ret == MEMCACHED_SUCCESS or ret == MEMCACHED_CONNECTION_FAILURE); test_compare(MEMCACHED_SERVER_TEMPORARILY_DISABLED, ret); - int limit= 5; + int limit= 10; do { - libtest::dream(3, 0); + libtest::dream(1, 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); @@ -196,7 +194,7 @@ static test_return_t MEMCACHED_SERVER_MARKED_DEAD_TEST(memcached_st *memc) test_compare_got(MEMCACHED_SERVER_MARKED_DEAD, ret, memcached_last_error_message(memc)); - return TEST_SUCCESS; + return restart_servers(memc); } test_st cull_TESTS[] ={ @@ -216,9 +214,9 @@ test_st server_permanently_disabled_TESTS[] ={ }; 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 }, + { "cull", NULL, NULL, cull_TESTS }, + { "server failed", NULL, NULL, server_temporarily_disabled_TESTS }, + { "server eject", NULL, NULL, server_permanently_disabled_TESTS }, { 0, 0, 0, 0 } }; -- 2.30.2