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.
This commit is contained in:
Daniel Nephin 2020-06-02 19:24:52 -04:00
parent e8a883e829
commit cd1115330f
2 changed files with 31 additions and 56 deletions

View File

@ -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)
})
}
}

View File

@ -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 {