X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ffunction.c;h=f21cb684a737cc7fff1d6e1c7db5f2b56faf7407;hb=61006df5c199906f2d4f644bc2776d774756899a;hp=c42cc82baa940c44607a12406dbe6503e93615ef;hpb=5c17e733976d4ce6287a68205a30d87f58f71ce1;p=awesomized%2Flibmemcached diff --git a/tests/function.c b/tests/function.c index c42cc82b..f21cb684 100644 --- a/tests/function.c +++ b/tests/function.c @@ -318,12 +318,21 @@ uint8_t prepend_test(memcached_st *memc) return 0; } +/* + Set the value, then quit to make sure it is flushed. + Come back in and test that add fails. +*/ uint8_t add_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; char *value= "when we sanitize"; + rc= memcached_set(memc, key, strlen(key), + value, strlen(value), + (time_t)0, (uint16_t)0); + assert(rc == MEMCACHED_SUCCESS); + memcached_quit(memc); rc= memcached_add(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint16_t)0); @@ -332,6 +341,16 @@ uint8_t add_test(memcached_st *memc) return 0; } +uint8_t add_wrapper(memcached_st *memc) +{ + unsigned int x; + + for (x= 0; x < 10000; x++) + add_test(memc); + + return 0; +} + uint8_t replace_test(memcached_st *memc) { memcached_return rc; @@ -652,7 +671,7 @@ uint8_t mget_result_test(memcached_st *memc) while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL) assert(!results); - assert(rc == MEMCACHED_NOTFOUND); + assert(rc == MEMCACHED_END); for (x= 0; x < 3; x++) { @@ -702,7 +721,7 @@ uint8_t mget_result_alloc_test(memcached_st *memc) assert(results); } assert(!results); - assert(rc == MEMCACHED_NOTFOUND); + assert(rc == MEMCACHED_END); for (x= 0; x < 3; x++) { @@ -758,7 +777,7 @@ uint8_t mget_test(memcached_st *memc) } assert(!return_value); assert(return_value_length == 0); - assert(rc == MEMCACHED_NOTFOUND); + assert(rc == MEMCACHED_END); for (x= 0; x < 3; x++) { @@ -1215,13 +1234,16 @@ uint8_t user_supplied_bug6(memcached_st *memc) value= memcached_get(memc, keys[0], key_length[0], &value_length, &flags, &rc); assert(value == NULL); + assert(rc == MEMCACHED_NOTFOUND); rc= memcached_mget(memc, keys, key_length, 4); + assert(rc == MEMCACHED_SUCCESS); count= 0; while ((value= memcached_fetch(memc, return_key, &return_key_length, &value_length, &flags, &rc))) count++; assert(count == 0); + assert(rc == MEMCACHED_END); for (x= 0; x < 4; x++) { @@ -1231,7 +1253,7 @@ uint8_t user_supplied_bug6(memcached_st *memc) assert(rc == MEMCACHED_SUCCESS); } - for (x= 0; x < 10; x++) + for (x= 0; x < 2; x++) { value= memcached_get(memc, keys[0], key_length[0], &value_length, &flags, &rc); @@ -1239,14 +1261,17 @@ uint8_t user_supplied_bug6(memcached_st *memc) free(value); rc= memcached_mget(memc, keys, key_length, 4); + assert(rc == MEMCACHED_SUCCESS); count= 3; /* We test for purge of partial complete fetches */ for (count= 3; count; count--) { value= memcached_fetch(memc, return_key, &return_key_length, &value_length, &flags, &rc); - free(value); assert(rc == MEMCACHED_SUCCESS); + assert(!(memcmp(value, insert_data, value_length))); + assert(value_length); + free(value); } } @@ -1328,6 +1353,132 @@ uint8_t user_supplied_bug7(memcached_st *memc) return 0; } +uint8_t user_supplied_bug9(memcached_st *memc) +{ + memcached_return rc; + char *keys[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"}; + size_t key_length[3]; + unsigned int x; + uint16_t flags; + unsigned count= 0; + + char return_key[MEMCACHED_MAX_KEY]; + size_t return_key_length; + char *return_value; + size_t return_value_length; + + + key_length[0]= strlen("UDATA:edevil@sapo.pt"); + key_length[1]= strlen("fudge&*@#"); + key_length[2]= strlen("for^#@&$not"); + + + for (x= 0; x < 3; x++) + { + rc= memcached_set(memc, keys[x], key_length[x], + keys[x], key_length[x], + (time_t)50, (uint16_t)9); + assert(rc == MEMCACHED_SUCCESS); + } + + rc= memcached_mget(memc, keys, key_length, 3); + assert(rc == MEMCACHED_SUCCESS); + + /* We need to empty the server before continueing test */ + while ((return_value= memcached_fetch(memc, return_key, &return_key_length, + &return_value_length, &flags, &rc)) != NULL) + { + assert(return_value); + free(return_value); + count++; + } + assert(count == 3); + + return 0; +} + +/* We are testing with aggressive timeout to get failures */ +uint8_t user_supplied_bug10(memcached_st *memc) +{ + char *key= "foo"; + char *value; + size_t value_length= 512; + unsigned int x; + int key_len= 3; + memcached_return rc; + unsigned int set= 1; + memcached_st *mclone= memcached_clone(NULL, memc); + int32_t timeout; + + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, &set); + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set); + timeout= 2; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout); + + value = (char*)malloc(value_length * sizeof(char)); + + for (x= 0; x < value_length; x++) + value[x]= (char) (x % 127); + + for (x= 1; x <= 100000; ++x) + { + rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0); + + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_WRITE_FAILURE); + + if (rc == MEMCACHED_WRITE_FAILURE) + x--; + } + + free(value); + memcached_free(mclone); + + return 0; +} + +/* + We are looking failures in the async protocol +*/ +uint8_t user_supplied_bug11(memcached_st *memc) +{ + char *key= "foo"; + char *value; + size_t value_length= 512; + unsigned int x; + int key_len= 3; + memcached_return rc; + unsigned int set= 1; + int32_t timeout; + memcached_st *mclone= memcached_clone(NULL, memc); + + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, &set); + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set); + timeout= -1; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout); + + timeout= (int32_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); + + assert(timeout == -1); + + value = (char*)malloc(value_length * sizeof(char)); + + for (x= 0; x < value_length; x++) + value[x]= (char) (x % 127); + + for (x= 1; x <= 100000; ++x) + { + rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0); + + WATCHPOINT_IFERROR(rc); + //assert(rc == MEMCACHED_SUCCESS); + } + + free(value); + memcached_free(mclone); + + return 0; +} + uint8_t result_static(memcached_st *memc) { memcached_result_st result; @@ -1654,6 +1805,23 @@ memcached_return pre_hash_ketama(memcached_st *memc) return MEMCACHED_SUCCESS; } +memcached_return enable_consistent(memcached_st *memc) +{ + memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT; + memcached_hash hash; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, &value); + pre_hsieh(memc); + + value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION); + assert(value == MEMCACHED_DISTRIBUTION_CONSISTENT); + + hash= (memcached_hash)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH); + assert(hash == MEMCACHED_HASH_HSIEH); + + + return MEMCACHED_SUCCESS; +} + memcached_return enable_cas(memcached_st *memc) { unsigned int set= 1; @@ -1751,7 +1919,7 @@ test_st tests[] ={ {"set", 0, set_test }, {"set2", 0, set_test2 }, {"set3", 0, set_test3 }, - {"add", 0, add_test }, + {"add", 1, add_test }, {"replace", 0, replace_test }, {"delete", 1, delete_test }, {"get", 1, get_test }, @@ -1772,6 +1940,11 @@ test_st tests[] ={ {0, 0, 0} }; +test_st async_tests[] ={ + {"add", 1, add_wrapper }, + {0, 0, 0} +}; + test_st string_tests[] ={ {"string static with null", 0, string_static_null }, {"string alloc with null", 0, string_alloc_null }, @@ -1806,6 +1979,9 @@ test_st user_tests[] ={ {"user_supplied_bug6", 1, user_supplied_bug6 }, {"user_supplied_bug7", 1, user_supplied_bug7 }, {"user_supplied_bug8", 1, user_supplied_bug8 }, + {"user_supplied_bug9", 1, user_supplied_bug9 }, + {"user_supplied_bug10", 1, user_supplied_bug10 }, + {"user_supplied_bug11", 1, user_supplied_bug11 }, {0, 0, 0} }; @@ -1835,13 +2011,17 @@ collection_st collection[] ={ {"unix_socket_nodelay", pre_nodelay, 0, tests}, {"poll_timeout", poll_timeout, 0, tests}, {"gets", enable_cas, 0, tests}, + {"consistent", enable_consistent, 0, tests}, // {"udp", pre_udp, 0, tests}, {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3}, {"string", 0, 0, string_tests}, {"result", 0, 0, result_tests}, + {"async", pre_nonblock, 0, async_tests}, {"user", 0, 0, user_tests}, {"generate", 0, 0, generate_tests}, {"generate_hsieh", pre_hsieh, 0, generate_tests}, + {"generate_hsieh_consistent", enable_consistent, 0, generate_tests}, + {"generate_md5", pre_md5, 0, generate_tests}, {"generate_nonblock", pre_nonblock, 0, generate_tests}, {0, 0, 0, 0} };