Пример #1
0
static test_outcome run_test_with_siglongjmp(const test_suite suite, const test* test_case)
{
	int sigsetret;
	if (0 == test_case->test_case) {
		fprintf(stderr, "%s is a null test\n", current_test);
		return INVALID;
	}
	sigsetret = sigsetjmp(recovery_buffer, 1);
	VERBOSE_LOG("Test %s:%s checkpoint status %d\n", sigsetret);
	switch (sigsetret) { /* clean path */
		case 0:
			current_stage = SETUP;
			VERBOSE_LOG("Running %s:%s suite setup\n");
			suite.setup();
			VERBOSE_LOG("Running %s:%s setup\n");
			test_case->setup();
			current_stage = TEST;
			VERBOSE_LOG("Running %s:%s\n");
			test_case->test_case();
			current_stage = TEARDOWN;
			VERBOSE_LOG("Running %s:%s tear down\n");
			test_case->teardown();
			VERBOSE_LOG("Running %s:%s tear down\n");
			suite.teardown();
			return PASS;
			break;
		case SETUP:
			LOG_TEST_ERROR("Error in [%s:%s] during setup\n");
			sigsetret = sigsetjmp(recovery_buffer, 1);
			if (0 == sigsetret) {
				current_stage = TEARDOWN;
				VERBOSE_LOG("Running %s:%s setup failure tear down\n");
				test_case->teardown();
			}
			break;
		case TEST:
			LOG_TEST_ERROR("Test failure in [%s:%s] ***%s\n", TEST_OUTCOMES[FAIL]);
			sigsetret = sigsetjmp(recovery_buffer, 1);
			if (0 == sigsetret) {
				current_stage = TEARDOWN;
				VERBOSE_LOG("Running %s:%s test failure tear down\n");
				test_case->teardown();
			}
			return FAIL;
			break;
		case TEARDOWN:
			LOG_TEST_ERROR("Error in [%s:%s] during teardown\n");
			break;
		default:
			LOG_TEST_ERROR("Error in [%s:%s] with unknown failure type %u\n", sigsetret);
			break;
	}

	return UNRESOLVED;
}
Пример #2
0
bool TestExtMysql::test_mysql_subsecond_timeout() {
  struct timeval before;
  gettimeofday(&before, NULL);
  Variant conn = f_mysql_connect(UNROUTABLE_DESTINATION,
                                 TEST_USERNAME, TEST_PASSWORD,
                                 true, /* new_link */
                                 0, /* client flags */
                                 1, /* connect ms */
                                 1 /* query ms */);

  VS(conn, false);
  // CR_CONN_HOST_ERROR which is a client-generated timeout and what
  // libmysqlclient.so will generate.
  VS(f_mysql_errno(), CR_CONN_HOST_ERROR);

  // Verify our perceived timeout of 1ms wasn't turned into a 1s
  // timeout by checking that the entire connect took less than 10ms.
  struct timeval after;
  gettimeofday(&after, NULL);
  const size_t delta_usec = 1000 * 1000 * (after.tv_sec - before.tv_sec) +
    (after.tv_usec - before.tv_usec);
  if (delta_usec > 10 * 1000) {
    LOG_TEST_ERROR("mysql timeout took too long: %.2f ms", delta_usec / 1000.0);
    Count(false);
  }
  return Count(true);
}