Skip to content

Commit

Permalink
chore(ci): improve integration_test.sh upgrade bash-buddy 🚼
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Sep 29, 2024
1 parent 6bc8218 commit d6d6d4d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/strong_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
11
17
21
23
distribution: zulu
cache: maven

Expand Down
41 changes: 25 additions & 16 deletions scripts/integration_test.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#!/bin/bash
set -eEuo pipefail
cd "$(dirname "$(readlink -f "$0")")"
# the canonical path of this script
SELF_PATH=$(realpath -- "$0")
readonly SELF_PATH SELF_DIR=${SELF_PATH%/*}

BASH_BUDDY_ROOT="$(readlink -f bash-buddy)"
readonly BASH_BUDDY_ROOT
readonly BASH_BUDDY_ROOT="$SELF_DIR/bash-buddy"
# shellcheck disable=SC1091
source "$BASH_BUDDY_ROOT/lib/trap_error_info.sh"
# shellcheck disable=SC1091
source "$BASH_BUDDY_ROOT/lib/common_utils.sh"
# shellcheck disable=SC1091
source "$BASH_BUDDY_ROOT/lib/java_utils.sh"
# shellcheck disable=SC1091
source "$BASH_BUDDY_ROOT/lib/maven_utils.sh"

################################################################################
Expand All @@ -20,6 +25,7 @@ readonly JDK_VERSIONS=(
11
"$default_build_jdk_version"
21
23
)

# here use `install` and `-D performRelease` intended
Expand All @@ -33,9 +39,12 @@ readonly MVU_MVN_OPTS=(
"${MVU_DEFAULT_MVN_OPTS[@]}"
-DperformRelease -P'!gen-sign'
${CI_MORE_MVN_OPTS:+${CI_MORE_MVN_OPTS}}
dependency:properties
)

cd ..
# cd to the project root directory
readonly PROJECT_ROOT=${SELF_DIR%/*}
cd "$PROJECT_ROOT"

########################################
# build and test by default version jdk
Expand All @@ -50,11 +59,11 @@ mvu::mvn_cmd clean install
# test by multiply version jdks
########################################

SUREFIRE_TEST_GOAL=(surefire:test)
# about CI env var
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
if [ "${CI:-}" = true ]; then
CI_MORE_BEGIN_OPTS=jacoco:prepare-agent CI_MORE_END_OPTS=jacoco:report
fi
[ "${CI:-}" = true ] && SUREFIRE_TEST_GOAL=(jacoco:prepare-agent "${SUREFIRE_TEST_GOAL[@]}" jacoco:report)
readonly SUREFIRE_TEST_GOAL

for jdk_version in "${JDK_VERSIONS[@]}"; do
jvu::switch_to_jdk "$jdk_version"
Expand All @@ -70,46 +79,46 @@ for jdk_version in "${JDK_VERSIONS[@]}"; do
if [ "$jdk_version" != "$default_build_jdk_version" ]; then
# just test without build
cu::head_line_echo "test without agents: $JAVA_HOME"
mvu::mvn_cmd ${CI_MORE_BEGIN_OPTS:-} dependency:properties surefire:test ${CI_MORE_END_OPTS:-}
mvu::mvn_cmd "${SUREFIRE_TEST_GOAL[@]}"
fi

cu::head_line_echo test under hello and world agents
STUDY_AGENT_RUN_MODE=hello-and-world-agents \
mvu::mvn_cmd ${CI_MORE_BEGIN_OPTS:-} dependency:properties surefire:test ${CI_MORE_END_OPTS:-}
mvu::mvn_cmd "${SUREFIRE_TEST_GOAL[@]}"

cu::head_line_echo test under hello agent
STUDY_AGENT_RUN_MODE=only-hello-agent STUDY_AGENT_ENABLE_CLASS_LOG=true \
mvu::mvn_cmd ${CI_MORE_BEGIN_OPTS:-} dependency:properties surefire:test ${CI_MORE_END_OPTS:-}
mvu::mvn_cmd "${SUREFIRE_TEST_GOAL[@]}"

cu::head_line_echo test under hello agent twice
STUDY_AGENT_RUN_MODE=only-hello-agent-twice \
mvu::mvn_cmd ${CI_MORE_BEGIN_OPTS:-} dependency:properties surefire:test ${CI_MORE_END_OPTS:-}
mvu::mvn_cmd "${SUREFIRE_TEST_GOAL[@]}"

##############################
# run main test
##############################

cu::head_line_echo run Main without agents
mvu::mvn_cmd dependency:properties exec:exec -pl main-runner
mvu::mvn_cmd exec:exec -pl main-runner

cu::head_line_echo "test jvm should fail if throw exception in agent premain"
tmp_output_file="target/study_hello_agent_throw_exception_$$_$RANDOM.tmp"
STUDY_AGENT_RUN_MODE=only-hello-agent STUDY_HELLO_AGENT_THROW_EXCEPTION=true \
mvu::mvn_cmd dependency:properties exec:exec -pl main-runner 2>&1 |
mvu::mvn_cmd exec:exec -pl main-runner 2>&1 |
tee "$tmp_output_file" &&
cu::die "jvm should fail if throw exception in agent premain!"
cu::log_then_run grep "IllegalStateException.*throw exception for jvm start failure test by setting STUDY_HELLO_AGENT_THROW_EXCEPTION env var!" "$tmp_output_file" ||
cu::die "should contains exception message!"

cu::head_line_echo run Main under hello and world agents
STUDY_AGENT_RUN_MODE=hello-and-world-agents \
mvu::mvn_cmd dependency:properties exec:exec -pl main-runner
mvu::mvn_cmd exec:exec -pl main-runner

cu::head_line_echo run Main under hello agent
STUDY_AGENT_RUN_MODE=only-hello-agent STUDY_AGENT_ENABLE_CLASS_LOG=true \
mvu::mvn_cmd dependency:properties exec:exec -pl main-runner
mvu::mvn_cmd exec:exec -pl main-runner

cu::head_line_echo run Main under hello agent twice
STUDY_AGENT_RUN_MODE=only-hello-agent-twice \
mvu::mvn_cmd dependency:properties exec:exec -pl main-runner
mvu::mvn_cmd exec:exec -pl main-runner
done

0 comments on commit d6d6d4d

Please sign in to comment.