Merge lp:~trond-norbye/libmemcached/memcapable-errors into lp:~tangent-org/libmemcached/trunk

Proposed by Trond Norbye
Status: Merged
Merged at revision: 842
Proposed branch: lp:~trond-norbye/libmemcached/memcapable-errors
Merge into: lp:~tangent-org/libmemcached/trunk
Diff against target: 100 lines (+70/-3)
2 files modified
clients/memcapable.c (+3/-3)
tests/mem_functions.c (+67/-0)
To merge this branch: bzr merge lp:~trond-norbye/libmemcached/memcapable-errors
Reviewer Review Type Date Requested Status
Libmemcached-developers Pending
Review via email: mp+26866@code.launchpad.net

Description of the change

I just tested memcapable on servers that prints more verbose error messages.. this change just verifies that the error message starts with ERROR, CLIENT_ERROR or SERVER_ERROR

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'clients/memcapable.c'
2--- clients/memcapable.c 2010-03-08 21:19:08 +0000
3+++ clients/memcapable.c 2010-06-05 19:20:35 +0000
4@@ -1173,9 +1173,9 @@
5 {
6 char buffer[80];
7 execute(receive_line(buffer, sizeof(buffer)));
8- verify(strncmp(buffer, "ERROR\r\n", 7) == 0 ||
9- strncmp(buffer, "CLIENT_ERROR:", 13) == 0 ||
10- strncmp(buffer, "SERVER_ERROR:", 13) == 0);
11+ verify(strncmp(buffer, "ERROR", 5) == 0 ||
12+ strncmp(buffer, "CLIENT_ERROR", 12) == 0 ||
13+ strncmp(buffer, "SERVER_ERROR", 12) == 0);
14 return TEST_PASS;
15 }
16
17
18=== modified file 'tests/mem_functions.c'
19--- tests/mem_functions.c 2010-05-06 15:56:53 +0000
20+++ tests/mem_functions.c 2010-06-05 19:20:35 +0000
21@@ -5027,6 +5027,71 @@
22 return TEST_SUCCESS;
23 }
24
25+/*
26+ Test case adapted from John Gorman <johngorman2@gmail.com>
27+
28+ We are testing the error condition when we connect to a server via memcached_get_by_key()
29+ but find that the server is not available.
30+*/
31+static test_return_t memcached_get_by_key_MEMCACHED_SOME_ERRORS(memcached_st *memc)
32+{
33+ (void)memc;
34+ memcached_st *tl_memc_h;
35+ memcached_server_st *servers;
36+
37+ const char *key= "MemcachedLives";
38+ size_t len;
39+ uint32_t flags;
40+ memcached_return rc;
41+ char *value;
42+
43+ // Create a handle.
44+ tl_memc_h= memcached_create(NULL);
45+ servers= memcached_servers_parse("localhost:9898"); // This server should not exist
46+ memcached_server_push(tl_memc_h, servers);
47+ memcached_server_list_free(servers);
48+
49+ // See if memcached is reachable.
50+ value= memcached_get_by_key(tl_memc_h, key, strlen(key), key, strlen(key), &len, &flags, &rc);
51+
52+ if (value)
53+ {
54+ free(value);
55+ test_true(value); // Pointer won't be zero so this is fine.
56+ }
57+
58+ test_true(len == 0);
59+ test_true(rc == MEMCACHED_SOME_ERRORS);
60+
61+ return TEST_SUCCESS;
62+}
63+
64+/*
65+ We connect to a server which exists, but search for a key that does not exist.
66+*/
67+static test_return_t memcached_get_by_key_MEMCACHED_NOTFOUND(memcached_st *memc)
68+{
69+ const char *key= "MemcachedKeyNotEXIST";
70+ size_t len;
71+ uint32_t flags;
72+ memcached_return rc;
73+ char *value;
74+
75+ // See if memcached is reachable.
76+ value= memcached_get_by_key(memc, key, strlen(key), key, strlen(key), &len, &flags, &rc);
77+
78+ if (value)
79+ {
80+ free(value);
81+ test_true(value); // Pointer won't be zero so this is fine.
82+ }
83+
84+ test_true(len == 0);
85+ test_true(rc == MEMCACHED_NOTFOUND);
86+
87+ return TEST_SUCCESS;
88+}
89+
90
91 static test_return_t ketama_compatibility_libmemcached(memcached_st *trash)
92 {
93@@ -6192,6 +6257,8 @@
94 test_st error_conditions[] ={
95 {"memcached_get_MEMCACHED_SOME_ERRORS", 0, (test_callback_fn)memcached_get_MEMCACHED_SOME_ERRORS },
96 {"memcached_get_MEMCACHED_NOTFOUND", 0, (test_callback_fn)memcached_get_MEMCACHED_NOTFOUND },
97+ {"memcached_get_by_key_MEMCACHED_SOME_ERRORS", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_SOME_ERRORS },
98+ {"memcached_get_by_key_MEMCACHED_NOTFOUND", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_NOTFOUND },
99 {0, 0, (test_callback_fn)0}
100 };
101

Subscribers

People subscribed via source and target branches

to all changes: