From 37ba4e29b13d5c8745d05b01051e4e9d97ee9e30 Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Sun, 9 Dec 2018 08:22:06 +0000 Subject: [PATCH] Moved integration tests to tests dir Signed-off-by: Janos SUTO --- tests/cases/05-smtp.inc | 69 +++++++++++++++++++++++++++++++++++++++ tests/cases/06-stress.inc | 21 ++++++++++++ tests/cases/07-dummy.inc | 8 +++++ tests/setup.inc | 36 ++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 tests/cases/05-smtp.inc create mode 100644 tests/cases/06-stress.inc create mode 100644 tests/cases/07-dummy.inc create mode 100644 tests/setup.inc diff --git a/tests/cases/05-smtp.inc b/tests/cases/05-smtp.inc new file mode 100644 index 00000000..e080b81d --- /dev/null +++ b/tests/cases/05-smtp.inc @@ -0,0 +1,69 @@ + +register_case "case1" + +case1() { + log $FUNCNAME "sending emails" + + setup + + "${SMTP_SOURCE_DIR}/smtp-source.py" -s $SMTP_HOST -r archive@cust1.acts.hu -p 25 -t 20 --dir "$EML_DIR/Inbox" --socket --no-counter + "${SMTP_SOURCE_DIR}/smtp-source.py" -s $SMTP_HOST -r archive@cust1.acts.hu -p 25 -t 20 --dir "$EML_DIR/Inbox2" --socket --no-counter + "${SMTP_SOURCE_DIR}/smtp-source.py" -s $SMTP_HOST -r archive@cust1.acts.hu -p 25 -t 20 --dir "$EML_DIR/Levelszemet" --socket --no-counter + "${SMTP_SOURCE_DIR}/smtp-source.py" -s $SMTP_HOST -r archive@cust1.acts.hu -p 25 -t 20 --dir "$EML_DIR/Levelszemet2" --socket --no-counter + "${SMTP_SOURCE_DIR}/smtp-source.py" -s $SMTP_HOST -r archive@cust1.acts.hu -p 25 -t 20 --dir "$EML_DIR/spam0" --socket --no-counter + "${SMTP_SOURCE_DIR}/smtp-source.py" -s $SMTP_HOST -r archive@cust1.acts.hu -p 25 -t 20 --dir "$EML_DIR/spam1" --socket --no-counter + "${SMTP_SOURCE_DIR}/smtp-source.py" -s $SMTP_HOST -r archive@cust1.acts.hu -p 25 -t 20 --dir "$EML_DIR/deduptest" --socket --no-counter + "${SMTP_SOURCE_DIR}/smtp-source.py" -s $SMTP_HOST -r archive@cust1.acts.hu extra@addr.ess another@extra.addr -p 25 -t 20 --dir "$EML_DIR/virus" --socket --no-counter + + + wait_until_emails_are_processed "piler1" 2995 + docker exec "piler1" su piler -c /usr/libexec/piler/indexer.delta.sh 2>/dev/null + + count_status_values 2995 2887 108 0 + + test_retrieved_messages_are_the_same "piler1" "piler" + + run_05_sphinx_tests +} + + +count_status_values() { + local container="piler1" + + log "$FUNCNAME" + + received=$(print_file_in_container "$container" "$LOG_FILE" | grep -c 'received:') || true + stored=$(print_file_in_container "$container" "$LOG_FILE" | grep -c status=stored) || true + discarded=$(print_file_in_container "$container" "$LOG_FILE" | grep -c status=discarded) || true + duplicate=$(print_file_in_container "$container" "$LOG_FILE" | grep -c status=duplicate) || true + + [[ $received -eq $1 ]] || set_verdict $RESULT_CRITICAL + [[ $stored -eq $2 ]] || set_verdict $RESULT_CRITICAL + [[ $discarded -eq $3 ]] || set_verdict $RESULT_CRITICAL + [[ $duplicate -eq $4 ]] || set_verdict $RESULT_CRITICAL +} + + +run_05_sphinx_tests() { + local container="piler1" + + log "$FUNCNAME" + + append_queries + + for i in $(seq 0 $((${#SEARCH_QUERIES[@]}-1)) ) + do + hits=$( run_sphinx_query "$container" "${SEARCH_QUERIES[$i]}" ) + echo $hits ${SEARCH_HITS[$i]} + done +} + + +append_queries() { + append_query "select * from main1,dailydelta1,delta1 WHERE MATCH('@subject budaörsi dc felmérés')" 9 + append_query "select * from main1,dailydelta1,delta1 WHERE MATCH('@from gruppi.hu')" 4 + append_query "select * from main1,dailydelta1,delta1 WHERE attachments > 0 AND MATCH('@subject spam ')" 85 + append_query "select * from main1,dailydelta1,delta1 WHERE attachments > 0 AND MATCH('@subject spam @attachment_types image')" 15 + append_query "select * from main1,dailydelta1,delta1 WHERE MATCH('@(subject,body) New Task TSK002*')" 29 + append_query "select * from main1,dailydelta1,delta1 WHERE MATCH('@subject \"virtualfax daily summary\" | \"adsl hibajegy\"')" 11 +} diff --git a/tests/cases/06-stress.inc b/tests/cases/06-stress.inc new file mode 100644 index 00000000..cb61e1dd --- /dev/null +++ b/tests/cases/06-stress.inc @@ -0,0 +1,21 @@ + +register_case "stress" + +stress() { + log $FUNCNAME "sending 10k emails" + + docker exec -i "piler1" cp /dev/null /var/log/syslog 2>/dev/null + + "${SMTP_SOURCE_DIR}/smtp-source.py" -s $SMTP_HOST -r archive@cust1.acts.hu -p 25 -t 20 --count 10000 --no-counter + + wait_until_emails_are_processed "piler1" 10000 + + log "running delta indexer" + docker exec -i "piler1" su piler -c /usr/libexec/piler/indexer.delta.sh 2>/dev/null + + log "running main indexer" + docker exec -i "piler1" su piler -c /usr/libexec/piler/indexer.main.sh 2>/dev/null + + log "running main index watcher" + docker exec -i "piler1" su piler -c /usr/libexec/piler/watch_sphinx_main_index.sh 2>/dev/null +} diff --git a/tests/cases/07-dummy.inc b/tests/cases/07-dummy.inc new file mode 100644 index 00000000..0064203e --- /dev/null +++ b/tests/cases/07-dummy.inc @@ -0,0 +1,8 @@ + +register_case "dummy" + +dummy() { + log $FUNCNAME + + setup +} diff --git a/tests/setup.inc b/tests/setup.inc new file mode 100644 index 00000000..31625831 --- /dev/null +++ b/tests/setup.inc @@ -0,0 +1,36 @@ +CONTAINERS=( "piler1" ) + +setup() { + destroy_containers + launch_containers + create_rules "piler1" +} + +launch_containers() { + docker run -d --net=piler --name piler1 -e PILER_HOST="cust1.acts.hu" -p 80:80 -p 25:25 "$docker_image" 2>/dev/null + wait_for_sleep_cycle_in_container "piler1" + + if [[ -v JENKINS_URL ]]; then + docker cp "${HOME}/telegraf.conf" piler1:/etc/telegraf/telegraf.conf 2>/dev/null + else + docker cp "${topdir}/secrets/telegraf.conf" piler1:/etc/telegraf/telegraf.conf 2>/dev/null + fi + + docker exec "piler1" sed -i 's/HOSTNAME/piler1/g' /etc/telegraf/telegraf.conf + docker exec "piler1" service telegraf start +} + +create_rules() { + local container="$1" + + echo 'echo "insert into domain (domain, mapped) values(\"fictive.com\",\"fictive.com\")"| mysql --defaults-file=/etc/piler/.my.cnf piler' | docker exec -i "$container" sh 2>/dev/null + + echo 'echo "insert into archiving_rule (subject) values (\"Android táblagép\")"| mysql --defaults-file=/etc/piler/.my.cnf piler'|docker exec -i "$container" sh 2>/dev/null + echo 'echo "insert into archiving_rule (\`from\`) values (\"@gmail.com\")"| mysql --defaults-file=/etc/piler/.my.cnf piler'|docker exec -i "$container" sh 2>/dev/null + echo 'echo "insert into archiving_rule (\`from\`,attachment_type, _attachment_size, attachment_size) values (\"finderis.co.ua\", \"image\", \">\", 100000)"|mysql --defaults-file=/etc/piler/.my.cnf piler'|docker exec -i "$container" sh 2>/dev/null + echo 'echo "insert into archiving_rule (\`to\`) values (\"undisclosed-recipients\")"|mysql --defaults-file=/etc/piler/.my.cnf piler'|docker exec -i "$container" sh 2>/dev/null + + echo 'echo "update user set password=\"\$6\$GKL00T\$8jqoFOe3PyAbOCLwKB7JwndwC.IinHrZRkdoQDZUc8vybZ88sA2qomlz5JceNif8fFpkGzZ03ilvQa7tqQx0v1\""| mysql --defaults-file=/etc/piler/.my.cnf piler'|docker exec -i "$container" sh 2>/dev/null + + docker exec "$container" /etc/init.d/rc.piler reload 2>/dev/null +}