Merge lp:~trond-norbye/libmemcached/ascii_test_mget into lp:~brianaker/libmemcached/build

Proposed by Trond Norbye
Status: Merged
Merged at revision: 847
Proposed branch: lp:~trond-norbye/libmemcached/ascii_test_mget
Merge into: lp:~brianaker/libmemcached/build
Diff against target: 126 lines (+82/-13)
1 file modified
clients/memcapable.c (+82/-13)
To merge this branch: bzr merge lp:~trond-norbye/libmemcached/ascii_test_mget
Reviewer Review Type Date Requested Status
Libmemcached-developers Pending
Review via email: mp+27329@code.launchpad.net

Description of the change

memcapable should verify that mget return the correct set of items, not the order they are returned in.

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-06-05 19:17:33 +0000
3+++ clients/memcapable.c 2010-06-11 08:05:42 +0000
4@@ -9,7 +9,6 @@
5 *
6 */
7
8-/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
9 #undef NDEBUG
10 #include "config.h"
11 #include <pthread.h>
12@@ -1297,6 +1296,42 @@
13 return test_ascii_add_impl("test_ascii_add_noreply", true);
14 }
15
16+static enum test_return ascii_get_unknown_value(char **key, char **value,
17+ ssize_t *ndata)
18+{
19+ char buffer[1024];
20+
21+ execute(receive_line(buffer, sizeof(buffer)));
22+ verify(strncmp(buffer, "VALUE ", 6) == 0);
23+ char *end = strchr(buffer + 6, ' ');
24+ verify(end != NULL);
25+ *end = '\0';
26+ *key = strdup(buffer + 6);
27+ verify(*key != NULL);
28+ char *ptr= end + 1;
29+
30+ unsigned long val= strtoul(ptr, &end, 10); /* flags */
31+ verify(ptr != end);
32+ verify(val == 0);
33+ verify(end != NULL);
34+ *ndata = strtoul(end, &end, 10); /* size */
35+ verify(ptr != end);
36+ verify(end != NULL);
37+ while (*end != '\n' && isspace(*end))
38+ ++end;
39+ verify(*end == '\n');
40+
41+ *value = malloc(*ndata);
42+ verify(*value != NULL);
43+
44+ execute(retry_read(*value, *ndata));
45+
46+ execute(retry_read(buffer, 2));
47+ verify(memcmp(buffer, "\r\n", 2) == 0);
48+
49+ return TEST_PASS;
50+}
51+
52 static enum test_return ascii_get_value(const char *key, const char *value)
53 {
54
55@@ -1565,25 +1600,59 @@
56
57 static enum test_return test_ascii_mget(void)
58 {
59- execute(ascii_set_item("test_ascii_mget1", "value"));
60- execute(ascii_set_item("test_ascii_mget2", "value"));
61- execute(ascii_set_item("test_ascii_mget3", "value"));
62- execute(ascii_set_item("test_ascii_mget4", "value"));
63- execute(ascii_set_item("test_ascii_mget5", "value"));
64-
65+ const int nkeys= 5;
66+ const char * const keys[]= {
67+ "test_ascii_mget1",
68+ "test_ascii_mget2",
69+ /* test_ascii_mget_3 does not exist :) */
70+ "test_ascii_mget4",
71+ "test_ascii_mget5",
72+ "test_ascii_mget6"
73+ };
74+
75+
76+ for (int x= 0; x < nkeys; ++x)
77+ execute(ascii_set_item(keys[x], "value"));
78+
79+ /* Ask for a key that doesn't exist as well */
80 execute(send_string("get test_ascii_mget1 test_ascii_mget2 test_ascii_mget3 "
81 "test_ascii_mget4 test_ascii_mget5 "
82 "test_ascii_mget6\r\n"));
83- execute(ascii_get_value("test_ascii_mget1", "value"));
84- execute(ascii_get_value("test_ascii_mget2", "value"));
85- execute(ascii_get_value("test_ascii_mget3", "value"));
86- execute(ascii_get_value("test_ascii_mget4", "value"));
87- execute(ascii_get_value("test_ascii_mget5", "value"));
88+
89+ char* returned[nkeys];
90+
91+ for (int x= 0; x < nkeys; ++x)
92+ {
93+ ssize_t nbytes;
94+ char *v;
95+ execute(ascii_get_unknown_value(&returned[x], &v, &nbytes));
96+ verify(nbytes == 5);
97+ verify(memcmp(v, "value", 5) == 0);
98+ free(v);
99+ }
100
101 char buffer[5];
102 execute(retry_read(buffer, 5));
103 verify(memcmp(buffer, "END\r\n", 5) == 0);
104- return TEST_PASS;
105+
106+ /* verify that we got all the keys we expected */
107+ for (int x= 0; x < nkeys; ++x)
108+ {
109+ bool found= false;
110+ for (int y= 0; y < nkeys; ++y) {
111+ if (strcmp(keys[x], returned[y]) == 0)
112+ {
113+ found = true;
114+ break;
115+ }
116+ }
117+ verify(found);
118+ }
119+
120+ for (int x= 0; x < nkeys; ++x)
121+ free(returned[x]);
122+
123+ return TEST_PASS;
124 }
125
126 static enum test_return test_ascii_incr_impl(const char* key, bool noreply)

Subscribers

People subscribed via source and target branches

to all changes: