From f258edcbc59cc6b996b863d0a514970064223d04 Mon Sep 17 00:00:00 2001 From: chip Date: Thu, 28 Feb 2013 18:59:55 -0800 Subject: [PATCH] Re-enable millisecond mysql timeouts --- hphp/test/test_ext_mysql.cpp | 38 ++++++++++++++++++++++++++++++++++++ hphp/test/test_ext_mysql.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/hphp/test/test_ext_mysql.cpp b/hphp/test/test_ext_mysql.cpp index 74a1b84d2..024cc8c16 100644 --- a/hphp/test/test_ext_mysql.cpp +++ b/hphp/test/test_ext_mysql.cpp @@ -18,6 +18,7 @@ #include #include #include +#include /////////////////////////////////////////////////////////////////////////////// @@ -51,6 +52,9 @@ bool TestExtMysql::RunTests(const std::string &which) { RUN_TEST(test_mysql_drop_db); RUN_TEST(test_mysql_affected_rows); RUN_TEST(test_mysql_set_timeout); +#ifdef MYSQL_MILLISECOND_TIMEOUT + RUN_TEST(test_mysql_subsecond_timeout); +#endif RUN_TEST(test_mysql_query); RUN_TEST(test_mysql_unbuffered_query); RUN_TEST(test_mysql_db_query); @@ -271,6 +275,40 @@ bool TestExtMysql::test_mysql_set_timeout() { return Count(true); } +#ifdef MYSQL_MILLISECOND_TIMEOUT + +// A random and hopefully unroutable and/or distant address. +#define UNROUTABLE_DESTINATION "10.76.184.41:1" + +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); +} +#endif + bool TestExtMysql::test_mysql_query() { Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD); VERIFY(CreateTestTable()); diff --git a/hphp/test/test_ext_mysql.h b/hphp/test/test_ext_mysql.h index 2407f7512..744ec9e14 100644 --- a/hphp/test/test_ext_mysql.h +++ b/hphp/test/test_ext_mysql.h @@ -51,6 +51,9 @@ class TestExtMysql : public TestCppExt { bool test_mysql_drop_db(); bool test_mysql_affected_rows(); bool test_mysql_set_timeout(); +#ifdef MYSQL_MILLISECOND_TIMEOUT + bool test_mysql_subsecond_timeout(); +#endif bool test_mysql_query(); bool test_mysql_unbuffered_query(); bool test_mysql_db_query();