~brianaker/libmemcached/1164440

« back to all changes in this revision

Viewing changes to tests/mem_functions.cc

Merge in updates for server failure testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
422
422
  return TEST_SUCCESS;
423
423
}
424
424
 
425
 
static test_return_t error_test(memcached_st *memc)
 
425
static test_return_t memcached_return_t_TEST(memcached_st *memc)
426
426
{
427
427
  uint32_t values[] = { 851992627U, 2337886783U, 4109241422U, 4001849190U,
428
428
                        982370485U, 1263635348U, 4242906218U, 3829656100U,
435
435
                        54481931U, 4186304426U, 1741088401U, 2979625118U,
436
436
                        4159057246U, 3425930182U, 2593724503U,  1868899624U,
437
437
                        1769812374U, 2302537950U, 1110330676U, 3365377466U, 
438
 
                        1336171666U, 3021258493U, 2334992265U, 3365377466U };
 
438
                        1336171666U, 3021258493U, 2334992265U, 3861994737U, 
 
439
                        3365377466U };
439
440
 
440
441
  // You have updated the memcache_error messages but not updated docs/tests.
441
442
  for (int rc= int(MEMCACHED_SUCCESS); rc < int(MEMCACHED_MAXIMUM_RETURN); ++rc)
446
447
                                            MEMCACHED_HASH_JENKINS);
447
448
    if (values[rc] != hash_val)
448
449
    {
449
 
      fprintf(stderr, "\n\nYou have updated memcached_return_t without updating the error_test\n");
 
450
      fprintf(stderr, "\n\nYou have updated memcached_return_t without updating the memcached_return_t_TEST\n");
450
451
      fprintf(stderr, "%u, %s, (%u)\n\n", (uint32_t)rc, memcached_strerror(memc, memcached_return_t(rc)), hash_val);
451
452
    }
452
453
    test_compare(values[rc], hash_val);
453
454
  }
454
 
  test_compare(47, int(MEMCACHED_MAXIMUM_RETURN));
 
455
  test_compare(48, int(MEMCACHED_MAXIMUM_RETURN));
455
456
 
456
457
  return TEST_SUCCESS;
457
458
}
1522
1523
                                                      test_literal_param("number"),
1523
1524
                                                      1, &new_number));
1524
1525
  test_compare(uint64_t(2), new_number);
 
1526
  memcached_free(memc);
1525
1527
 
1526
1528
  return TEST_SUCCESS;
1527
1529
}
2614
2616
/* We are testing with aggressive timeout to get failures */
2615
2617
static test_return_t user_supplied_bug10(memcached_st *memc)
2616
2618
{
2617
 
  const char *key= "foo";
2618
2619
  size_t value_length= 512;
2619
 
  size_t key_len= 3;
2620
2620
  unsigned int set= 1;
2621
2621
  memcached_st *mclone= memcached_clone(NULL, memc);
2622
2622
 
2633
2633
 
2634
2634
  for (unsigned int x= 1; x <= 100000; ++x)
2635
2635
  {
2636
 
    memcached_return_t rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
 
2636
    memcached_return_t rc= memcached_set(mclone, 
 
2637
                                         test_literal_param("foo"),
 
2638
                                         value, value_length, 0, 0);
2637
2639
 
2638
 
    test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_BUFFERED or rc == MEMCACHED_TIMEOUT or rc == MEMCACHED_CONNECTION_FAILURE, 
 
2640
    test_true_got((rc == MEMCACHED_SUCCESS or rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_BUFFERED or rc == MEMCACHED_TIMEOUT or rc == MEMCACHED_CONNECTION_FAILURE 
 
2641
                  or rc == MEMCACHED_SERVER_TEMPORARILY_DISABLED), 
2639
2642
                  memcached_strerror(NULL, rc));
2640
2643
 
2641
2644
    if (rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_TIMEOUT)
3219
3222
  for (host_index= 0; host_index < SERVERS_TO_CREATE; host_index++)
3220
3223
  {
3221
3224
    /* This test was changes so that "make test" would work properlly */
3222
 
#ifdef DEBUG
3223
 
    memcached_server_instance_st instance=
3224
 
      memcached_server_instance_by_position(memc, host_index);
 
3225
    if (DEBUG)
 
3226
    {
 
3227
      memcached_server_instance_st instance=
 
3228
        memcached_server_instance_by_position(memc, host_index);
3225
3229
 
3226
 
    printf("\nserver %u|%s|%u bytes: %llu\n", host_index, instance->hostname, instance->port, (unsigned long long)(stat_p + host_index)->bytes);
3227
 
#endif
 
3230
      printf("\nserver %u|%s|%u bytes: %llu\n", host_index, instance->hostname, instance->port, (unsigned long long)(stat_p + host_index)->bytes);
 
3231
    }
3228
3232
    test_true((unsigned long long)(stat_p + host_index)->bytes);
3229
3233
  }
3230
3234
 
5259
5263
    {
5260
5264
      const char *msg=  memcached_strerror(memc, memcached_return_t(x));
5261
5265
      memcached_return_t ret= memcached_set(memc, msg, strlen(msg), NULL, 0, (time_t)0, (uint32_t)0);
5262
 
      test_compare_got(MEMCACHED_CONNECTION_FAILURE, ret, memcached_last_error_message(memc));
 
5266
      test_true_got((ret == MEMCACHED_CONNECTION_FAILURE or ret == MEMCACHED_SERVER_TEMPORARILY_DISABLED), memcached_last_error_message(memc));
5263
5267
 
5264
5268
      memcached_server_instance_st disconnected_server= memcached_server_get_last_disconnect(memc);
5265
5269
      test_true(disconnected_server);
5285
5289
  return TEST_SUCCESS;
5286
5290
}
5287
5291
 
5288
 
static test_return_t test_server_failure(memcached_st *memc)
5289
 
{
5290
 
  if (memcached_server_count(memc) < 2)
5291
 
    return TEST_SKIPPED;
5292
 
 
5293
 
  memcached_server_instance_st instance= memcached_server_instance_by_position(memc, 0);
5294
 
 
5295
 
  memcached_st *local_memc= memcached_create(NULL);
5296
 
 
5297
 
  memcached_server_add(local_memc, memcached_server_name(instance), memcached_server_port(instance));
5298
 
  memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, 2);
5299
 
 
5300
 
  uint32_t server_count= memcached_server_count(local_memc);
5301
 
  test_compare(1U, server_count);
5302
 
 
5303
 
  // Disable the server
5304
 
  instance= memcached_server_instance_by_position(local_memc, 0);
5305
 
  ((memcached_server_write_instance_st)instance)->server_failure_counter= 2;
5306
 
 
5307
 
  memcached_return_t rc;
5308
 
  test_compare_got(MEMCACHED_SERVER_MARKED_DEAD,
5309
 
                   rc= memcached_set(local_memc, "foo", strlen("foo"), NULL, 0, (time_t)0, (uint32_t)0),
5310
 
                   memcached_last_error_message(local_memc));
5311
 
 
5312
 
  ((memcached_server_write_instance_st)instance)->server_failure_counter= 0;
5313
 
  test_compare(MEMCACHED_SUCCESS,
5314
 
               memcached_set(local_memc, "foo", strlen("foo"), NULL, 0, (time_t)0, (uint32_t)0));
5315
 
#if 0
5316
 
  memcached_last_error_message(local_memc));
5317
 
#endif
5318
 
 
5319
 
 
5320
 
  memcached_free(local_memc);
5321
 
 
5322
 
  return TEST_SUCCESS;
5323
 
}
5324
 
 
5325
 
static test_return_t test_cull_servers(memcached_st *memc)
5326
 
{
5327
 
  uint32_t count= memcached_server_count(memc);
5328
 
 
5329
 
  if (count < 2)
5330
 
  {
5331
 
    return TEST_SKIPPED;
5332
 
  }
5333
 
 
5334
 
  // Do not do this in your code, it is not supported.
5335
 
  memc->servers[1].options.is_dead= true;
5336
 
  memc->state.is_time_for_rebuild= true;
5337
 
 
5338
 
  uint32_t new_count= memcached_server_count(memc);
5339
 
  test_compare(count, new_count);
5340
 
 
5341
 
#if 0
5342
 
  test_true(count == new_count + 1 );
5343
 
#endif
5344
 
 
5345
 
  return TEST_SUCCESS;
5346
 
}
5347
 
 
5348
5292
 
5349
5293
static memcached_return_t stat_printer(memcached_server_instance_st server,
5350
5294
                                       const char *key, size_t key_length,
5857
5801
  {"connection_test", false, (test_callback_fn*)connection_test},
5858
5802
  {"callback_test", false, (test_callback_fn*)callback_test},
5859
5803
  {"userdata_test", false, (test_callback_fn*)userdata_test},
5860
 
  {"error", false, (test_callback_fn*)error_test },
5861
5804
  {"set", false, (test_callback_fn*)set_test },
5862
5805
  {"set2", false, (test_callback_fn*)set_test2 },
5863
5806
  {"set3", false, (test_callback_fn*)set_test3 },
5903
5846
  {"memcached_pool_test", true, (test_callback_fn*)memcached_pool_test },
5904
5847
  {"test_get_last_disconnect", true, (test_callback_fn*)test_get_last_disconnect},
5905
5848
  {"verbosity", true, (test_callback_fn*)test_verbosity},
5906
 
  {"test_server_failure", true, (test_callback_fn*)test_server_failure},
5907
 
  {"cull_servers", true, (test_callback_fn*)test_cull_servers},
5908
5849
  {"memcached_stat_execute", true, (test_callback_fn*)memcached_stat_execute_test},
5909
5850
  {0, 0, 0}
5910
5851
};
5933
5874
  {"reset heap", true, (test_callback_fn*)basic_reset_heap_test},
5934
5875
  {"reset stack clone", true, (test_callback_fn*)basic_reset_stack_clone_test},
5935
5876
  {"reset heap clone", true, (test_callback_fn*)basic_reset_heap_clone_test},
 
5877
  {"memcached_return_t", false, (test_callback_fn*)memcached_return_t_TEST },
5936
5878
  {0, 0, 0}
5937
5879
};
5938
5880
 
6216
6158
  {"async", (test_callback_fn*)pre_nonblock, 0, async_tests},
6217
6159
  {"async(BINARY)", (test_callback_fn*)pre_nonblock_binary, 0, async_tests},
6218
6160
  {"Cal Haldenbrand's tests", 0, 0, haldenbrand_tests},
6219
 
  {"user", 0, 0, user_tests},
 
6161
  {"user written tests", 0, 0, user_tests},
6220
6162
  {"generate", 0, 0, generate_tests},
6221
6163
  {"generate_hsieh", (test_callback_fn*)pre_hsieh, 0, generate_tests},
6222
6164
  {"generate_ketama", (test_callback_fn*)pre_behavior_ketama, 0, generate_tests},