From 7f7cb0a9829a64c655b7bd1fcdb3b04b26e86e26 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 10 Nov 2014 14:30:56 +0200 Subject: [PATCH] Switched from CPU time to real time in connection test. --- server/modules/routing/test/CMakeLists.txt | 2 +- server/modules/routing/test/testconnect.c | 118 ++++++++++++++++----- 2 files changed, 92 insertions(+), 28 deletions(-) diff --git a/server/modules/routing/test/CMakeLists.txt b/server/modules/routing/test/CMakeLists.txt index 62bdf06e8..2eedb914d 100644 --- a/server/modules/routing/test/CMakeLists.txt +++ b/server/modules/routing/test/CMakeLists.txt @@ -1,6 +1,6 @@ if(MYSQLCLIENT_FOUND) add_executable(testconnect testconnect.c) message(STATUS "Linking against: ${MYSQLCLIENT_LIBRARIES}") - target_link_libraries(testconnect ${MYSQLCLIENT_LIBRARIES} ssl crypto dl z m rt) + target_link_libraries(testconnect ${MYSQLCLIENT_LIBRARIES} ssl crypto dl z m rt pthread) add_test(NAME ReadConnRouterLoginTest COMMAND $ 10000 ${TEST_HOST} ${MASTER_PORT} ${TEST_HOST} ${TEST_PORT} 1.10) endif() \ No newline at end of file diff --git a/server/modules/routing/test/testconnect.c b/server/modules/routing/test/testconnect.c index 46a293e51..35c381c6d 100644 --- a/server/modules/routing/test/testconnect.c +++ b/server/modules/routing/test/testconnect.c @@ -4,24 +4,40 @@ #include #include #include +#include int main(int argc, char** argv) { MYSQL* server; - char *host; + char *host = NULL, *str_baseline = NULL,*str_test = NULL, *errmsg = NULL; unsigned int port; int rval, iterations,i; clock_t begin,end; - double baseline,test, ratio, result, minimum; + size_t offset; + struct timeval real_begin,real_end,real_baseline,real_test; + time_t time; + double baseline, test, ratio, result; if(argc < 7){ fprintf(stderr,"Usage: %s \n",argv[0]); - fprintf(stderr,"The ratio is measured as:\ntest CPU time / baseline CPU time\n"); + fprintf(stderr,"The ratio is measured as:\ntest time / baseline time\n"); fprintf(stderr,"The test fails if this ratio is exceeded.\n"); return 1; } + + ; + + if((str_baseline = calloc(256,sizeof(char))) == NULL){ + return 1; + } + + if((str_test = calloc(256,sizeof(char))) == NULL){ + free(str_baseline); + return 1; + } + iterations = atoi(argv[1]); host = strdup(argv[2]); port = atoi(argv[3]); @@ -35,24 +51,36 @@ int main(int argc, char** argv) /**Testing direct connection to master*/ printf("Connecting to MySQL server through %s:%d.\n",host,port); + gettimeofday(&real_begin,NULL); begin = clock(); + if((server = mysql_init(NULL)) == NULL){ + return 1; + } + + if(mysql_real_connect(server,host,"maxuser","maxpwd",NULL,port,NULL,0) == NULL){ + rval = 1; + printf( "Failed to connect to database: Error: %s\n", + mysql_error(server)); + goto report; + } + for(i = 0;i ratio){ - printf("Test failed: CPU time ratio was %f which exceeded the limit of %f.\n", result, ratio); - rval = 1; - }else{ - printf("Test passed: CPU time ratio was %f.\n",result); - } + printf("\nTest failed: Errors during test run.\n"); + + }else{ + + struct tm *tm; + time = real_baseline.tv_sec; + tm = localtime(&time); + offset = strftime(str_baseline,256*sizeof(char),"%S",tm); + sprintf(str_baseline + offset,".%06d",(int)real_baseline.tv_usec); + time = real_test.tv_sec; + tm = localtime(&time); + offset = strftime(str_test,256*sizeof(char),"%S",tm); + sprintf(str_test + offset,".%06d",(int)real_test.tv_usec); + + printf("\n\tCPU time in seconds\n\nDirect connection: %f\nThrough MaxScale: %f\n",baseline,test); + printf("\n\tReal time in seconds\n\nDirect connection: %s\nThrough MaxScale: %s\n",str_baseline,str_test); + + double base_res = real_baseline.tv_sec + (real_baseline.tv_usec / 1000000.0); + double test_res = real_test.tv_sec + (real_test.tv_usec / 1000000.0); + result = test_res/base_res; + + if(result > ratio){ + printf("\nTest failed: Time ratio was %f which exceeded the limit of %f.\n", result, ratio); + rval = 1; + }else{ + printf("\nTest passed: Time ratio was %f.\n",result); + } + } + free(str_baseline); + free(str_test); free(host); + free(errmsg); return rval; }