@@ -430,6 +430,7 @@ class SwingBuilderConsoleTest extends GroovySwingTestCase {
430430
431431 console. inputArea. text = ' throw new Exception()'
432432 console. runScript(new EventObject ([:]))
433+ waitForScriptCompletion(console)
433434
434435 def doc = console. outputArea. document
435436 assert doc. getText(0 , doc. length) =~ / java.lang.Exception/
@@ -544,18 +545,21 @@ class SwingBuilderConsoleTest extends GroovySwingTestCase {
544545
545546 console. inputArea. text = ' println "test1"'
546547 console. runScript()
548+ waitForScriptCompletion(console)
547549
548550 assert ' test1' == doc. getText(0 , doc. length). trim()
549551 assert ' ' == doc2. getText(0 , doc2. length). trim()
550552
551553 console2. inputArea. text = ' println "test2"'
552554 console2. runScript()
555+ waitForScriptCompletion(console2)
553556
554557 assert ' test1' == doc. getText(0 , doc. length). trim()
555558 assert ' test2' == doc2. getText(0 , doc2. length). trim()
556559
557560 console2. inputArea. text = ' System.err.println "error2"'
558561 console2. runScript()
562+ waitForScriptCompletion(console2)
559563
560564 assert ' test1' == doc. getText(0 , doc. length). trim()
561565 assert doc2. getText(0 , doc2. length) ==~ / (?s)(test2)[^\w ].*(error2).*/
@@ -591,11 +595,13 @@ class SwingBuilderConsoleTest extends GroovySwingTestCase {
591595 console. inputEditor. textEditor. text = scriptSource
592596
593597 console. runScript(new EventObject ([:]))
598+ waitForScriptCompletion(console)
594599 assert console. config. getOptimizationOptions(). get(CompilerConfiguration . INVOKEDYNAMIC )
595600 assert outputDocument. getText(0 , outputDocument. length) == ' Result: foobar'
596601
597602 console. outputArea. text = ' '
598603 console. runScript(new EventObject ([:]))
604+ waitForScriptCompletion(console)
599605 assert console. config. getOptimizationOptions(). get(CompilerConfiguration . INVOKEDYNAMIC )
600606 assert outputDocument. getText(0 , outputDocument. length) == ' Result: foobar'
601607 } finally {
@@ -606,4 +612,10 @@ class SwingBuilderConsoleTest extends GroovySwingTestCase {
606612 }
607613 }
608614
615+ private static void waitForScriptCompletion (Console console ) {
616+ Thread thread = console. runThread
617+ thread?. join(5000 )
618+ assert thread == null || ! thread. alive
619+ }
620+
609621}
0 commit comments