Fix state conversion, fix tests
This commit is contained in:
@@ -25,8 +25,6 @@ import org.jetbrains.kotlin.integration.KotlinIntegrationTestBase
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||
import org.jetbrains.kotlin.script.*
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
@@ -111,7 +109,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
}
|
||||
}
|
||||
assertTrue("Expecting that compilation 1 ($compileTime1 ms) is at least two times longer than compilation 2 ($compileTime2 ms)",
|
||||
compileTime1 > compileTime2 * 2)
|
||||
compileTime1 > compileTime2 * 2)
|
||||
logFile.delete()
|
||||
run("hello.run", "-cp", jar, "Hello.HelloKt")
|
||||
}
|
||||
@@ -536,10 +534,12 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
|
||||
fun testDaemonReplLocalEvalNoParams() {
|
||||
withDaemon { daemon ->
|
||||
val repl = KotlinRemoteReplCompiler(daemon, null, CompileService.TargetPlatform.JVM,
|
||||
classpathFromClassloader(),
|
||||
ScriptWithNoParam::class.qualifiedName!!,
|
||||
System.err)
|
||||
val repl = KotlinRemoteReplCompilerClient(daemon!!, null, CompileService.TargetPlatform.JVM,
|
||||
emptyArray(),
|
||||
TestMessageCollector(),
|
||||
classpathFromClassloader(),
|
||||
ScriptWithNoParam::class.qualifiedName!!,
|
||||
ScriptArgsWithTypes(emptyArray(), emptyArray()))
|
||||
|
||||
val localEvaluator = GenericReplEvaluator(emptyList(), Thread.currentThread().contextClassLoader)
|
||||
|
||||
@@ -550,10 +550,11 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
|
||||
fun testDaemonReplLocalEvalStandardTemplate() {
|
||||
withDaemon { daemon ->
|
||||
val repl = KotlinRemoteReplCompiler(daemon, null, CompileService.TargetPlatform.JVM,
|
||||
classpathFromClassloader(),
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithArgs",
|
||||
System.err)
|
||||
val repl = KotlinRemoteReplCompilerClient(disposable, daemon!!, null, CompileService.TargetPlatform.JVM, emptyArray(),
|
||||
TestMessageCollector(),
|
||||
classpathFromClassloader(),
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithArgs",
|
||||
ScriptArgsWithTypes(emptyArray(), emptyArray()))
|
||||
|
||||
val localEvaluator = GenericReplEvaluator(emptyList(), Thread.currentThread().contextClassLoader,
|
||||
ScriptArgsWithTypes(arrayOf(emptyArray<String>()), arrayOf(Array<String>::class)))
|
||||
@@ -563,66 +564,37 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun doReplTestWithLocalEval(repl: KotlinRemoteReplCompiler, localEvaluator: ReplEvaluator) {
|
||||
val res0 = repl.check(ReplCodeLine(0, "val x ="))
|
||||
private fun doReplTestWithLocalEval(replCompiler: KotlinRemoteReplCompilerClient, localEvaluator: ReplEvaluator) {
|
||||
|
||||
val compilerState = replCompiler.createState()
|
||||
val evaluatorState = localEvaluator.createState()
|
||||
|
||||
val res0 = replCompiler.check(compilerState, ReplCodeLine(0, "val x ="))
|
||||
TestCase.assertTrue("Unexpected check results: $res0", res0 is ReplCheckResult.Incomplete)
|
||||
|
||||
val codeLine1 = ReplCodeLine(1, "val lst = listOf(1)\nval x = 5")
|
||||
val res1 = repl.compile(codeLine1, emptyList())
|
||||
val res1 = replCompiler.compile(compilerState, codeLine1)
|
||||
val res1c = res1 as? ReplCompileResult.CompiledClasses
|
||||
TestCase.assertNotNull("Unexpected compile result: $res1", res1c)
|
||||
|
||||
val res11 = localEvaluator.eval(res1c!!)
|
||||
val res11 = localEvaluator.eval(evaluatorState, res1c!!)
|
||||
val res11e = res11 as? ReplEvalResult.UnitResult
|
||||
TestCase.assertNotNull("Unexpected eval result: $res11", res11e)
|
||||
|
||||
val codeLine2 = ReplCodeLine(2, "x + 2")
|
||||
val res2x = repl.compile(codeLine2, listOf(codeLine2))
|
||||
val res2x = replCompiler.compile(compilerState, codeLine2)
|
||||
TestCase.assertNotNull("Unexpected compile result: $res2x", res2x as? ReplCompileResult.HistoryMismatch)
|
||||
|
||||
val res2 = repl.compile(codeLine2, listOf(codeLine1))
|
||||
val res2 = replCompiler.compile(compilerState, codeLine2)
|
||||
val res2c = res2 as? ReplCompileResult.CompiledClasses
|
||||
TestCase.assertNotNull("Unexpected compile result: $res2", res2c)
|
||||
|
||||
val res21 = localEvaluator.eval(res2c!!)
|
||||
val res21 = localEvaluator.eval(evaluatorState, res2c!!)
|
||||
val res21e = res21 as? ReplEvalResult.ValueResult
|
||||
TestCase.assertNotNull("Unexpected eval result: $res21", res21e)
|
||||
TestCase.assertEquals(7, res21e!!.value)
|
||||
}
|
||||
|
||||
fun testDaemonReplRemoteEval() {
|
||||
withDaemon { daemon ->
|
||||
val evalOut = ByteArrayOutputStream()
|
||||
val evalErr = ByteArrayOutputStream()
|
||||
val evalIn = ByteArrayInputStream("42\n".toByteArray())
|
||||
|
||||
val repl = KotlinRemoteReplEvaluator(daemon, null, CompileService.TargetPlatform.JVM,
|
||||
listOf(File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-runtime.jar")),
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithArgs",
|
||||
arrayOf(emptyArray<String>()),
|
||||
arrayOf(Array<String>::class.java),
|
||||
System.err, evalOut, evalErr, evalIn)
|
||||
|
||||
val res0 = repl.check(ReplCodeLine(0, "val x ="))
|
||||
TestCase.assertTrue("Unexpected check results: $res0", res0 is ReplCheckResult.Incomplete)
|
||||
|
||||
val codeLine1 = ReplCodeLine(1, "val x = 5")
|
||||
val res1 = repl.compileAndEval(codeLine1, verifyHistory = emptyList())
|
||||
val res1e = res1 as? ReplEvalResult.UnitResult
|
||||
TestCase.assertNotNull("Unexpected eval result: $res1", res1e)
|
||||
|
||||
val codeLine2 = ReplCodeLine(2, "x + 2")
|
||||
val res2x = repl.compileAndEval(codeLine2, verifyHistory = listOf(codeLine2))
|
||||
TestCase.assertNotNull("Unexpected compile result: $res2x", res2x as? ReplEvalResult.HistoryMismatch)
|
||||
|
||||
val res2 = repl.compileAndEval(codeLine2, verifyHistory = listOf(codeLine1))
|
||||
val res2e = res2 as? ReplEvalResult.ValueResult
|
||||
TestCase.assertNotNull("Unexpected eval result: $res2", res2e)
|
||||
TestCase.assertEquals(7, res2e!!.value)
|
||||
repl.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
fun testDaemonReplAutoshutdownOnIdle() {
|
||||
withFlagFile(getTestName(true), ".alive") { flagFile ->
|
||||
val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1, autoshutdownUnusedSeconds = 1, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath)
|
||||
@@ -636,15 +608,19 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
val daemon = KotlinCompilerClient.connectToCompileService(compilerId, flagFile, daemonJVMOptions, daemonOptions, DaemonReportingTargets(out = System.err), autostart = true)
|
||||
assertNotNull("failed to connect daemon", daemon)
|
||||
|
||||
val repl = KotlinRemoteReplCompiler(daemon!!, null, CompileService.TargetPlatform.JVM,
|
||||
classpathFromClassloader(),
|
||||
ScriptWithNoParam::class.qualifiedName!!,
|
||||
System.err)
|
||||
val replCompiler = KotlinRemoteReplCompilerClient(daemon!!, null, CompileService.TargetPlatform.JVM,
|
||||
emptyArray(),
|
||||
TestMessageCollector(),
|
||||
classpathFromClassloader(),
|
||||
ScriptWithNoParam::class.qualifiedName!!,
|
||||
ScriptArgsWithTypes(emptyArray(), emptyArray()))
|
||||
|
||||
val compilerState = replCompiler.createState()
|
||||
|
||||
// use repl compiler for >> 1s, making sure that idle/unused timeouts are not firing
|
||||
for (attempts in 1..10) {
|
||||
val codeLine1 = ReplCodeLine(attempts, "3 + 5")
|
||||
val res1 = repl.compile(codeLine1)
|
||||
val res1 = replCompiler.compile(compilerState, codeLine1)
|
||||
val res1c = res1 as? ReplCompileResult.CompiledClasses
|
||||
TestCase.assertNotNull("Unexpected compile result: $res1", res1c)
|
||||
Thread.sleep(200)
|
||||
|
||||
Reference in New Issue
Block a user