Suggested change from Antony
[awesomized/libmemcached] / tests / function.c
index 771178267b1d06c2fe29506605597f0b425cb39b..f21cb684a737cc7fff1d6e1c7db5f2b56faf7407 100644 (file)
@@ -341,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;
@@ -1379,6 +1389,7 @@ uint8_t user_supplied_bug9(memcached_st *memc)
                       &return_value_length, &flags, &rc)) != NULL)
   {
     assert(return_value);
+    free(return_value);
     count++;
   }
   assert(count == 3);
@@ -1386,6 +1397,7 @@ uint8_t user_supplied_bug9(memcached_st *memc)
   return 0;
 }
 
+/* We are testing with aggressive timeout to get failures */
 uint8_t user_supplied_bug10(memcached_st *memc)
 {
   char *key= "foo";
@@ -1396,9 +1408,12 @@ uint8_t user_supplied_bug10(memcached_st *memc)
   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));
 
@@ -1421,6 +1436,49 @@ uint8_t user_supplied_bug10(memcached_st *memc)
   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;
@@ -1882,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 },
@@ -1918,6 +1981,7 @@ test_st user_tests[] ={
   {"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}
 };
 
@@ -1952,6 +2016,7 @@ collection_st collection[] ={
   {"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},