66# Global env vars:
77# UAA_GRADLE_INT_TEST_COMMAND: Gradle command to run integration tests (default: integrationTest)
88# this could include :cloudfoundry-identity-server:integrationTest --tests to run specific tests
9+ # jvm_heap: JVM heap size for UAA boot server (default: 640m)
10+ # jvm_metaspace: JVM metaspace size for UAA boot server (default: 192m)
11+ # gradle_heap: JVM heap size for Gradle daemon (default: 1024m)
12+ # gradle_test_heap: JVM heap size for Gradle test workers (default: 640m)
913# ######################################
1014function main() {
1115 local script_dir; script_dir=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
@@ -24,18 +28,38 @@ function main() {
2428
2529 local wd launch_boot assemble_code integration_test_code
2630 wd=$( pwd)
27- echo " Setting heap to ${jvm_heap:= 768m} "
28- echo " Setting metaspace to ${jvm_metaspace:= 256m} "
31+ temp_dir=${script_dir} /tmp
32+ mkdir -p " ${temp_dir} "
33+
34+ # Memory settings optimized for Gradle 9.0 with Kotlin 2.2
35+ # Boot server needs enough memory to handle test requests without crashing
36+ # Increased Gradle daemon heap to 1GB to prevent hanging with 2 workers
37+ # --no-configuration-cache prevents stale Kotlin compiler state reuse between daemon processes
38+ # logging.manager is set to org.apache.logging.log4j.jul.LogManager to prevent log4j2 from using java.util.logging
39+ echo " Setting boot heap to ${jvm_heap:= 640m} "
40+ echo " Setting boot metaspace to ${jvm_metaspace:= 192m} "
41+ echo " Setting Gradle daemon heap to ${gradle_heap:= 1024m} "
42+ echo " Setting test worker heap to ${gradle_test_heap:= 640m} "
2943
3044 readonly launch_boot=" nohup java \
31- -XX:+UseParallelGC \
32- -Xmx${jvm_heap} \
45+ -XX:+UseG1GC \
46+ -XX:G1HeapRegionSize=1m \
47+ -Xms64m -Xmx${jvm_heap} \
3348 -XX:MaxMetaspaceSize=${jvm_metaspace} \
49+ -XX:MetaspaceSize=${jvm_metaspace} \
50+ -XX:+UseStringDeduplication \
51+ -XX:MaxGCPauseMillis=200 \
3452 -XX:+HeapDumpOnOutOfMemoryError \
3553 -XX:HeapDumpPath=${wd} \
3654 -DCLOUDFOUNDRY_CONFIG_PATH=${wd} /scripts/boot \
55+ -Dlogging.config=${wd} /scripts/boot/log4j2.properties \
56+ -Dlog4j.configurationFile=${wd} /scripts/boot/log4j2.properties \
57+ -Dlog4j2.formatMsgNoLookups=true \
58+ -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager \
3759 -DSECRETS_DIR=${wd} /scripts/boot \
3860 -Djava.security.egd=file:/dev/./urandom \
61+ -Djava.io.tmpdir=${temp_dir} \
62+ -Dorg.bouncycastle.native.loader.install_dir=${temp_dir} \
3963 -Dmetrics.perRequestMetrics=true \
4064 -Dserver.servlet.context-path=/uaa \
4165 -Dserver.tomcat.basedir=${wd} /scripts/boot/tomcat \
@@ -50,46 +74,89 @@ function main() {
5074 -jar ${wd} /uaa/build/libs/cloudfoundry-identity-uaa-0.0.0.war \
5175 > boot.log 2>&1 &"
5276
77+ # Explicit Gradle daemon memory for Kotlin 2.2 with additional GC tuning
5378 readonly assemble_code=" ./gradlew '-Dspring.profiles.active=${test_profile} ' \
5479 '-Djava.security.egd=file:/dev/./urandom' \
80+ '-Dorg.gradle.jvmargs=-Dfile.encoding=utf8 -Xms64m -Xmx${gradle_heap} -XX:MaxMetaspaceSize=128m -XX:+UseG1GC -XX:MaxGCPauseMillis=100' \
5581 assemble \
82+ --no-watch-fs \
5683 --no-daemon \
57- --max-workers=4 \
84+ --no-configuration-cache \
85+ --max-workers=2 \
5886 --stacktrace \
5987 --console=plain"
6088
89+ # Explicit memory limits for test JVMs with GC tuning and classloader fixes
90+ # All flags required to prevent classloading deadlocks and thread starvation during test init
91+ # --no-configuration-cache prevents stale Kotlin compiler state reuse between daemon processes
92+ readonly compile_test_code=" ./gradlew \
93+ '-Dspring.profiles.active=${test_profile} ' \
94+ '-Djava.security.egd=file:/dev/./urandom' \
95+ '-DskipUaaAutoStart=true' \
96+ '-Dorg.gradle.jvmargs=-Dfile.encoding=utf8 -Xms64m -Xmx${gradle_test_heap} -XX:MaxMetaspaceSize=128m -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -XX:ParallelGCThreads=2 -XX:CICompilerCount=2 -Djdk.lang.processReaperUseDefaultStackSize=true' \
97+ '-Dorg.gradle.daemon.idletimeout=300000' \
98+ '-Dorg.gradle.parallel=false' \
99+ '-Dorg.gradle.workers.max=2' \
100+ clean assemble compileTestJava \
101+ --no-watch-fs \
102+ --no-daemon \
103+ --no-configuration-cache \
104+ --max-workers=2 \
105+ --stacktrace \
106+ --console=plain"
107+
108+ # Explicit memory limits for test JVMs with GC tuning and classloader fixes
109+ # All flags required to prevent classloading deadlocks and thread starvation during test init
61110 readonly integration_test_code=" ./gradlew \
62111 '-Dspring.profiles.active=${test_profile} ' \
63112 '-Djava.security.egd=file:/dev/./urandom' \
64113 '-DskipUaaAutoStart=true' \
114+ '-Dorg.gradle.jvmargs=-Dfile.encoding=utf8 -Xms64m -Xmx${gradle_test_heap} -XX:MaxMetaspaceSize=128m -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -XX:ParallelGCThreads=2 -XX:CICompilerCount=2 -Djdk.lang.processReaperUseDefaultStackSize=true' \
115+ '-Dorg.gradle.daemon.idletimeout=300000' \
116+ '-Dorg.gradle.parallel=false' \
117+ '-Dorg.gradle.workers.max=2' \
65118 ${UAA_GRADLE_INT_TEST_COMMAND:- integrationTest} \
66- --stacktrace \
119+ --no-watch-fs \
67120 --no-daemon \
121+ --no-configuration-cache \
122+ --max-workers=2 \
123+ --stacktrace \
68124 --console=plain"
69125
70- set -x
71126 if [[ " ${RUN_TESTS:- true} " = ' true' ]]; then
127+ set -x
72128 eval " $assemble_code "
73129
74- # Always start the boot server before running integration tests
130+ # Start and ensure the boot server is running before integration tests
75131 eval " $launch_boot "
76132 echo $! > boot.pid
133+ { set +x; } 2> /dev/null
134+
77135 if is_boot_running ; then
78136 echo " Boot started. Can continue to run tests."
79137 else
80- echo " Boot did not start - failing"
138+ echo " Boot did not start, failing"
81139 cat boot.log
82140 exit 1
83141 fi
84142
143+ if [[ -z " ${DBUS_SESSION_BUS_ADDRESS:- } " ]]; then
144+ export DBUS_SESSION_BUS_ADDRESS=/dev/null
145+ fi
146+ set -x
147+ eval " $compile_test_code "
85148 eval " $integration_test_code "
86-
149+ { set +x; } 2> /dev/null
150+
87151 # Clean up: kill the boot server
88152 if [[ -f boot.pid ]]; then
89- kill -9 " $( cat boot.pid) " || true
153+ local pid; pid=$( cat boot.pid)
154+ echo " Sending SIGKILL (kill -9) to UAA process (pid=${pid} )"
155+ kill -9 " ${pid} " || true
90156 rm boot.pid
91157 fi
92158 else
159+ set -x
93160 echo " $integration_test_code "
94161 bash
95162 fi
0 commit comments