Skip to content
Merged
45 changes: 31 additions & 14 deletions scripts/run-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ while getopts ":hr:v:e:" opt; do
r)
RETRIES="$OPTARG"
if ! [[ "$RETRIES" =~ ^[0-9]+$ ]] || [[ "$RETRIES" -lt 0 ]]; then
echo "error: -r requires a non-negative integer (got: $RETRIES)" >&2
echo "ERROR: -r requires a non-negative integer (got: $RETRIES)" >&2
exit 2
fi
;;
Expand All @@ -63,12 +63,12 @@ while getopts ":hr:v:e:" opt; do
TEST_ENV="$OPTARG"
;;
\?)
echo "error: unknown option: -$OPTARG" >&2
echo "ERROR: unknown option: -$OPTARG" >&2
usage
exit 2
;;
:)
echo "error: option -$OPTARG requires an argument" >&2
echo "ERROR: option -$OPTARG requires an argument" >&2
usage
exit 2
;;
Expand All @@ -81,7 +81,7 @@ VERBOSITY=${VERBOSITY:-'-v'}

# Validate required positional args
if [[ $# -ne 2 ]]; then
echo "error: missing required positional arguments" >&2
echo "ERROR: missing required positional arguments" >&2
usage
exit 1
fi
Expand All @@ -92,7 +92,7 @@ TEST_NAME=$2
case "$TEST_TYPE" in
int|e2e) ;;
*)
echo "error: TEST_TYPE must be 'int' or 'e2e' (got: $TEST_TYPE)" >&2
echo "ERROR: TEST_TYPE must be 'int' or 'e2e' (got: $TEST_TYPE)" >&2
usage
exit 1
;;
Expand All @@ -105,34 +105,51 @@ if [[ ${#TEST_ENV} -gt 0 ]]; then
else
# Collect all available environments via auto-discovery
mapfile -t TEST_ENVIRONMENTS < <(cargo vdev "${VERBOSITY}" "${TEST_TYPE}" show -e "${TEST_NAME}")
if [[ ${#TEST_ENVIRONMENTS[@]} -eq 0 ]]; then
echo "ERROR: no environments found for ${TEST_TYPE} test '${TEST_NAME}'" >&2
exit 1
fi
fi

for TEST_ENV in "${TEST_ENVIRONMENTS[@]}"; do

docker run --rm \
-v vector_target:/output/"${TEST_NAME}" \
alpine:3.20 \
# Execution flow for each environment:
# 1. Clean up previous test output
# 2. Start environment
# 3. If start succeeded:
# - Run tests
# - Upload results to Datadog CI
# 4. If start failed:
# - Skip test phase
# - Exit with error code
# 5. Stop environment (always, best effort)
# 6. Exit if there was a failure

docker run --rm -v vector_target:/output/"${TEST_NAME}" alpine:3.20 \
sh -c "rm -rf /output/${TEST_NAME}/*"

cargo vdev "${VERBOSITY}" "${TEST_TYPE}" start -a "${TEST_NAME}" "${TEST_ENV}" || true
cargo vdev "${VERBOSITY}" "${TEST_TYPE}" start -a "${TEST_NAME}" "${TEST_ENV}"
START_RET=$?
print_compose_logs_on_failure "$START_RET"

if [[ "$START_RET" -eq 0 ]]; then
cargo vdev "${VERBOSITY}" "${TEST_TYPE}" test --retries "$RETRIES" -a "${TEST_NAME}" "${TEST_ENV}"
RET=$?
print_compose_logs_on_failure "$RET"

# Upload test results only if the vdev test step ran
./scripts/upload-test-results.sh
else
echo "Skipping test phase because 'vdev start' failed"
RET=$START_RET
fi

# Always stop the environment (best effort cleanup)
cargo vdev "${VERBOSITY}" "${TEST_TYPE}" stop -a "${TEST_NAME}" || true

# Only upload test results if CI is defined
if [[ -n "${CI:-}" ]]; then
./scripts/upload-test-results.sh
# Exit early on first failure
if [[ "$RET" -ne 0 ]]; then
exit "$RET"
fi
done

exit "$RET"
exit 0
25 changes: 18 additions & 7 deletions scripts/upload-test-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@ IFS=$'\n\t'
#
# SUMMARY
#
# Upload `cargo-nextest` JUnit output to Datadog
# Upload `cargo-nextest` JUnit output to Datadog (CI only)
# Print test results location when running locally
#
# NOTES
#
# Only uploads in CI environments. Prints file location when called locally.

JUNIT_FILE="target/nextest/default/junit.xml"

# Print location locally, upload in CI
if [[ -z "${CI:-}" ]]; then
if [[ -f "$JUNIT_FILE" ]]; then
echo "Test results available at: $JUNIT_FILE"
fi
exit 0
fi

cd "$(dirname "${BASH_SOURCE[0]}")/.."
set -x

_os_platform="$(uname -s)"
Expand All @@ -17,8 +31,5 @@ _os_architecture="$(uname -m)"
export DD_TAGS="os.platform:$_os_platform,os.architecture:$_os_architecture"
export DD_ENV="${DD_ENV:-"local"}"

# TODO: outside contributors don't have access to the
# CI secrets, so allowing this to fail for now
datadog-ci junit upload \
--service vector \
target/nextest/default/junit.xml || echo "Failed to upload results"
# TODO: outside contributors don't have access to the CI secrets, so upload might fail.
datadog-ci junit upload --service vector "${JUNIT_FILE}" || echo "Failed to upload results"
Loading