Merge lp:~athomason/libmemcached/test-big-binary-mget into lp:~tangent-org/libmemcached/trunk

Proposed by Adam Thomason
Status: Merged
Merged at revision: not available
Proposed branch: lp:~athomason/libmemcached/test-big-binary-mget
Merge into: lp:~tangent-org/libmemcached/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~athomason/libmemcached/test-big-binary-mget
Reviewer Review Type Date Requested Status
Trond Norbye (community) Needs Fixing
Review via email: mp+12193@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Adam Thomason (athomason) wrote :
Revision history for this message
Trond Norbye (trond-norbye) wrote :

1) The test case doesn't use the memcached servers started by the test suite, but tries to connect to localhost:11211. You should connect to the servers started by the test suite instead. If you want to limit the number of servers being used, you should create a clone with memcached_clone and set memc_clone->number_of_hosts to the number of hosts you want (BUT ADD A COMMENT THAT THIS IS A DIRTY HACK JUST USED IN THE TEST FRAMEWORK AND SHOULDN'T BE USED OUTSIDE THE TEST FRAMEWORK!!)

2) Test cases should return TEST_SUCCESS/TEST_FAIL and not MEMCACHED_SUCCESS (different enums)

3) You can use calloc instead of malloc followed by a memset call, and you can assign a void* to everything according to C99 standard so you don't need any casting there...

review: Needs Fixing
Revision history for this message
Adam Thomason (athomason) wrote :

Trond Norbye wrote:
> Review: Needs Fixing
> 1) The test case doesn't use the memcached servers started by the test suite, but tries to connect to localhost:11211. You should connect to the servers started by the test suite instead.
Actually not, it's 11221, the first one the tests start. I didn't see an
obvious bit of what I wanted to do elsewhere in the tests, but point taken.
> If you want to limit the number of servers being used, you should create a clone with memcached_clone and set memc_clone->number_of_hosts to the number of hosts you want (BUT ADD A COMMENT THAT THIS IS A DIRTY HACK JUST USED IN THE TEST FRAMEWORK AND SHOULDN'T BE USED OUTSIDE THE TEST FRAMEWORK!!)
>
No need to yell at your own suggestion ;). The number of servers is
actually irrelevant, I just need a fresh memcached_st. memcached_clone
does seem simpler and more correct, so I'll use that.
> 2) Test cases should return TEST_SUCCESS/TEST_FAIL and not MEMCACHED_SUCCESS (different enums)
>
Sure. To prevent future annoyances I'd suggest cleaning up the rest of
the tests to do the same since newbies like me are likely to just copy
surrounding examples :).
> 3) You can use calloc instead of malloc followed by a memset call, and you can assign a void* to everything according to C99 standard so you don't need any casting there...
>
Similarly, that's code just borrowed from user_supplied_bug3. I'll fix
up all the malloc/memset instances that I see.

582. By Adam Thomason

Address trond's comments

583. By Adam Thomason

Fix return codes

584. By Adam Thomason

Factor out fetch-all-requests code marked "Turn this into a help function" into fetch_all_results help function

Revision history for this message
Brian Aker (brianaker) wrote :

Hi!

I just wanted to update you. We are still working on this... we have a
new interface we will be putting together to solve this problem.

We have not forgotten you :)

Cheers,
    -Brian

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/function.c'
2--- tests/function.c 2009-09-10 10:57:11 +0000
3+++ tests/function.c 2009-09-21 20:29:20 +0000
4@@ -11,6 +11,7 @@
5 #include <sys/time.h>
6 #include <sys/types.h>
7 #include <sys/stat.h>
8+#include <signal.h>
9 #include <unistd.h>
10 #include <time.h>
11 #include "server.h"
12@@ -2457,6 +2458,105 @@
13 return 0;
14 }
15
16+/* Large mget() of missing keys with binary proto
17+ * See http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
18+ */
19+
20+void fail(int);
21+
22+static test_return _user_supplied_bug21(size_t key_count)
23+{
24+ memcached_return rc;
25+ unsigned int x;
26+ char **keys;
27+ size_t* key_lengths;
28+ void (*oldalarm)(int);
29+ memcached_st *memc;
30+
31+ key_lengths = malloc(sizeof(size_t) * key_count);
32+
33+ memc= memcached_create(NULL);
34+ assert(memc);
35+
36+ /* only binproto uses getq for mget */
37+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
38+
39+ rc= memcached_server_add(memc, "localhost", 11221);
40+
41+ /* empty the cache to ensure misses (hence non-responses) */
42+ rc= memcached_flush(memc, 0);
43+ assert(rc == MEMCACHED_SUCCESS);
44+
45+ keys= (char **)malloc(sizeof(char *) * key_count);
46+ assert(keys);
47+ memset(keys, 0, (sizeof(char *) * key_count));
48+ for (x= 0; x < key_count; x++)
49+ {
50+ char buffer[30];
51+
52+ snprintf(buffer, 30, "%u", x);
53+ keys[x]= strdup(buffer);
54+ key_lengths[x]= strlen(keys[x]);
55+ }
56+
57+ oldalarm = signal(SIGALRM, fail);
58+ alarm(5);
59+
60+ rc= memcached_mget(memc, (const char **)keys, key_lengths, key_count);
61+ assert(rc == MEMCACHED_SUCCESS);
62+
63+ alarm(0);
64+ signal(SIGALRM, oldalarm);
65+
66+ /* Turn this into a help function */
67+ {
68+ char return_key[MEMCACHED_MAX_KEY];
69+ size_t return_key_length;
70+ char *return_value;
71+ size_t return_value_length;
72+ uint32_t flags;
73+
74+ while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
75+ &return_value_length, &flags, &rc)))
76+ {
77+ assert(return_value);
78+ assert(rc == MEMCACHED_SUCCESS);
79+ free(return_value);
80+ }
81+ }
82+
83+ for (x= 0; x < key_count; x++)
84+ free(keys[x]);
85+ free(keys);
86+
87+ memcached_free(memc);
88+
89+ free(key_lengths);
90+
91+ return MEMCACHED_SUCCESS;
92+}
93+
94+static test_return user_supplied_bug21(memcached_st *trash)
95+{
96+ (void)trash;
97+ memcached_return rc;
98+
99+ /* should work as of r580 */
100+ rc = _user_supplied_bug21(10);
101+ assert(rc == MEMCACHED_SUCCESS);
102+
103+ /* should fail as of r580 */
104+ rc = _user_supplied_bug21(1000);
105+ assert(rc == MEMCACHED_SUCCESS);
106+
107+ return MEMCACHED_SUCCESS;
108+}
109+
110+void fail(int unused __attribute__((unused)))
111+{
112+ assert(0);
113+}
114+
115 static test_return auto_eject_hosts(memcached_st *trash)
116 {
117 (void) trash;
118@@ -4526,6 +4626,7 @@
119 {"user_supplied_bug18", 1, user_supplied_bug18 },
120 {"user_supplied_bug19", 1, user_supplied_bug19 },
121 {"user_supplied_bug20", 1, user_supplied_bug20 },
122+ {"user_supplied_bug21", 0, user_supplied_bug21 },
123 {0, 0, 0}
124 };
125

Subscribers

People subscribed via source and target branches

to all changes: