Skip to content

Commit

Permalink
test: add test case "jvm should fail if throw exception in agent prem…
Browse files Browse the repository at this point in the history
…ain" 💥
  • Loading branch information
oldratlee committed Jul 16, 2023
1 parent 9624e4d commit 13c9f04
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
test:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners
runs-on: ${{ matrix.os }}
timeout-minutes: 5
timeout-minutes: 10
name: fast test on OS ${{ matrix.os }}
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/strong_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
test:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 15
name: test by multiply java versions

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.util.Collections;
import java.util.List;

import static io.foldright.study.agent.utils.transform.ThreadPoolExecutorTransformlet.THREAD_POOL_EXECUTOR_CLASS_NAME;
import static io.foldright.study.agent.utils.Utils.isClassLoaded;
import static io.foldright.study.agent.utils.transform.ThreadPoolExecutorTransformlet.THREAD_POOL_EXECUTOR_CLASS_NAME;


/**
Expand All @@ -21,6 +21,10 @@ public class HelloAgent {
public static void premain(final String agentArgs, @NonNull final Instrumentation inst) {
System.out.println("[" + NAME + "Agent] Enter premain!");

if (System.getenv().containsKey("STUDY_HELLO_AGENT_THROW_EXCEPTION")) {
throw new IllegalStateException("throw exception for jvm start failure test by setting HELLO_AGENT_THROW_EXCEPTION env var!");
}

if (isClassLoaded(inst, THREAD_POOL_EXECUTOR_CLASS_NAME))
throw new IllegalStateException("class " + THREAD_POOL_EXECUTOR_CLASS_NAME + " already loaded");

Expand Down
16 changes: 16 additions & 0 deletions scripts/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ for jdk_version in "${JDK_VERSIONS[@]}"; do
# just test without build
cu::head_line_echo "test with Java $jdk_version: $JAVA_HOME"

##############################
# run unit test
##############################

# skip default jdk, already tested above
if [ "$jdk_version" != "$default_build_jdk_version" ]; then
# just test without build
Expand All @@ -83,9 +87,21 @@ for jdk_version in "${JDK_VERSIONS[@]}"; do
cu::head_line_echo test under hello agent twice
STUDY_AGENT_RUN_MODE=only-hello-agent-twice jvb::mvn_cmd ${CI_MORE_BEGIN_OPTS:-} dependency:properties surefire:test ${CI_MORE_END_OPTS:-}

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

cu::head_line_echo run Main without agents
jvb::mvn_cmd dependency:properties 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_HELLO_AGENT_THROW_EXCEPTION= STUDY_AGENT_RUN_MODE=only-hello-agent jvb::mvn_cmd dependency:properties 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 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 jvb::mvn_cmd dependency:properties exec:exec -pl main-runner

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.util.Collections;
import java.util.List;

import static io.foldright.study.agent.utils.transform.ThreadPoolExecutorTransformlet.THREAD_POOL_EXECUTOR_CLASS_NAME;
import static io.foldright.study.agent.utils.Utils.isClassLoaded;
import static io.foldright.study.agent.utils.transform.ThreadPoolExecutorTransformlet.THREAD_POOL_EXECUTOR_CLASS_NAME;


/**
Expand Down

0 comments on commit 13c9f04

Please sign in to comment.