tests/mem_functions.cc
/*
 * Test that ensures mget_execute does not end into recursive calls that finally fails
 */
Test that ensures mget_execute does not end into recursive calls that finally fails
Test that ensures mget_execute does not end into recursive calls that finally fails
static test_return_t regression_bug_490486(memcached_st *memc)
{
  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 1);
  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, 1000);
  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, 1);
  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 3600);
#ifdef __APPLE__
  return TEST_SKIPPED; 
#endif
  uint32_t number_of_hosts= memc->number_of_hosts;
  memc->number_of_hosts= 1;
  size_t max_keys= 20480;
  char **keys= (char **)calloc(max_keys, sizeof(char*));
  size_t *key_length= (size_t *)calloc(max_keys, sizeof(size_t));
  char blob[1024]= { 0 };
  for (size_t x= 0; x < max_keys; ++x)
  {
    char k[251];
    key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%lu", (unsigned long)x);
    keys[x]= strdup(k);
    test_true(keys[x]);
    memcached_return rc= memcached_set(memc, keys[x], key_length[x], blob, sizeof(blob), 0, 0);
    test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); 
  }
  {
    size_t counter= 0;
    memcached_execute_function callbacks[]= { &callback_counter };
    memcached_return_t rc= memcached_mget_execute(memc, (const char**)keys, key_length,
                                                  (size_t)max_keys, callbacks, &counter, 1);
    test_compare(MEMCACHED_SUCCESS, rc);
    char* the_value= NULL;
    char the_key[MEMCACHED_MAX_KEY];
    size_t the_key_length;
    size_t the_value_length;
    uint32_t the_flags;
    do {
      the_value= memcached_fetch(memc, the_key, &the_key_length, &the_value_length, &the_flags, &rc);
      if ((the_value!= NULL) && (rc == MEMCACHED_SUCCESS))
      {
        ++counter;
        free(the_value);
      }
    } while ( (the_value!= NULL) && (rc == MEMCACHED_SUCCESS));
    test_compare(MEMCACHED_END, rc);
    test_compare(counter, max_keys);
  }
  for (size_t x= 0; x < max_keys; ++x)
  {
    free(keys[x]);
  }
  free(keys);
  free(key_length);
  memc->number_of_hosts= number_of_hosts;
  return TEST_SUCCESS;
}
static test_return_t regression_bug_490486 ( memcached_st * memc ) { memcached_behavior_set ( memc , MEMCACHED_BEHAVIOR_BINARY_PROTOCOL , 1 ) ; memcached_behavior_set ( memc , MEMCACHED_BEHAVIOR_NO_BLOCK , 1 ) ; memcached_behavior_set ( memc , MEMCACHED_BEHAVIOR_POLL_TIMEOUT , 1000 ) ; memcached_behavior_set ( memc , MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT , 1 ) ; memcached_behavior_set ( memc , MEMCACHED_BEHAVIOR_RETRY_TIMEOUT , 3600 ) ; #ifdef __APPLE__ return TEST_SKIPPED ; #endif uint32_t number_of_hosts = memc -> number_of_hosts ; memc -> number_of_hosts = 1 ; size_t max_keys = 20480 ; char * * keys = ( char * * ) calloc ( max_keys , sizeof ( char * ) ) ; size_t * key_length = ( size_t * ) calloc ( max_keys , sizeof ( size_t ) ) ; char blob [ 1024 ] = { 0 } ; for ( size_t x = 0 ; x < max_keys ; ++ x ) { char k [ 251 ] ; key_length [ x ] = ( size_t ) snprintf ( k , sizeof ( k ) , " " , ( unsigned long ) x ) ; keys [ x ] = strdup ( k ) ; test_true ( keys [ x ] ) ; memcached_return rc = memcached_set ( memc , keys [ x ] , key_length [ x ] , blob , sizeof ( blob ) , 0 , 0 ) ; test_true ( rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED ) ; } { size_t counter = 0 ; memcached_execute_function callbacks [ ] = { & callback_counter } ; memcached_return_t rc = memcached_mget_execute ( memc , ( const char * * ) keys , key_length , ( size_t ) max_keys , callbacks , & counter , 1 ) ; test_compare ( MEMCACHED_SUCCESS , rc ) ; char * the_value = NULL ; char the_key [ MEMCACHED_MAX_KEY ] ; size_t the_key_length ; size_t the_value_length ; uint32_t the_flags ; do { the_value = memcached_fetch ( memc , the_key , & the_key_length , & the_value_length , & the_flags , & rc ) ; if ( ( the_value != NULL ) && ( rc == MEMCACHED_SUCCESS ) ) { ++ counter ; free ( the_value ) ; } } while ( ( the_value != NULL ) && ( rc == MEMCACHED_SUCCESS ) ) ; test_compare ( MEMCACHED_END , rc ) ; test_compare ( counter , max_keys ) ; } for ( size_t x = 0 ; x < max_keys ; ++ x ) { free ( keys [ x ] ) ; } free ( keys ) ; free ( key_length ) ; memc -> number_of_hosts = number_of_hosts ; return TEST_SUCCESS ; }
Test that ensures mget_execute does not end into recursive calls that finally fails
Test that ensures mget_execute does not end into recursive calls that finally fails
// My MAC can't handle this test /*
   * I only want to hit _one_ server so I know the number of requests I'm
   * sending in the pipeline.
   */ /* First add all of the items.. */ // MEMCACHED_TIMEOUT <-- hash been observed on OSX /* Try to get all of them with a large multiget */ /* Verify that we got all of the items */ /* Release all allocated resources */