From cd1115330f35e104d5d1e85c8d906b568526acf6 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 2 Jun 2020 19:24:52 -0400 Subject: [PATCH] ci: fix log capture for envoy integration tests The previous change, which moved test running to Go, appears to have broken log capturing. I am not entirely sure why, but the run_tests function seems to exit on the first error. This change moves test teardown and log capturing out of run_test, and has the go test runner call them when necessary. --- test/integration/connect/envoy/main_test.go | 12 +++- test/integration/connect/envoy/run-tests.sh | 75 ++++++--------------- 2 files changed, 31 insertions(+), 56 deletions(-) diff --git a/test/integration/connect/envoy/main_test.go b/test/integration/connect/envoy/main_test.go index 68e1d9e02..1dbd84d14 100644 --- a/test/integration/connect/envoy/main_test.go +++ b/test/integration/connect/envoy/main_test.go @@ -51,7 +51,17 @@ func TestEnvoy(t *testing.T) { for _, tc := range testcases { t.Run(tc, func(t *testing.T) { - runCmd(t, "run_tests", "CASE_DIR="+tc) + caseDir := "CASE_DIR=" + tc + + t.Cleanup(func() { + if t.Failed() { + runCmd(t, "capture_logs", caseDir) + } + + runCmd(t, "test_teardown", caseDir) + }) + + runCmd(t, "run_tests", caseDir) }) } } diff --git a/test/integration/connect/envoy/run-tests.sh b/test/integration/connect/envoy/run-tests.sh index 805891207..6ca141c10 100755 --- a/test/integration/connect/envoy/run-tests.sh +++ b/test/integration/connect/envoy/run-tests.sh @@ -125,6 +125,11 @@ function verify { } function capture_logs { + # exported to prevent docker-compose warning about unset var + export LOG_DIR="workdir/logs/${CASE_DIR}/${ENVOY_VERSION}" + + init_vars + echo "Capturing Logs" mkdir -p "$LOG_DIR" services="$REQUIRED_SERVICES consul-primary" @@ -139,7 +144,6 @@ function capture_logs { source ${CASE_DIR}/capture.sh || true fi - for cont in $services do echo "Capturing log for $cont" @@ -195,80 +199,41 @@ function run_tests { docker cp workdir/. envoy_workdir_1:/workdir start_consul primary - if [ $? -ne 0 ] - then - capture_logs - return 1 - fi - if is_set $REQUIRE_SECONDARY - then + if is_set $REQUIRE_SECONDARY; then start_consul secondary - if [ $? -ne 0 ] - then - capture_logs - return 1 - fi fi echo "Setting up the primary datacenter" pre_service_setup primary - if [ $? -ne 0 ] - then - echo "Setting up the primary datacenter failed" - capture_logs - return 1 - fi - if is_set $REQUIRE_SECONDARY - then + if is_set $REQUIRE_SECONDARY; then echo "Setting up the secondary datacenter" pre_service_setup secondary - if [ $? -ne 0 ] - then - echo "Setting up the secondary datacenter failed" - capture_logs - return 1 - fi fi echo "Starting services" start_services - if [ $? -ne 0 ] - then - capture_logs - return 1 - fi # Run the verify container and report on the output verify primary - TESTRESULT=$? - if is_set $REQUIRE_SECONDARY && test "$TESTRESULT" -eq 0 - then + if is_set $REQUIRE_SECONDARY; then verify secondary - SECONDARYRESULT=$? + fi +} - if [ "$SECONDARYRESULT" -ne 0 ] - then - TESTRESULT=$SECONDARYRESULT +function test_teardown { + # Set a log dir to prevent docker-compose warning about unset var + export LOG_DIR="workdir/logs/" + + init_vars + + stop_services primary + + if is_set $REQUIRE_SECONDARY; then + stop_services secondary fi - fi - - if [ "$TESTRESULT" -ne 0 ] - then - capture_logs - fi - - stop_services primary - - if is_set $REQUIRE_SECONDARY - then - stop_services secondary - fi - - - return $TESTRESULT } function suite_setup {