Skip to content

Commit

Permalink
[FLINK-9380][tests] Do not delete logs on E2E test failure
Browse files Browse the repository at this point in the history
This closes apache#6289.
  • Loading branch information
deepaks4077 authored and zentol committed Jul 16, 2018
1 parent 010f665 commit 0777753
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
15 changes: 9 additions & 6 deletions flink-end-to-end-tests/test-scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,11 @@ export EXIT_CODE=0
echo "Flink dist directory: $FLINK_DIR"

TEST_ROOT=`pwd`
TEST_INFRA_DIR="$0"
TEST_INFRA_DIR=`dirname "$TEST_INFRA_DIR"`
TEST_INFRA_DIR="$END_TO_END_DIR/test-scripts/"
cd $TEST_INFRA_DIR
TEST_INFRA_DIR=`pwd`
cd $TEST_ROOT

# used to randomize created directories
export TEST_DATA_DIR=$TEST_INFRA_DIR/temp-test-directory-$(date +%S%N)
echo "TEST_DATA_DIR: $TEST_DATA_DIR"

function print_mem_use_osx {
declare -a mem_types=("active" "inactive" "wired down")
used=""
Expand Down Expand Up @@ -280,6 +275,12 @@ function check_logs_for_non_empty_out_files {
fi
}

function shutdown_all {
stop_cluster
tm_kill_all
jm_kill_all
}

function stop_cluster {
"$FLINK_DIR"/bin/stop-cluster.sh

Expand Down Expand Up @@ -536,10 +537,12 @@ function end_timer {

function clean_stdout_files {
rm ${FLINK_DIR}/log/*.out
echo "Deleted all stdout files under ${FLINK_DIR}/log/"
}

function clean_log_files {
rm ${FLINK_DIR}/log/*
echo "Deleted all files under ${FLINK_DIR}/log/"
}

# Expect a string to appear in the log files of the task manager before a given timeout
Expand Down
41 changes: 29 additions & 12 deletions flink-end-to-end-tests/test-scripts/test-runner-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ function run_test {
printf "\n==============================================================================\n"
printf "Running '${description}'\n"
printf "==============================================================================\n"

# used to randomize created directories
export TEST_DATA_DIR=$TEST_INFRA_DIR/temp-test-directory-$(date +%S%N)
echo "TEST_DATA_DIR: $TEST_DATA_DIR"

start_timer
${command}
exit_code="$?"
Expand All @@ -41,8 +46,8 @@ function run_test {
check_logs_for_exceptions
check_logs_for_non_empty_out_files

cleanup

# 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"
Expand All @@ -58,20 +63,32 @@ function run_test {
fi
fi

if [[ ${exit_code} != 0 ]]; then
if [[ ${exit_code} == 0 ]]; then
cleanup
else
exit "${exit_code}"
fi
}

# Shuts down the cluster and cleans up all temporary folders and files. Make sure to clean up even in case of failures.
# Shuts down cluster and reverts changes to cluster configs
function cleanup_proc {
shutdown_all
revert_default_config
}

# Cleans up all temporary folders and files
function cleanup_tmp_files {
clean_log_files

rm -rf ${TEST_DATA_DIR} 2> /dev/null
echo "Deleted ${TEST_DATA_DIR}"
}

# Shuts down the cluster and cleans up all temporary folders and files.
function cleanup {
stop_cluster
tm_kill_all
jm_kill_all
rm -rf $TEST_DATA_DIR 2> /dev/null
revert_default_config
clean_log_files
clean_stdout_files
cleanup_proc
cleanup_tmp_files
}

trap cleanup EXIT
trap cleanup SIGINT
trap cleanup_proc EXIT

0 comments on commit 0777753

Please sign in to comment.