Scripting: implement correct disposal of REPL state on finalization
#KT-47927 fixed
This commit is contained in:
committed by
TeamCityServer
parent
a45e31720c
commit
4243bafd1d
+25
@@ -8,7 +8,9 @@ package kotlin.script.experimental.jsr223.test
|
||||
import org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
||||
import org.junit.Assert
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import java.lang.management.ManagementFactory
|
||||
import javax.script.*
|
||||
import kotlin.script.experimental.jvmhost.jsr223.KotlinJsr223ScriptEngineImpl
|
||||
|
||||
@@ -71,6 +73,29 @@ class KotlinJsr223ScriptEngineIT {
|
||||
Assert.assertEquals(5, res2)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // Probably not possible to make it sensible on CI and with parallel run, so leaving it here for manual testing only
|
||||
fun testMemory() {
|
||||
val memoryMXBean = ManagementFactory.getMemoryMXBean()!!
|
||||
var prevMem = memoryMXBean.getHeapMemoryUsage().getUsed()
|
||||
for (i in 1..10) {
|
||||
with(ScriptEngineManager().getEngineByExtension("kts")) {
|
||||
val res1 = eval("val x = 3")
|
||||
Assert.assertNull(res1)
|
||||
val res2 = eval("x + 2")
|
||||
Assert.assertEquals(5, res2)
|
||||
}
|
||||
System.gc()
|
||||
val curMem = memoryMXBean.getHeapMemoryUsage().getUsed()
|
||||
if (i > 3 && curMem > prevMem) {
|
||||
Assert.assertTrue("Memory leak: iter: $i prev: $prevMem, cur: $curMem", (curMem - prevMem) < 1024*1024 )
|
||||
}
|
||||
println("${curMem/1024/1024}Mb")
|
||||
prevMem = curMem
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testIncomplete() {
|
||||
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
|
||||
|
||||
Reference in New Issue
Block a user