ashb commented on a change in pull request #14531:
URL: https://github.com/apache/airflow/pull/14531#discussion_r586410651
##########
File path: scripts/ci/testing/ci_run_airflow_testing.sh
##########
@@ -170,5 +161,282 @@ do
echo
"**********************************************************************************************"
run_airflow_testing_in_docker "${@}"
+}
+
+
+# Cleans up Docker before test execution. System prune should clean all the
temporary/unnamed images
+# And left-over volumes
+function cleanup_docker() {
+ echo
+ echo "System-prune docker"
+ echo
+ docker system prune --force --volumes
+ echo
+ echo "Check available space"
+ echo
+ df --human
+ echo
+ echo "Check available memory"
+ echo
+ free --human
+}
+
+# Prints status of a parallel test type. Returns 0 if the test type is still
running, 1 otherwise
+#
+# $1 - Test type
+#
+# The test_pids variable should contain mapping of test types to pids
+# NOTE: It might be surprise that local variables (like test_pids) are visible
to called functions
+# But this is how local variables in bash work (by design).
+function print_test_type_status() {
+ local test_type=$1
+ local pid="${test_pids[${test_type}]}"
+ local log_file="${CACHE_TMP_FILE_DIR}/output-${test_type}.log"
+ if ps -p "${pid}" >/dev/null 2>/dev/null; then
+ if [[ ${TEST_SHOW_ALL_OUTPUT_LINES_AS_THEY_APPEAR} != "true" ]]; then
+ echo "${COLOR_BLUE}Test type ${test_type} in progress (last
${TEST_SHOW_OUTPUT_LINES} lines of the output shown).${COLOR_RESET}"
+ echo
+ tail -${TEST_SHOW_OUTPUT_LINES} "${log_file}"
+ echo
+ echo
+ fi
+ return 0
+ else
+ if wait "${pid}"; then
+ echo
+ echo "${COLOR_GREEN}Test type: ${test_type}
succeeded.${COLOR_RESET}"
+ echo
+ return 1
+ else
+ echo
+ echo "${COLOR_RED}Test type: ${test_type} failed.${COLOR_RESET}"
+ echo
+ return 1
+ fi
+ fi
+}
+
+# Prints status of all parallel test types. Returns 0 if any of the tests are
still running, 1 otherwise
+function print_all_test_types_status() {
+ local still_running="false"
+ local test_type
+ echo "${COLOR_YELLOW}Progress for all tests:
${COLOR_BLUE}${TEST_TYPES}${COLOR_RESET}"
+ echo
+ for test_type in ${TEST_TYPES}
+ do
+ if print_test_type_status "${test_type}" ; then
+ still_running="true"
+ fi
+ done
+ if [[ ${still_running} == "true" ]]; then
+ return 0
+ fi
+ return 1
+}
+
+# Starts all test types in parallel
+# TEST_TYPES - list of all test types (it's not an array, it is space-separate
list)
+# ${@} - additional arguments to pass to test execution
+function start_test_types_in_parallel() {
+ local test_type
+ local database_port
+ start_end::group_start "Starting parallel tests: ${TEST_TYPES}"
+ for test_type in ${TEST_TYPES}
+ do
+ # Grabbing a free random port to use for database forwarding
+ database_port="$(python -c 'import socket; s=socket.socket();
s.bind(("", 0)); print(s.getsockname()[1])')";
+ echo
+ echo "Grabbed database port for forwarding: ${database_port}"
+ log_file="${CACHE_TMP_FILE_DIR}/output-${test_type}.log"
+ TEST_TYPE=${test_type} MYSQL_HOST_PORT="${database_port}"
POSTGRES_HOST_PORT="${database_port}" \
+ run_single_test_type "${@}" >"${log_file}" 2>&1 &
Review comment:
Nice, I didn't know you could "background" a function call like this.
Curiously it appears that `$$` is "wrong" in such a case. (Doesn't affect
us, I was just testing this out):
```bash
function run_it {
echo $$ sub-started
sleep 10
echo $$ finished
}
echo $$ started
run_it &
pid=$!
echo wating for $pid
wait $pid
```
Outputs this:
```
410386 started
wating for 410387
410386 sub-started
410386 finished
```
##########
File path: scripts/ci/testing/ci_run_airflow_testing.sh
##########
@@ -170,5 +161,282 @@ do
echo
"**********************************************************************************************"
run_airflow_testing_in_docker "${@}"
+}
+
+
+# Cleans up Docker before test execution. System prune should clean all the
temporary/unnamed images
+# And left-over volumes
+function cleanup_docker() {
+ echo
+ echo "System-prune docker"
+ echo
+ docker system prune --force --volumes
+ echo
+ echo "Check available space"
+ echo
+ df --human
+ echo
+ echo "Check available memory"
+ echo
+ free --human
+}
+
+# Prints status of a parallel test type. Returns 0 if the test type is still
running, 1 otherwise
+#
+# $1 - Test type
+#
+# The test_pids variable should contain mapping of test types to pids
+# NOTE: It might be surprise that local variables (like test_pids) are visible
to called functions
+# But this is how local variables in bash work (by design).
+function print_test_type_status() {
+ local test_type=$1
+ local pid="${test_pids[${test_type}]}"
+ local log_file="${CACHE_TMP_FILE_DIR}/output-${test_type}.log"
+ if ps -p "${pid}" >/dev/null 2>/dev/null; then
+ if [[ ${TEST_SHOW_ALL_OUTPUT_LINES_AS_THEY_APPEAR} != "true" ]]; then
+ echo "${COLOR_BLUE}Test type ${test_type} in progress (last
${TEST_SHOW_OUTPUT_LINES} lines of the output shown).${COLOR_RESET}"
+ echo
+ tail -${TEST_SHOW_OUTPUT_LINES} "${log_file}"
+ echo
+ echo
+ fi
+ return 0
+ else
+ if wait "${pid}"; then
+ echo
+ echo "${COLOR_GREEN}Test type: ${test_type}
succeeded.${COLOR_RESET}"
+ echo
+ return 1
+ else
+ echo
+ echo "${COLOR_RED}Test type: ${test_type} failed.${COLOR_RESET}"
+ echo
+ return 1
+ fi
+ fi
+}
+
+# Prints status of all parallel test types. Returns 0 if any of the tests are
still running, 1 otherwise
+function print_all_test_types_status() {
+ local still_running="false"
+ local test_type
+ echo "${COLOR_YELLOW}Progress for all tests:
${COLOR_BLUE}${TEST_TYPES}${COLOR_RESET}"
+ echo
+ for test_type in ${TEST_TYPES}
+ do
+ if print_test_type_status "${test_type}" ; then
+ still_running="true"
+ fi
+ done
+ if [[ ${still_running} == "true" ]]; then
+ return 0
+ fi
+ return 1
+}
+
+# Starts all test types in parallel
+# TEST_TYPES - list of all test types (it's not an array, it is space-separate
list)
+# ${@} - additional arguments to pass to test execution
+function start_test_types_in_parallel() {
+ local test_type
+ local database_port
+ start_end::group_start "Starting parallel tests: ${TEST_TYPES}"
+ for test_type in ${TEST_TYPES}
+ do
+ # Grabbing a free random port to use for database forwarding
+ database_port="$(python -c 'import socket; s=socket.socket();
s.bind(("", 0)); print(s.getsockname()[1])')";
+ echo
+ echo "Grabbed database port for forwarding: ${database_port}"
+ log_file="${CACHE_TMP_FILE_DIR}/output-${test_type}.log"
+ TEST_TYPE=${test_type} MYSQL_HOST_PORT="${database_port}"
POSTGRES_HOST_PORT="${database_port}" \
+ run_single_test_type "${@}" >"${log_file}" 2>&1 &
+ pid=$!
+ echo "The process started for ${test_type}. Log file ${log_file}"
+ echo
+ test_pids[${test_type}]=${pid}
+ done
+ start_end::group_end
+}
+
+# Monitors progress of all test types running
+# TEST_TYPES - all test types to monitor
+# test_pids - map of test types to PIDs
+function monitor_test_types() {
+ start_end::group_start "Monitoring progress of running parallel tests:
${TEST_TYPES}"
+ while true;
+ do
+ sleep "${TEST_SLEEP_TIME}"
+ if ! print_all_test_types_status; then
+ break
+ fi
+ done
+ start_end::group_end
+}
+
+
+# Monitors progress of single test type running
+# $1 - test type to monitor
+# test_pids - map of test types to PIDs
+function monitor_sequential_test_type() {
+ local test_type=$1
+ start_end::group_start "Monitoring progress of running sequential test
type: $1"
+ while true;
+ do
+ sleep "${TEST_SLEEP_TIME}"
+ if ! print_test_type_status "${test_type}"; then
+ break
+ fi
+ done
+ start_end::group_end
+}
+
+# Checks status for all test types running. Returns 0 if any of the tests
failed (with the exception of
+# Quarantined test.
+#
+# TEST_TYPES - all test types to run
+# test_pids - map of test types to PIDs
+#
+# output:
+# successful_tests - array of test types that succeeded
+# failed_tests - array of test types that failed
+function check_test_types_status() {
+ start_end::group_start "Checking status for parallel tests: ${TEST_TYPES}"
+ local test_type_exit_code="0"
+ for test_type in "${!test_pids[@]}"; do
+ local pid="${test_pids[${test_type}]}"
+ wait "${pid}"
+ local temp_exit_code=$?
+ if [[ ${temp_exit_code} == "0" ]]; then
+ successful_tests+=("${test_type}")
+ else
+ failed_tests+=("${test_type}")
+ if [[ ${test_type} != "Quarantined" ]]; then
+ test_type_exit_code=${temp_exit_code}``
+ fi
+ fi
+ done
+ start_end::group_end
+ return "${test_type_exit_code}"
+}
+
+# Outputs logs for failed test type
+# $1 test type
+function output_log_for_failed_test_type(){
+ local failed_test_type=$1
+ local log_file="${CACHE_TMP_FILE_DIR}/output-${failed_test_type}.log"
+ start_end::group_start "${COLOR_RED}Output for failed ${failed_test_type}
from log: ${log_file}${COLOR_RESET}"
+ echo "${COLOR_RED}##### Test type ${failed_test_type} failed #####
${COLOR_RESET}"
+ echo
+ cat "${log_file}"
+ echo
+ echo "${COLOR_RED}##### Test type ${failed_test_type} failed #####
${COLOR_RESET}"
+ echo
+ start_end::group_end
+}
+
+function print_test_summary() {
+ if [[ ${#successful_tests[@]} != 0 ]]; then
+ echo
+ echo "${COLOR_GREEN}Successful test types: ${successful_tests[*]}
${COLOR_RESET}"
+ echo
+ fi
+ if [[ ${#failed_tests[@]} != 0 ]]; then
+ echo
+ echo "${COLOR_RED}Failed test types: ${failed_tests[*]}${COLOR_RESET}"
+ echo
+ for test_type in "${failed_tests[@]}"
+ do
+ output_log_for_failed_test_type "${test_type}"
+ done
+ fi
+}
+
+# Runs all test types in parallel, monitors their progress and summarizes the
result when finished.
+function run_all_test_types_in_parallel() {
+ local successful_tests=()
+ local failed_tests=()
+ local exit_code="0"
+ local log_file
+ local test_type
+ local test_pids
+ declare -A test_pids
+
+ start_end::group_start "Cleanup docker before parallel tests:
${TEST_TYPES}."
+ cleanup_docker
start_end::group_end
-done
+
+ start_test_types_in_parallel "${@}"
+
+ set +e
+ monitor_test_types
+
+ check_test_types_status
+ exit_code=$?
+ set -e
+ print_test_summary
+ return ${exit_code}
+}
+
+function run_all_test_types_sequentially() {
+ local exit_code="0"
+ local successful_tests=()
+ local failed_tests=()
+ local log_file
+ local test_type
+ local pid
+ local test_pids
+ declare -A test_pids
Review comment:
```suggestion
local -A test_pids
```
(or `declare -A test_pids`) We don't need both:
> When used in a function, declare and typeset make each name local, as with
the local command, unless the -g option is supplied.
##########
File path: .github/workflows/ci.yml
##########
@@ -35,6 +35,8 @@ env:
DB_RESET: "true"
VERBOSE: "true"
DOCKER_CACHE: "pulled"
+ # Do not show all output lines on CI. Only output of the failed tests will
be shown as a summary
+ TEST_SHOW_ALL_OUTPUT_LINES_AS_THEY_APPEAR: "false"
Review comment:
Do we want this configurable at all? If we are running a single test
(i.e. in sequential mode) then we still want output to show up, and if we are
running parallel tests then we can't have this and force it off anyway.
##########
File path: scripts/ci/testing/ci_run_airflow_testing.sh
##########
@@ -170,5 +161,282 @@ do
echo
"**********************************************************************************************"
run_airflow_testing_in_docker "${@}"
+}
+
+
+# Cleans up Docker before test execution. System prune should clean all the
temporary/unnamed images
+# And left-over volumes
+function cleanup_docker() {
+ echo
+ echo "System-prune docker"
+ echo
+ docker system prune --force --volumes
+ echo
+ echo "Check available space"
+ echo
+ df --human
+ echo
+ echo "Check available memory"
+ echo
+ free --human
+}
+
+# Prints status of a parallel test type. Returns 0 if the test type is still
running, 1 otherwise
+#
+# $1 - Test type
+#
+# The test_pids variable should contain mapping of test types to pids
+# NOTE: It might be surprise that local variables (like test_pids) are visible
to called functions
+# But this is how local variables in bash work (by design).
+function print_test_type_status() {
+ local test_type=$1
+ local pid="${test_pids[${test_type}]}"
+ local log_file="${CACHE_TMP_FILE_DIR}/output-${test_type}.log"
+ if ps -p "${pid}" >/dev/null 2>/dev/null; then
+ if [[ ${TEST_SHOW_ALL_OUTPUT_LINES_AS_THEY_APPEAR} != "true" ]]; then
+ echo "${COLOR_BLUE}Test type ${test_type} in progress (last
${TEST_SHOW_OUTPUT_LINES} lines of the output shown).${COLOR_RESET}"
+ echo
+ tail -${TEST_SHOW_OUTPUT_LINES} "${log_file}"
+ echo
+ echo
+ fi
+ return 0
+ else
+ if wait "${pid}"; then
+ echo
+ echo "${COLOR_GREEN}Test type: ${test_type}
succeeded.${COLOR_RESET}"
+ echo
+ return 1
+ else
+ echo
+ echo "${COLOR_RED}Test type: ${test_type} failed.${COLOR_RESET}"
+ echo
+ return 1
+ fi
+ fi
+}
+
+# Prints status of all parallel test types. Returns 0 if any of the tests are
still running, 1 otherwise
+function print_all_test_types_status() {
+ local still_running="false"
+ local test_type
+ echo "${COLOR_YELLOW}Progress for all tests:
${COLOR_BLUE}${TEST_TYPES}${COLOR_RESET}"
+ echo
+ for test_type in ${TEST_TYPES}
+ do
+ if print_test_type_status "${test_type}" ; then
+ still_running="true"
+ fi
+ done
+ if [[ ${still_running} == "true" ]]; then
+ return 0
+ fi
+ return 1
+}
+
+# Starts all test types in parallel
+# TEST_TYPES - list of all test types (it's not an array, it is space-separate
list)
+# ${@} - additional arguments to pass to test execution
+function start_test_types_in_parallel() {
+ local test_type
+ local database_port
+ start_end::group_start "Starting parallel tests: ${TEST_TYPES}"
+ for test_type in ${TEST_TYPES}
+ do
+ # Grabbing a free random port to use for database forwarding
+ database_port="$(python -c 'import socket; s=socket.socket();
s.bind(("", 0)); print(s.getsockname()[1])')";
+ echo
+ echo "Grabbed database port for forwarding: ${database_port}"
+ log_file="${CACHE_TMP_FILE_DIR}/output-${test_type}.log"
+ TEST_TYPE=${test_type} MYSQL_HOST_PORT="${database_port}"
POSTGRES_HOST_PORT="${database_port}" \
+ run_single_test_type "${@}" >"${log_file}" 2>&1 &
+ pid=$!
+ echo "The process started for ${test_type}. Log file ${log_file}"
+ echo
+ test_pids[${test_type}]=${pid}
+ done
+ start_end::group_end
+}
+
+# Monitors progress of all test types running
+# TEST_TYPES - all test types to monitor
+# test_pids - map of test types to PIDs
+function monitor_test_types() {
+ start_end::group_start "Monitoring progress of running parallel tests:
${TEST_TYPES}"
+ while true;
+ do
+ sleep "${TEST_SLEEP_TIME}"
+ if ! print_all_test_types_status; then
+ break
+ fi
+ done
+ start_end::group_end
+}
+
+
+# Monitors progress of single test type running
+# $1 - test type to monitor
+# test_pids - map of test types to PIDs
+function monitor_sequential_test_type() {
+ local test_type=$1
+ start_end::group_start "Monitoring progress of running sequential test
type: $1"
+ while true;
+ do
+ sleep "${TEST_SLEEP_TIME}"
+ if ! print_test_type_status "${test_type}"; then
+ break
+ fi
+ done
+ start_end::group_end
+}
+
+# Checks status for all test types running. Returns 0 if any of the tests
failed (with the exception of
+# Quarantined test.
+#
+# TEST_TYPES - all test types to run
+# test_pids - map of test types to PIDs
+#
+# output:
+# successful_tests - array of test types that succeeded
+# failed_tests - array of test types that failed
+function check_test_types_status() {
+ start_end::group_start "Checking status for parallel tests: ${TEST_TYPES}"
+ local test_type_exit_code="0"
+ for test_type in "${!test_pids[@]}"; do
+ local pid="${test_pids[${test_type}]}"
+ wait "${pid}"
+ local temp_exit_code=$?
+ if [[ ${temp_exit_code} == "0" ]]; then
+ successful_tests+=("${test_type}")
+ else
+ failed_tests+=("${test_type}")
+ if [[ ${test_type} != "Quarantined" ]]; then
+ test_type_exit_code=${temp_exit_code}``
+ fi
+ fi
+ done
+ start_end::group_end
+ return "${test_type_exit_code}"
+}
+
+# Outputs logs for failed test type
+# $1 test type
+function output_log_for_failed_test_type(){
+ local failed_test_type=$1
+ local log_file="${CACHE_TMP_FILE_DIR}/output-${failed_test_type}.log"
+ start_end::group_start "${COLOR_RED}Output for failed ${failed_test_type}
from log: ${log_file}${COLOR_RESET}"
+ echo "${COLOR_RED}##### Test type ${failed_test_type} failed #####
${COLOR_RESET}"
+ echo
+ cat "${log_file}"
+ echo
+ echo "${COLOR_RED}##### Test type ${failed_test_type} failed #####
${COLOR_RESET}"
+ echo
+ start_end::group_end
+}
+
+function print_test_summary() {
+ if [[ ${#successful_tests[@]} != 0 ]]; then
+ echo
+ echo "${COLOR_GREEN}Successful test types: ${successful_tests[*]}
${COLOR_RESET}"
+ echo
+ fi
+ if [[ ${#failed_tests[@]} != 0 ]]; then
+ echo
+ echo "${COLOR_RED}Failed test types: ${failed_tests[*]}${COLOR_RESET}"
+ echo
+ for test_type in "${failed_tests[@]}"
+ do
+ output_log_for_failed_test_type "${test_type}"
+ done
+ fi
+}
+
+# Runs all test types in parallel, monitors their progress and summarizes the
result when finished.
+function run_all_test_types_in_parallel() {
+ local successful_tests=()
+ local failed_tests=()
+ local exit_code="0"
+ local log_file
+ local test_type
+ local test_pids
+ declare -A test_pids
+
+ start_end::group_start "Cleanup docker before parallel tests:
${TEST_TYPES}."
+ cleanup_docker
start_end::group_end
-done
+
+ start_test_types_in_parallel "${@}"
+
+ set +e
+ monitor_test_types
+
+ check_test_types_status
+ exit_code=$?
+ set -e
+ print_test_summary
+ return ${exit_code}
+}
+
+function run_all_test_types_sequentially() {
+ local exit_code="0"
+ local successful_tests=()
+ local failed_tests=()
+ local log_file
+ local test_type
+ local pid
+ local test_pids
+ declare -A test_pids
+ for test_type in ${TEST_TYPES}
+ do
+ start_end::group_start "Cleanup docker before ${test_type} test"
+ cleanup_docker
+ start_end::group_end
+ start_end::group_start "Running tests ${test_type}"
+ log_file="${CACHE_TMP_FILE_DIR}/output-${test_type}.log"
+ TEST_TYPE=${test_type} run_single_test_type "${@}" >"${log_file}"
2>&1 &
+ pid=$!
+ echo "The process started for ${test_type}. Log file ${log_file}"
+ test_pids[${test_type}]=${pid}
+ if [[ ${TEST_SHOW_ALL_OUTPUT_LINES_AS_THEY_APPEAR} == "true" ]]; then
+ # If all output is to be shown, start a tail process to show the
logs
+ tail -f "${log_file}" &
+ fi
+ start_end::group_end
+ set +e
+ monitor_sequential_test_type "${test_type}"
+ wait "${pid}"
+ local temp_exit_code=$?
+ set -e
+ if [[ ${temp_exit_code} == "0" ]]; then
+ successful_tests+=("${test_type}")
+ else
+ if [[ ${test_type} != "Quarantined" ]]; then
+ exit_code=${temp_exit_code}
+ fi
+ failed_tests+=("${test_type}")
+ fi
+ done
+ print_test_summary
+ return ${exit_code}
+}
+
+build_images::prepare_ci_build
+
+build_images::rebuild_ci_image_if_needed_with_group
+
+prepare_tests_to_run
+
+RUN_TESTS="true"
+export RUN_TESTS
+
+if [[ ${RUN_TESTS_IN_PARALLEL} == "true" ]] ; then
+ if [[ ${TEST_SHOW_ALL_OUTPUT_LINES_AS_THEY_APPEAR} == "true" ]]; then
+ echo
+ echo "In case of parallel tests we cannot mis those output lines as
they appear. Disabling it!"
Review comment:
```suggestion
echo "In case of parallel tests we cannot show output lines as they
appear. Disabling it!"
```
##########
File path: tests/www/test_views.py
##########
@@ -1154,6 +1154,11 @@ def test_page_instance_name_xss_prevention(self):
class TestConfigurationView(TestBase):
+ def setUp(self):
+ super().setUp()
+ with mock.patch.dict(os.environ, {"AIRFLOW__CORE__UNIT_TEST_MODE":
"False"}):
+ initialize_config()
Review comment:
WWW tests right now are run in full isolation, and if I start a fresh
breeze container on master and run `pytest test/www/` it passes, so I don't
quite understand what you mean.
##########
File path: scripts/ci/testing/ci_run_airflow_testing.sh
##########
@@ -170,5 +161,282 @@ do
echo
"**********************************************************************************************"
run_airflow_testing_in_docker "${@}"
+}
+
+
+# Cleans up Docker before test execution. System prune should clean all the
temporary/unnamed images
+# And left-over volumes
+function cleanup_docker() {
+ echo
+ echo "System-prune docker"
+ echo
+ docker system prune --force --volumes
+ echo
+ echo "Check available space"
+ echo
+ df --human
+ echo
+ echo "Check available memory"
+ echo
+ free --human
+}
+
+# Prints status of a parallel test type. Returns 0 if the test type is still
running, 1 otherwise
+#
+# $1 - Test type
+#
+# The test_pids variable should contain mapping of test types to pids
+# NOTE: It might be surprise that local variables (like test_pids) are visible
to called functions
+# But this is how local variables in bash work (by design).
+function print_test_type_status() {
+ local test_type=$1
+ local pid="${test_pids[${test_type}]}"
+ local log_file="${CACHE_TMP_FILE_DIR}/output-${test_type}.log"
+ if ps -p "${pid}" >/dev/null 2>/dev/null; then
+ if [[ ${TEST_SHOW_ALL_OUTPUT_LINES_AS_THEY_APPEAR} != "true" ]]; then
+ echo "${COLOR_BLUE}Test type ${test_type} in progress (last
${TEST_SHOW_OUTPUT_LINES} lines of the output shown).${COLOR_RESET}"
+ echo
+ tail -${TEST_SHOW_OUTPUT_LINES} "${log_file}"
+ echo
+ echo
+ fi
+ return 0
+ else
+ if wait "${pid}"; then
+ echo
+ echo "${COLOR_GREEN}Test type: ${test_type}
succeeded.${COLOR_RESET}"
+ echo
+ return 1
+ else
+ echo
+ echo "${COLOR_RED}Test type: ${test_type} failed.${COLOR_RESET}"
+ echo
+ return 1
+ fi
+ fi
+}
+
+# Prints status of all parallel test types. Returns 0 if any of the tests are
still running, 1 otherwise
+function print_all_test_types_status() {
+ local still_running="false"
+ local test_type
+ echo "${COLOR_YELLOW}Progress for all tests:
${COLOR_BLUE}${TEST_TYPES}${COLOR_RESET}"
+ echo
+ for test_type in ${TEST_TYPES}
+ do
+ if print_test_type_status "${test_type}" ; then
+ still_running="true"
+ fi
+ done
+ if [[ ${still_running} == "true" ]]; then
+ return 0
+ fi
+ return 1
+}
+
+# Starts all test types in parallel
+# TEST_TYPES - list of all test types (it's not an array, it is space-separate
list)
+# ${@} - additional arguments to pass to test execution
+function start_test_types_in_parallel() {
+ local test_type
+ local database_port
+ start_end::group_start "Starting parallel tests: ${TEST_TYPES}"
+ for test_type in ${TEST_TYPES}
+ do
+ # Grabbing a free random port to use for database forwarding
+ database_port="$(python -c 'import socket; s=socket.socket();
s.bind(("", 0)); print(s.getsockname()[1])')";
+ echo
+ echo "Grabbed database port for forwarding: ${database_port}"
+ log_file="${CACHE_TMP_FILE_DIR}/output-${test_type}.log"
+ TEST_TYPE=${test_type} MYSQL_HOST_PORT="${database_port}"
POSTGRES_HOST_PORT="${database_port}" \
+ run_single_test_type "${@}" >"${log_file}" 2>&1 &
+ pid=$!
+ echo "The process started for ${test_type}. Log file ${log_file}"
+ echo
+ test_pids[${test_type}]=${pid}
+ done
+ start_end::group_end
+}
+
+# Monitors progress of all test types running
+# TEST_TYPES - all test types to monitor
+# test_pids - map of test types to PIDs
+function monitor_test_types() {
+ start_end::group_start "Monitoring progress of running parallel tests:
${TEST_TYPES}"
+ while true;
+ do
+ sleep "${TEST_SLEEP_TIME}"
+ if ! print_all_test_types_status; then
+ break
+ fi
+ done
+ start_end::group_end
+}
+
+
+# Monitors progress of single test type running
+# $1 - test type to monitor
+# test_pids - map of test types to PIDs
+function monitor_sequential_test_type() {
+ local test_type=$1
+ start_end::group_start "Monitoring progress of running sequential test
type: $1"
+ while true;
+ do
+ sleep "${TEST_SLEEP_TIME}"
+ if ! print_test_type_status "${test_type}"; then
+ break
+ fi
+ done
+ start_end::group_end
+}
+
+# Checks status for all test types running. Returns 0 if any of the tests
failed (with the exception of
+# Quarantined test.
+#
+# TEST_TYPES - all test types to run
+# test_pids - map of test types to PIDs
+#
+# output:
+# successful_tests - array of test types that succeeded
+# failed_tests - array of test types that failed
+function check_test_types_status() {
+ start_end::group_start "Checking status for parallel tests: ${TEST_TYPES}"
+ local test_type_exit_code="0"
+ for test_type in "${!test_pids[@]}"; do
+ local pid="${test_pids[${test_type}]}"
+ wait "${pid}"
+ local temp_exit_code=$?
+ if [[ ${temp_exit_code} == "0" ]]; then
+ successful_tests+=("${test_type}")
+ else
+ failed_tests+=("${test_type}")
+ if [[ ${test_type} != "Quarantined" ]]; then
+ test_type_exit_code=${temp_exit_code}``
+ fi
+ fi
+ done
+ start_end::group_end
+ return "${test_type_exit_code}"
+}
+
+# Outputs logs for failed test type
+# $1 test type
+function output_log_for_failed_test_type(){
+ local failed_test_type=$1
+ local log_file="${CACHE_TMP_FILE_DIR}/output-${failed_test_type}.log"
+ start_end::group_start "${COLOR_RED}Output for failed ${failed_test_type}
from log: ${log_file}${COLOR_RESET}"
+ echo "${COLOR_RED}##### Test type ${failed_test_type} failed #####
${COLOR_RESET}"
+ echo
+ cat "${log_file}"
+ echo
+ echo "${COLOR_RED}##### Test type ${failed_test_type} failed #####
${COLOR_RESET}"
+ echo
+ start_end::group_end
+}
+
+function print_test_summary() {
+ if [[ ${#successful_tests[@]} != 0 ]]; then
+ echo
+ echo "${COLOR_GREEN}Successful test types: ${successful_tests[*]}
${COLOR_RESET}"
+ echo
Review comment:
I think we should have the output logs shown even in case of success, at
least on CI.
The reason I'd like this is I often use information about the timing, both
the total run time, and the output from `--durations` to see when things have
gotten slow/where possible cases for speeding up might be.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]