From: Brian Aker Date: Sun, 25 Nov 2007 17:17:34 +0000 (-0800) Subject: Extended tests so that memcached starts up its own tests X-Git-Tag: _11~7 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=03a38ffb6dbde1be82141c71e22900e18d7b56fa;p=m6w6%2Flibmemcached Extended tests so that memcached starts up its own tests --- diff --git a/ChangeLog b/ChangeLog index 15316a20..14b627de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,8 @@ value was returned. * Bug fixed in memcached_connect() which would cause servers that did not need to be enabled to be enabled (performance issue). - * Rewrote bounds checking code for get calls + * Rewrote bounds checking code for get calls. + * "make test" now starts its own memcached servers. 0.10 Tue Nov 20 23:22:31 PST 2007 * Added append binary test. diff --git a/tests/function.c b/tests/function.c index 3819eae7..1f536e88 100644 --- a/tests/function.c +++ b/tests/function.c @@ -542,13 +542,14 @@ uint8_t get_test4(memcached_st *memc) return 0; } +/* Do not copy the style of this code, I just access hosts to testthis function */ uint8_t stats_servername_test(memcached_st *memc) { memcached_return rc; memcached_stat_st stat; rc= memcached_stat_servername(&stat, NULL, - "localhost", - MEMCACHED_DEFAULT_PORT); + memc->hosts[0].hostname, + memc->hosts[0].port); return 0; } diff --git a/tests/test.c b/tests/test.c index 1de861ab..2ea99ff2 100644 --- a/tests/test.c +++ b/tests/test.c @@ -13,6 +13,9 @@ #include "test.h" +#define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10 +#define TEST_SERVERS 1 + long int timedif(struct timeval a, struct timeval b) { register int us, s; @@ -24,6 +27,43 @@ long int timedif(struct timeval a, struct timeval b) return s + us; } +char *server_startup() +{ + unsigned int x; + char server_string_buffer[8096]; + char *end_ptr; + + end_ptr= server_string_buffer; + + for (x= 0; x < TEST_SERVERS; x++) + { + char buffer[1024]; /* Nothing special for number */ + int count; + + sprintf(buffer, "memcached -d -P /tmp/%umemc.pid -p %u", x, x+ TEST_PORT_BASE); + system(buffer); + count= sprintf(end_ptr, "localhost:%u,", x + TEST_PORT_BASE); + end_ptr+= count; + } + *end_ptr= 0; + + return strdup(server_string_buffer); +} + +void server_shutdown(char *server_string) +{ + unsigned int x; + + for (x= 0; x < TEST_SERVERS; x++) + { + char buffer[1024]; /* Nothing special for number */ + sprintf(buffer, "cat /tmp/%umemc.pid | xargs kill", x); + system(buffer); + } + if (server_string) + free(server_string); +} + int main(int argc, char *argv[]) { unsigned int x; @@ -43,14 +83,22 @@ int main(int argc, char *argv[]) if (argc == 3) wildcard= argv[2]; - if (!(server_list= getenv("MEMCACHED_SERVERS"))) - server_list= "localhost"; + if ((server_list= getenv("MEMCACHED_SERVERS"))) + { + printf("servers %s\n", server_list); + servers= memcached_servers_parse(server_list); + server_list= NULL; + } + else + { + server_list= server_startup(); + printf("servers %s\n", server_list); + servers= memcached_servers_parse(server_list); + } + assert(servers); - printf("servers %s\n", server_list); srandom(time(NULL)); - servers= memcached_servers_parse(server_list); - assert(servers); for (x= 0; x < memcached_server_list_count(servers); x++) { @@ -137,5 +185,7 @@ error: memcached_server_list_free(servers); + server_shutdown(server_list); + return 0; }