From e8e1e61177069cdb89e89b3a41459ae19e84e914 Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Wed, 27 May 2009 22:58:02 +0000 Subject: Added test for #2000. --- test/files/jvm/actor-looping.check | 5 +++++ test/files/jvm/actor-looping.scala | 27 +++++++++++++++++++++++++++ test/files/jvm/actor-normal-exit.check | 2 ++ test/files/jvm/actor-normal-exit.scala | 26 ++++++++++++++++++++++++++ test/files/jvm/daemon-actor-termination.scala | 12 ++++++++++-- test/files/jvm/terminateLinked.check | 1 + test/files/jvm/terminateLinked.scala | 24 ++++++++++++++++++++++++ 7 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 test/files/jvm/actor-looping.check create mode 100644 test/files/jvm/actor-looping.scala create mode 100644 test/files/jvm/actor-normal-exit.check create mode 100644 test/files/jvm/actor-normal-exit.scala create mode 100644 test/files/jvm/terminateLinked.check create mode 100644 test/files/jvm/terminateLinked.scala diff --git a/test/files/jvm/actor-looping.check b/test/files/jvm/actor-looping.check new file mode 100644 index 0000000000..a6f5c2e73a --- /dev/null +++ b/test/files/jvm/actor-looping.check @@ -0,0 +1,5 @@ +received A +received A +received A +received A +received last A diff --git a/test/files/jvm/actor-looping.scala b/test/files/jvm/actor-looping.scala new file mode 100644 index 0000000000..9599adbb2c --- /dev/null +++ b/test/files/jvm/actor-looping.scala @@ -0,0 +1,27 @@ + +import scala.actors.Actor._ + +object Test { + case object A + + def main(args: Array[String]) { + val a = actor { + var cnt = 0 + loop { + react { + case A => + cnt += 1 + if (cnt % 2 != 0) continue + if (cnt < 10) + println("received A") + else { + println("received last A") + exit() + } + } + } + } + + for (i <- 0 until 10) a ! A + } +} diff --git a/test/files/jvm/actor-normal-exit.check b/test/files/jvm/actor-normal-exit.check new file mode 100644 index 0000000000..6865f83b90 --- /dev/null +++ b/test/files/jvm/actor-normal-exit.check @@ -0,0 +1,2 @@ +Done +slave exited for reason 'normal diff --git a/test/files/jvm/actor-normal-exit.scala b/test/files/jvm/actor-normal-exit.scala new file mode 100644 index 0000000000..40dc7b7da4 --- /dev/null +++ b/test/files/jvm/actor-normal-exit.scala @@ -0,0 +1,26 @@ + +import scala.actors.{Actor, Exit} + +object Test { + object Master extends Actor { + trapExit = true + def act() { + Slave.start() + react { + case Exit(from, reason) => + println("slave exited for reason " + reason) + } + } + } + + object Slave extends Actor { + def act() { + link(Master) + println("Done") + } + } + + def main(args: Array[String]) { + Master.start() + } +} diff --git a/test/files/jvm/daemon-actor-termination.scala b/test/files/jvm/daemon-actor-termination.scala index 322efbe212..c3dd58e253 100644 --- a/test/files/jvm/daemon-actor-termination.scala +++ b/test/files/jvm/daemon-actor-termination.scala @@ -1,8 +1,16 @@ -import scala.actors.DaemonActor +import scala.actors.{Actor, DefaultExecutorScheduler} -/* Test that a DaemonActor that hasn't finished does not prevent termination */ +/* Test that a daemon Actor that hasn't finished does not prevent termination */ + +trait DaemonActor extends Actor { + override def scheduler = + Test.daemonSched +} object Test { + val daemonSched = + new DefaultExecutorScheduler(true) + class MyDaemon extends DaemonActor { def act() { println("I'm going to make you wait.") diff --git a/test/files/jvm/terminateLinked.check b/test/files/jvm/terminateLinked.check new file mode 100644 index 0000000000..a965a70ed4 --- /dev/null +++ b/test/files/jvm/terminateLinked.check @@ -0,0 +1 @@ +Done diff --git a/test/files/jvm/terminateLinked.scala b/test/files/jvm/terminateLinked.scala new file mode 100644 index 0000000000..2a3b7fb49e --- /dev/null +++ b/test/files/jvm/terminateLinked.scala @@ -0,0 +1,24 @@ +import scala.actors.Actor +import Actor._ + +object Test { + def main(args: Array[String]) { + val a = actor { + for (_ <- 1 to 10) + receive { + case b: Actor => link(b) + } + throw new Exception + } + + for (_ <- 1 to 10) + actor { + a ! self + react { + case _ => + } + } + + println("Done") + } +} -- cgit v1.2.3