Skip to content

Commit

Permalink
chore(integ): add ability to run integration tests in parallel (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlove-aws authored Feb 26, 2021
1 parent 551545f commit cd34712
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
20 changes: 16 additions & 4 deletions integ/components/deadline/common/scripts/bash/deploy-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ function deploy_component_stacks () {
echo "Running $COMPONENT_NAME end-to-end test..."

echo "Deploying test app for $COMPONENT_NAME test suite"
npx cdk deploy "*" --require-approval=never
if [ "${RUN_TESTS_IN_PARALLEL}" = true ]; then
npx cdk deploy "*" --require-approval=never > "$INTEG_TEMP_DIR/${COMPONENT_NAME}_deploy.txt" 2>&1
else
npx cdk deploy "*" --require-approval=never
fi
echo "Test app $COMPONENT_NAME deployed."

return 0
}

Expand All @@ -32,7 +36,11 @@ function execute_component_test () {
run_aws_interaction_hook

echo "Running test suite $COMPONENT_NAME..."
yarn run test "$COMPONENT_NAME.test" --json --outputFile="./.e2etemp/$COMPONENT_NAME.json"
if [ "${RUN_TESTS_IN_PARALLEL}" = true ]; then
yarn run test "$COMPONENT_NAME.test" --json --outputFile="$INTEG_TEMP_DIR/$COMPONENT_NAME.json" > "$INTEG_TEMP_DIR/${COMPONENT_NAME}.txt" 2>&1
else
yarn run test "$COMPONENT_NAME.test" --json --outputFile="$INTEG_TEMP_DIR/$COMPONENT_NAME.json"
fi
echo "Test suite $COMPONENT_NAME complete."

return 0
Expand All @@ -44,7 +52,11 @@ function destroy_component_stacks () {
run_aws_interaction_hook

echo "Destroying test app $COMPONENT_NAME..."
npx cdk destroy "*" -f
if [ "${RUN_TESTS_IN_PARALLEL}" = true ]; then
npx cdk destroy "*" -f > "$INTEG_TEMP_DIR/${COMPONENT_NAME}_destroy.txt" 2>&1
else
npx cdk destroy "*" -f
fi
rm -f "./cdk.context.json"
rm -rf "./cdk.out"
echo "Test app $COMPONENT_NAME destroyed."
Expand Down
43 changes: 42 additions & 1 deletion integ/scripts/bash/rfdk-integ-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fi

# Create temp directory
export INTEG_TEMP_DIR="$INTEG_ROOT/.e2etemp"
rm -rf $INTEG_TEMP_DIR
mkdir -p $INTEG_TEMP_DIR

# Stage deadline from script
Expand Down Expand Up @@ -76,6 +77,7 @@ $BASH_SCRIPTS/deploy-infrastructure.sh || cleanup_on_failure
export INFRASTRUCTURE_DEPLOY_FINISH_TIME=$SECONDS

# Pull the top level directory for each cdk app in the components directory
COMPONENTS=()
for COMPONENT in **/cdk.json; do
# In case the yarn install was done inside this integ package, there are some example cdk.json files in the aws-cdk
# package we want to avoid.
Expand All @@ -90,11 +92,50 @@ for COMPONENT in **/cdk.json; do
export ${COMPONENT_NAME}_START_TIME=$SECONDS
if [[ "$COMPONENT_NAME" != _* ]]; then
# Excecute the e2e test in the component's scripts directory
cd "$INTEG_ROOT/$COMPONENT_ROOT" && ../common/scripts/bash/component_e2e.sh "$COMPONENT_NAME" || cleanup_on_failure
cd "$INTEG_ROOT/$COMPONENT_ROOT"
if [ "${RUN_TESTS_IN_PARALLEL}" = true ]; then
(../common/scripts/bash/component_e2e.sh "$COMPONENT_NAME" || ../common/scripts/bash/component_e2e.sh "$COMPONENT_NAME" --destroy-only) &
export ${COMPONENT_NAME}_PID=$!
COMPONENTS+=(${COMPONENT_NAME})
else
../common/scripts/bash/component_e2e.sh "$COMPONENT_NAME" || cleanup_on_failure
fi
fi
export ${COMPONENT_NAME}_FINISH_TIME=$SECONDS
done

if [ "${RUN_TESTS_IN_PARALLEL}" = true ]; then
while [ "${#COMPONENTS[@]}" -ne 0 ]; do
ACTIVE_COMPONENTS=()
for COMPONENT_NAME in ${COMPONENTS[@]}; do
PID=$(eval echo \"\$${COMPONENT_NAME}_PID\")
if ps -p "$PID" > /dev/null; then
ACTIVE_COMPONENTS+=(${COMPONENT_NAME})
else
echo "Test app $COMPONENT_NAME finished."
if [ -f "$INTEG_TEMP_DIR/${COMPONENT_NAME}_deploy.txt" ]; then
cat "$INTEG_TEMP_DIR/${COMPONENT_NAME}_deploy.txt"
fi
if [ -f "$INTEG_TEMP_DIR/${COMPONENT_NAME}.txt" ]; then
cat "$INTEG_TEMP_DIR/${COMPONENT_NAME}.txt"
fi
if [ -f "$INTEG_TEMP_DIR/${COMPONENT_NAME}_destroy.txt" ]; then
cat "$INTEG_TEMP_DIR/${COMPONENT_NAME}_destroy.txt"
fi
fi
export ${COMPONENT_NAME}_FINISH_TIME=$SECONDS
done
if [ "${#ACTIVE_COMPONENTS[@]}" -ne 0 ]; then
COMPONENTS=(${ACTIVE_COMPONENTS[@]})
else
COMPONENTS=()
fi
sleep 1
done

wait
fi

# Mark infrastructure destroy start time
export INFRASTRUCTURE_DESTROY_START_TIME=$SECONDS

Expand Down
3 changes: 3 additions & 0 deletions integ/test-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ export SKIP_deadline_01_repository_TEST
export SKIP_deadline_02_renderQueue_TEST
export SKIP_deadline_03_workerFleetHttp_TEST
export SKIP_deadline_04_workerFleetHttps_TEST

# All test suites will be run in parallel
export RUN_TESTS_IN_PARALLEL=false

0 comments on commit cd34712

Please sign in to comment.