diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-05-17 16:16:20 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-05-17 16:16:20 -0700 |
commit | 8213a757a0f8f3cd00ff294301b877ac5e05cb92 (patch) | |
tree | 77703de75a7ea1dcd3c71a917a2548cd6b015573 /test/files/run | |
parent | aea3cbc91b31f482c05e65c3fd1c1b50164eda16 (diff) | |
parent | 538aa22ec8144430e778a34bc749eccb6f5dbf4c (diff) | |
download | scala-8213a757a0f8f3cd00ff294301b877ac5e05cb92.tar.gz scala-8213a757a0f8f3cd00ff294301b877ac5e05cb92.tar.bz2 scala-8213a757a0f8f3cd00ff294301b877ac5e05cb92.zip |
Merge pull request #2538 from som-snytt/issue/6488-process-io-destroy
SI-6488 Interrupt i/o threads on process destroy
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/t6488.check | 1 | ||||
-rw-r--r-- | test/files/run/t6488.scala | 57 |
2 files changed, 55 insertions, 3 deletions
diff --git a/test/files/run/t6488.check b/test/files/run/t6488.check deleted file mode 100644 index 35821117c8..0000000000 --- a/test/files/run/t6488.check +++ /dev/null @@ -1 +0,0 @@ -Success diff --git a/test/files/run/t6488.scala b/test/files/run/t6488.scala index 487614ecfd..e234876fbe 100644 --- a/test/files/run/t6488.scala +++ b/test/files/run/t6488.scala @@ -1,11 +1,64 @@ -import sys.process._ +import scala.sys.process._ +import scala.util.Try +import scala.util.Properties.{ javaHome, javaClassPath } +import java.io.{ File, IOException } +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit._ +import java.util.concurrent.atomic._ + object Test { + /* // Program that prints "Success" if the command was successfully run then destroyed // It will silently pass if the command "/bin/ls" does not exist - // It will fail due to the uncatchable exception in t6488 race condition + // It will fail due to the uncatchable exception in t6488 race condition, + // i.e., if any uncaught exceptions on spawned threads are printed. def main(args: Array[String]) { try Process("/bin/ls").run(ProcessLogger { _ => () }).destroy catch { case _ => () } println("Success") } + */ + + // Show that no uncaught exceptions are thrown on spawned I/O threads + // when the process is destroyed. The default handler will print + // stack traces in the failing case. + def main(args: Array[String]) { + if (args.nonEmpty && args(0) == "data") + data() + else + test() // args(0) == "jvm" + } + + // fork the data spewer, wait for input, then destroy the process + def test() { + val f = new File(javaHome, "bin").listFiles.sorted filter (_.getName startsWith "java") find (_.canExecute) getOrElse { + // todo signal test runner that test is skipped + new File("/bin/ls") // innocuous + } + //Process(f.getAbsolutePath).run(ProcessLogger { _ => () }).destroy + val reading = new CountDownLatch(1) + val count = new AtomicInteger + def counted = count.get + val command = s"${f.getAbsolutePath} -classpath ${javaClassPath} Test data" + Try { + Process(command) run ProcessLogger { (s: String) => + //Console println s"[[$s]]" // java help + count.getAndIncrement + reading.countDown + Thread.`yield`() + } + } foreach { (p: Process) => + val ok = reading.await(10, SECONDS) + if (!ok) Console println "Timed out waiting for process output!" + p.destroy() + } + //Console println s"Read count $counted lines" + } + + // spew something + def data() { + def filler = "." * 100 + for (i <- 1 to 1000) + Console println s"Outputting data line $i $filler" + } } |