asfgit closed pull request #7023: [FLINK-10711] [e2e] Allow basic error
handling with bash
URL: https://github.com/apache/flink/pull/7023
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/flink-end-to-end-tests/README.md b/flink-end-to-end-tests/README.md
index 257298e3cce..025d927492f 100644
--- a/flink-end-to-end-tests/README.md
+++ b/flink-end-to-end-tests/README.md
@@ -47,6 +47,8 @@ In order to add a new test case you need add it to either
`test-scripts/run-nigh
_Note: If you want to parameterize your tests please do so by adding multiple
test cases with parameters as arguments to the nightly / pre-commit test
suites. This allows the test runner to do a cleanup in between each individual
test and also to fail those tests individually._
+_Note: While developing a new test case make sure to enable bash's error
handling in `test-scripts/test-runner-common.sh` by uncommenting `set -Eexuo
pipefail` and commenting the current default `set` call. If your test is
implemented properly, add `set -Eeuo pipefail` on the very top of your test
script (before any `common` script)._
+
### Passing your test
A test is considered to have passed if it:
- has exit code 0
diff --git a/flink-end-to-end-tests/test-scripts/common.sh
b/flink-end-to-end-tests/test-scripts/common.sh
index 4f628fc6d12..670090c2c41 100644
--- a/flink-end-to-end-tests/test-scripts/common.sh
+++ b/flink-end-to-end-tests/test-scripts/common.sh
@@ -17,8 +17,6 @@
# limitations under the License.
################################################################################
-set -o pipefail
-
if [[ -z $FLINK_DIR ]]; then
echo "FLINK_DIR needs to point to a Flink distribution directory"
exit 1
@@ -304,6 +302,7 @@ function start_and_wait_for_tm {
}
function check_logs_for_errors {
+ echo "Checking for errors..."
error_count=$(grep -rv "GroupCoordinatorNotAvailableException"
$FLINK_DIR/log \
| grep -v "RetriableCommitFailedException" \
| grep -v "NoAvailableBrokersException" \
@@ -320,15 +319,18 @@ function check_logs_for_errors {
| grep -v "java.lang.NoClassDefFoundError:
org/apache/hadoop/yarn/exceptions/YarnException" \
| grep -v "java.lang.NoClassDefFoundError:
org/apache/hadoop/conf/Configuration" \
| grep -v
"org.apache.flink.fs.shaded.hadoop3.org.apache.commons.beanutils.FluentPropertyBeanIntrospector
- Error when creating PropertyDescriptor for public final void
org.apache.flink.fs.shaded.hadoop3.org.apache.commons.configuration2.AbstractConfiguration.setProperty(java.lang.String,java.lang.Object)!
Ignoring this property." \
- | grep -ic "error")
+ | grep -ic "error" || true)
if [[ ${error_count} -gt 0 ]]; then
echo "Found error in log files:"
cat $FLINK_DIR/log/*
EXIT_CODE=1
+ else
+ echo "No errors in log files."
fi
}
function check_logs_for_exceptions {
+ echo "Checking for exceptions..."
exception_count=$(grep -rv "GroupCoordinatorNotAvailableException"
$FLINK_DIR/log \
| grep -v "RetriableCommitFailedException" \
| grep -v "NoAvailableBrokersException" \
@@ -348,19 +350,24 @@ function check_logs_for_exceptions {
| grep -v "java.io.InvalidClassException:
org.apache.flink.formats.avro.typeutils.AvroSerializer" \
| grep -v "Caused by: java.lang.Exception: JobManager is shutting down" \
| grep -v "java.lang.Exception: Artificial failure" \
- | grep -ic "exception")
+ | grep -ic "exception" || true)
if [[ ${exception_count} -gt 0 ]]; then
echo "Found exception in log files:"
cat $FLINK_DIR/log/*
EXIT_CODE=1
+ else
+ echo "No exceptions in log files."
fi
}
function check_logs_for_non_empty_out_files {
+ echo "Checking for non-empty .out files..."
if grep -ri "." $FLINK_DIR/log/*.out > /dev/null; then
echo "Found non-empty .out files:"
cat $FLINK_DIR/log/*.out
EXIT_CODE=1
+ else
+ echo "No non-empty .out files."
fi
}
@@ -374,7 +381,9 @@ function stop_cluster {
"$FLINK_DIR"/bin/stop-cluster.sh
# stop zookeeper only if there are processes running
- if ! [ "`jps | grep 'FlinkZooKeeperQuorumPeer' | wc -l`" = "0" ]; then
+ zookeeper_process_count=$(jps | grep -c 'FlinkZooKeeperQuorumPeer' || true)
+ if [[ ${zookeeper_process_count} -gt 0 ]]; then
+ echo "Stopping zookeeper..."
"$FLINK_DIR"/bin/zookeeper.sh stop
fi
}
@@ -489,9 +498,9 @@ function tm_kill_all {
# Kills all processes that match the given name.
function kill_all {
- local pid=`jps | grep -E "${1}" | cut -d " " -f 1`
- kill ${pid} 2> /dev/null
- wait ${pid} 2> /dev/null
+ local pid=`jps | grep -E "${1}" | cut -d " " -f 1 || true`
+ kill ${pid} 2> /dev/null || true
+ wait ${pid} 2> /dev/null || true
}
function kill_random_taskmanager {
diff --git a/flink-end-to-end-tests/test-scripts/elasticsearch-common.sh
b/flink-end-to-end-tests/test-scripts/elasticsearch-common.sh
index 834e84528b3..3d64b31b897 100644
--- a/flink-end-to-end-tests/test-scripts/elasticsearch-common.sh
+++ b/flink-end-to-end-tests/test-scripts/elasticsearch-common.sh
@@ -17,8 +17,6 @@
# limitations under the License.
################################################################################
-set -o pipefail
-
if [[ -z $TEST_DATA_DIR ]]; then
echo "Must run common.sh before elasticsearch-common.sh."
exit 1
diff --git a/flink-end-to-end-tests/test-scripts/kafka-common.sh
b/flink-end-to-end-tests/test-scripts/kafka-common.sh
index dedfe5208b1..5f8f65ec251 100644
--- a/flink-end-to-end-tests/test-scripts/kafka-common.sh
+++ b/flink-end-to-end-tests/test-scripts/kafka-common.sh
@@ -17,10 +17,6 @@
# limitations under the License.
################################################################################
-set -e
-set -u
-set -o pipefail
-
if [[ -z $TEST_DATA_DIR ]]; then
echo "Must run common.sh before kafka-common.sh."
exit 1
diff --git a/flink-end-to-end-tests/test-scripts/test-runner-common.sh
b/flink-end-to-end-tests/test-scripts/test-runner-common.sh
index 0e56d2ac250..9d6bd972f09 100644
--- a/flink-end-to-end-tests/test-scripts/test-runner-common.sh
+++ b/flink-end-to-end-tests/test-scripts/test-runner-common.sh
@@ -17,6 +17,10 @@
# limitations under the License.
################################################################################
+# Enable this line when developing a new end-to-end test
+#set -Eexuo pipefail
+set -o pipefail
+
source "${END_TO_END_DIR}"/test-scripts/common.sh
#######################################
@@ -29,7 +33,7 @@ source "${END_TO_END_DIR}"/test-scripts/common.sh
function run_test {
local description="$1"
local command="$2"
- local skip_check_exceptions="$3"
+ local skip_check_exceptions=${3:-}
printf
"\n==============================================================================\n"
printf "Running '${description}'\n"
@@ -39,32 +43,51 @@ function run_test {
export TEST_DATA_DIR=$TEST_INFRA_DIR/temp-test-directory-$(date +%S%N)
echo "TEST_DATA_DIR: $TEST_DATA_DIR"
+ export DESCRIPTION="$description"
+ export SKIP_CHECK_EXCEPTIONS="$skip_check_exceptions"
+
backup_config
start_timer
+
+ function test_error() {
+ echo "[FAIL] Test script contains errors."
+ post_test_validation 1
+ }
+ trap 'test_error' ERR
+
${command}
exit_code="$?"
- time_elapsed=$(end_timer)
+ post_test_validation ${exit_code}
+}
+
+# Validates the test result and exit code after its execution.
+function post_test_validation {
+ local exit_code="$1"
- if [[ "${skip_check_exceptions}" != "skip_check_exceptions" ]]; then
+ local time_elapsed=$(end_timer)
+
+ if [[ "${SKIP_CHECK_EXCEPTIONS}" != "skip_check_exceptions" ]]; then
check_logs_for_errors
check_logs_for_exceptions
check_logs_for_non_empty_out_files
+ else
+ echo "Checking of logs skipped."
fi
# Investigate exit_code for failures of test executable as well as
EXIT_CODE for failures of the test.
# Do not clean up if either fails.
if [[ ${exit_code} == 0 ]]; then
if [[ ${EXIT_CODE} != 0 ]]; then
- printf "\n[FAIL] '${description}' failed after ${time_elapsed}!
Test exited with exit code 0 but the logs contained errors, exceptions or
non-empty .out files\n\n"
+ printf "\n[FAIL] '${DESCRIPTION}' failed after ${time_elapsed}!
Test exited with exit code 0 but the logs contained errors, exceptions or
non-empty .out files\n\n"
exit_code=1
else
- printf "\n[PASS] '${description}' passed after ${time_elapsed}!
Test exited with exit code 0.\n\n"
+ printf "\n[PASS] '${DESCRIPTION}' passed after ${time_elapsed}!
Test exited with exit code 0.\n\n"
fi
else
if [[ ${EXIT_CODE} != 0 ]]; then
- printf "\n[FAIL] '${description}' failed after ${time_elapsed}!
Test exited with exit code ${exit_code} and the logs contained errors,
exceptions or non-empty .out files\n\n"
+ printf "\n[FAIL] '${DESCRIPTION}' failed after ${time_elapsed}!
Test exited with exit code ${exit_code} and the logs contained errors,
exceptions or non-empty .out files\n\n"
else
- printf "\n[FAIL] '${description}' failed after ${time_elapsed}!
Test exited with exit code ${exit_code}\n\n"
+ printf "\n[FAIL] '${DESCRIPTION}' failed after ${time_elapsed}!
Test exited with exit code ${exit_code}\n\n"
fi
fi
diff --git a/flink-end-to-end-tests/test-scripts/test_streaming_kafka.sh
b/flink-end-to-end-tests/test-scripts/test_streaming_kafka.sh
index c5cdfde3dc0..044d2237988 100755
--- a/flink-end-to-end-tests/test-scripts/test_streaming_kafka.sh
+++ b/flink-end-to-end-tests/test-scripts/test_streaming_kafka.sh
@@ -17,9 +17,7 @@
# limitations under the License.
################################################################################
-set -e
-set -u
-set -o pipefail
+set -Eeuo pipefail
source "$(dirname "$0")"/common.sh
source "$(dirname "$0")"/kafka-common.sh 2.0.0 5.0.0 5.0
diff --git a/flink-end-to-end-tests/test-scripts/test_streaming_kafka010.sh
b/flink-end-to-end-tests/test-scripts/test_streaming_kafka010.sh
index ecd651448a9..a55b0bc33c6 100755
--- a/flink-end-to-end-tests/test-scripts/test_streaming_kafka010.sh
+++ b/flink-end-to-end-tests/test-scripts/test_streaming_kafka010.sh
@@ -17,6 +17,8 @@
# limitations under the License.
################################################################################
+set -Eeuo pipefail
+
source "$(dirname "$0")"/common.sh
source "$(dirname "$0")"/kafka-common.sh 0.10.2.0 3.2.0 3.2
diff --git a/flink-end-to-end-tests/test-scripts/test_streaming_kafka_common.sh
b/flink-end-to-end-tests/test-scripts/test_streaming_kafka_common.sh
index ff3adc158c7..0583638b3bc 100644
--- a/flink-end-to-end-tests/test-scripts/test_streaming_kafka_common.sh
+++ b/flink-end-to-end-tests/test-scripts/test_streaming_kafka_common.sh
@@ -17,10 +17,6 @@
# limitations under the License.
################################################################################
-set -e
-set -u
-set -o pipefail
-
KAFKA_EXAMPLE_JAR="$1"
setup_kafka_dist
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services