build(test): 가용 메모리로 테스트 힙을 산정하고 워커 수명을 제한한다

This commit is contained in:
2026-11-19 14:21:56 +09:00
parent 1c270048a1
commit bc84faf7a8
5 changed files with 331 additions and 1 deletions
+27 -1
View File
@@ -1,3 +1,4 @@
import buildlogic.TestHeapPolicy
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
@@ -108,8 +109,33 @@ tasks.withType<KotlinCompile> {
tasks.withType<Test>().configureEach {
useJUnitPlatform()
maxHeapSize = "4g"
maxParallelForks = 1
forkEvery = 50
systemProperty("spring.test.context.cache.maxSize", 4)
jvmArgs("-Dfile.encoding=UTF-8")
val gcLogDirectory = layout.buildDirectory.dir("test-gc/$name").get().asFile
doFirst {
val availableBytes = TestHeapPolicy.readAvailableBytes()
val maxWorkers = gradle.startParameter.maxWorkerCount
val heapMiB = TestHeapPolicy.calculateHeapMiB(availableBytes, maxParallelForks, maxWorkers)
maxHeapSize = "${heapMiB}m"
logger.lifecycle(
"Test heap: available estimate={} MiB, workers={}, maxHeap={} MiB (50% budget, 1 GiB native reserve per worker)",
availableBytes / (1024 * 1024),
minOf(maxParallelForks, maxWorkers),
heapMiB
)
gcLogDirectory.mkdirs()
}
jvmArgs(
"-Xlog:gc*:file=${gcLogDirectory.resolve("gc-%p.log")}:time,uptime,pid,level,tags:filecount=3,filesize=10M"
)
beforeSuite(
closureOf<TestDescriptor> {
if (className != null) logger.lifecycle("Test class: $className")
}
)
}
tasks.getByName<Jar>("jar") {