From 25a5ea1465fa7ff2b5d841326edbaf932edae243 Mon Sep 17 00:00:00 2001 From: Ramil Valitov Date: Tue, 7 Jul 2020 15:17:58 +0300 Subject: [PATCH] [add] run duration test --- tests/all.sh | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/tests/all.sh b/tests/all.sh index de6089f..9509449 100644 --- a/tests/all.sh +++ b/tests/all.sh @@ -18,6 +18,15 @@ function restoreUserParameters() { sudo cp "$TRAVIS_BUILD_DIR/zabbix/userparameter_php_fpm.conf" "$(sudo find /etc/zabbix/ -name 'zabbix_agentd*.d' -type d | head -n1)" } +function AddSleepToConfig() { + PARAMS_FILE=$(getUserParameters) + sudo sed -i 's#.*zabbix_php_fpm_discovery.*#UserParameter=php-fpm.discover[*],sudo /etc/zabbix/zabbix_php_fpm_discovery.sh sleep $1#' "$PARAMS_FILE" + echo "New UserParameter file:" + sudo cat "$PARAMS_FILE" + sudo service zabbix-agent restart + sleep 2 +} + copyPool() { ORIGINAL_FILE=$1 POOL_NAME=$2 @@ -260,15 +269,6 @@ testDiscoverScriptSleep() { assertTrue "No success stop checks detected" "[ $STOP_OK_COUNT -gt 0 ]" } -function AddSleepToConfig() { - PARAMS_FILE=$(getUserParameters) - sudo sed -i 's#.*zabbix_php_fpm_discovery.*#UserParameter=php-fpm.discover[*],sudo /etc/zabbix/zabbix_php_fpm_discovery.sh sleep $1#' "$PARAMS_FILE" - echo "New UserParameter file:" - sudo cat "$PARAMS_FILE" - sudo service zabbix-agent restart - sleep 2 -} - testZabbixDiscoverSleep() { #Add sleep AddSleepToConfig @@ -276,6 +276,31 @@ testZabbixDiscoverSleep() { testZabbixDiscoverReturnsData } +testDiscoverScriptRunDuration() { + START_TIME=$(date +%s%N) + DATA=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "debug" "sleep" "/php-fpm-status") + END_TIME=$(date +%s%N) + ELAPSED_TIME=$(echo "($END_TIME - $START_TIME)/1000000" | bc) + + echo "Elapsed time $ELAPSED_TIME ms" + + assertTrue "The script worked for too long" "[ $ELAPSED_TIME -lt 3000 ]" +} + +testZabbixDiscoverRunDuration() { + #Add sleep + AddSleepToConfig + + START_TIME=$(date +%s%N) + DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.discover["/php-fpm-status"]) + END_TIME=$(date +%s%N) + ELAPSED_TIME=$(echo "($END_TIME - $START_TIME)/1000000" | bc) + + echo "Elapsed time $ELAPSED_TIME ms" + + assertTrue "The script worked for too long" "[ $ELAPSED_TIME -lt 3000 ]" +} + testDiscoverScriptDoubleRun() { DATA_FIRST=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "debug" "sleep" "/php-fpm-status") DATA_SECOND=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "debug" "sleep" "/php-fpm-status")