From: Brian Aker Date: Thu, 6 May 2010 15:56:53 +0000 (-0700) Subject: Look for regressions in error messages. X-Git-Tag: 0.41~33 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=727bb52db1af1d405c76df285001938eafb67d0a;p=awesomized%2Flibmemcached Look for regressions in error messages. --- diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 7d36ea72..3872ee38 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -4962,6 +4962,71 @@ static test_return_t memcached_get_hashkit_test (memcached_st *memc) return TEST_SUCCESS; } +/* + Test case adapted from John Gorman + + We are testing the error condition when we connect to a server via memcached_get() + but find that the server is not available. +*/ +static test_return_t memcached_get_MEMCACHED_SOME_ERRORS(memcached_st *memc) +{ + (void)memc; + memcached_st *tl_memc_h; + memcached_server_st *servers; + + const char *key= "MemcachedLives"; + size_t len; + uint32_t flags; + memcached_return rc; + char *value; + + // Create a handle. + tl_memc_h= memcached_create(NULL); + servers= memcached_servers_parse("localhost:9898"); // This server should not exist + memcached_server_push(tl_memc_h, servers); + memcached_server_list_free(servers); + + // See if memcached is reachable. + value= memcached_get(tl_memc_h, key, strlen(key), &len, &flags, &rc); + + if (value) + { + free(value); + test_true(value); // Pointer won't be zero so this is fine. + } + + test_true(len == 0); + test_true(rc == MEMCACHED_SOME_ERRORS); + + return TEST_SUCCESS; +} + +/* + We connect to a server which exists, but search for a key that does not exist. +*/ +static test_return_t memcached_get_MEMCACHED_NOTFOUND(memcached_st *memc) +{ + const char *key= "MemcachedKeyNotEXIST"; + size_t len; + uint32_t flags; + memcached_return rc; + char *value; + + // See if memcached is reachable. + value= memcached_get(memc, key, strlen(key), &len, &flags, &rc); + + if (value) + { + free(value); + test_true(value); // Pointer won't be zero so this is fine. + } + + test_true(len == 0); + test_true(rc == MEMCACHED_NOTFOUND); + + return TEST_SUCCESS; +} + static test_return_t ketama_compatibility_libmemcached(memcached_st *trash) { @@ -6124,6 +6189,12 @@ test_st hash_tests[] ={ {0, 0, (test_callback_fn)0} }; +test_st error_conditions[] ={ + {"memcached_get_MEMCACHED_SOME_ERRORS", 0, (test_callback_fn)memcached_get_MEMCACHED_SOME_ERRORS }, + {"memcached_get_MEMCACHED_NOTFOUND", 0, (test_callback_fn)memcached_get_MEMCACHED_NOTFOUND }, + {0, 0, (test_callback_fn)0} +}; + collection_st collection[] ={ #if 0 {"hash_sanity", 0, 0, hash_sanity}, @@ -6184,6 +6255,7 @@ collection_st collection[] ={ {"regression", 0, 0, regression_tests}, {"behaviors", 0, 0, behavior_tests}, {"regression_binary_vs_block", (test_callback_fn)key_setup, (test_callback_fn)key_teardown, regression_binary_vs_block}, + {"error_conditions", 0, 0, error_conditions}, {0, 0, 0, 0} };