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
=== modified file 'tests/function.c'
--- tests/function.c 2009-09-10 10:57:11 +0000
+++ tests/function.c 2009-09-21 20:29:20 +0000
@@ -11,6 +11,7 @@
11#include <sys/time.h>11#include <sys/time.h>
12#include <sys/types.h>12#include <sys/types.h>
13#include <sys/stat.h>13#include <sys/stat.h>
14#include <signal.h>
14#include <unistd.h>15#include <unistd.h>
15#include <time.h>16#include <time.h>
16#include "server.h"17#include "server.h"
@@ -2457,6 +2458,105 @@
2457 return 0;2458 return 0;
2458}2459}
24592460
2461/* Large mget() of missing keys with binary proto
2462 * See http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
2463 */
2464
2465void fail(int);
2466
2467static test_return _user_supplied_bug21(size_t key_count)
2468{
2469 memcached_return rc;
2470 unsigned int x;
2471 char **keys;
2472 size_t* key_lengths;
2473 void (*oldalarm)(int);
2474 memcached_st *memc;
2475
2476 key_lengths = malloc(sizeof(size_t) * key_count);
2477
2478 memc= memcached_create(NULL);
2479 assert(memc);
2480
2481 /* only binproto uses getq for mget */
2482 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
2483
2484 rc= memcached_server_add(memc, "localhost", 11221);
2485
2486 /* empty the cache to ensure misses (hence non-responses) */
2487 rc= memcached_flush(memc, 0);
2488 assert(rc == MEMCACHED_SUCCESS);
2489
2490 keys= (char **)malloc(sizeof(char *) * key_count);
2491 assert(keys);
2492 memset(keys, 0, (sizeof(char *) * key_count));
2493 for (x= 0; x < key_count; x++)
2494 {
2495 char buffer[30];
2496
2497 snprintf(buffer, 30, "%u", x);
2498 keys[x]= strdup(buffer);
2499 key_lengths[x]= strlen(keys[x]);
2500 }
2501
2502 oldalarm = signal(SIGALRM, fail);
2503 alarm(5);
2504
2505 rc= memcached_mget(memc, (const char **)keys, key_lengths, key_count);
2506 assert(rc == MEMCACHED_SUCCESS);
2507
2508 alarm(0);
2509 signal(SIGALRM, oldalarm);
2510
2511 /* Turn this into a help function */
2512 {
2513 char return_key[MEMCACHED_MAX_KEY];
2514 size_t return_key_length;
2515 char *return_value;
2516 size_t return_value_length;
2517 uint32_t flags;
2518
2519 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
2520 &return_value_length, &flags, &rc)))
2521 {
2522 assert(return_value);
2523 assert(rc == MEMCACHED_SUCCESS);
2524 free(return_value);
2525 }
2526 }
2527
2528 for (x= 0; x < key_count; x++)
2529 free(keys[x]);
2530 free(keys);
2531
2532 memcached_free(memc);
2533
2534 free(key_lengths);
2535
2536 return MEMCACHED_SUCCESS;
2537}
2538
2539static test_return user_supplied_bug21(memcached_st *trash)
2540{
2541 (void)trash;
2542 memcached_return rc;
2543
2544 /* should work as of r580 */
2545 rc = _user_supplied_bug21(10);
2546 assert(rc == MEMCACHED_SUCCESS);
2547
2548 /* should fail as of r580 */
2549 rc = _user_supplied_bug21(1000);
2550 assert(rc == MEMCACHED_SUCCESS);
2551
2552 return MEMCACHED_SUCCESS;
2553}
2554
2555void fail(int unused __attribute__((unused)))
2556{
2557 assert(0);
2558}
2559
2460static test_return auto_eject_hosts(memcached_st *trash)2560static test_return auto_eject_hosts(memcached_st *trash)
2461{2561{
2462 (void) trash;2562 (void) trash;
@@ -4526,6 +4626,7 @@
4526 {"user_supplied_bug18", 1, user_supplied_bug18 },4626 {"user_supplied_bug18", 1, user_supplied_bug18 },
4527 {"user_supplied_bug19", 1, user_supplied_bug19 },4627 {"user_supplied_bug19", 1, user_supplied_bug19 },
4528 {"user_supplied_bug20", 1, user_supplied_bug20 },4628 {"user_supplied_bug20", 1, user_supplied_bug20 },
4629 {"user_supplied_bug21", 0, user_supplied_bug21 },
4529 {0, 0, 0}4630 {0, 0, 0}
4530};4631};
45314632

Subscribers

People subscribed via source and target branches

to all changes: