Re: [sbt] Tests hang with actor objects

195 views
Skip to first unread message

Eugene Vigdorchik

unread,
Jul 4, 2012, 7:47:50 AM7/4/12
to simple-b...@googlegroups.com
On Wed, Jul 4, 2012 at 2:55 PM, Gerd Riesselmann
<gerd.rie...@gmail.com> wrote:
> Hello,
>
> I noticed the following behaviour, which I think is a bug. It may as well be
> an error of mine, of course. SBT is version 0.12-RC3.
>
> If there are objects in the code that are actors, and if they are started,
> sbt test will never finish but wait for the actors to terminate. This was no
> issue in SBT 0.7.
>
> Here's a test case:
> https://github.com/gerdriesselmann/sbt-actor-object-testcase
Hi Gerd,
I'm not sure about sbt part (I believe there is a non-daemon thread
hanging around, but I'm not good enough in scala actors to predict
what that thread is), but starting an actor inside itself looks like a
bad idea to me:
Basically you side-effect in a constructor, and there is no-one to
stop the actor until it is finished by itself.

Eugene.
>
> --
> You received this message because you are subscribed to the Google Groups
> "simple-build-tool" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/simple-build-tool/-/8PBWtL1x7UMJ.
> To post to this group, send email to simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to
> simple-build-t...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/simple-build-tool?hl=en.

Eugene Vigdorchik

unread,
Jul 4, 2012, 2:18:09 PM7/4/12
to simple-b...@googlegroups.com
On Wed, Jul 4, 2012 at 4:01 PM, Gerd Riesselmann
<gerd.rie...@gmail.com> wrote:
> Hello Eugene,
>
> starting the actor in the constructor is just for convenience. Starting it
> from the outside does not change the behaviour of sbt test.
Right. Still leaving an actor running looks like a leak. I'm curious
how it relates to sbt and how it used to work before.

Cheers,
Eugene.
>
> Cheers,
>
> Gerd
> https://groups.google.com/d/msg/simple-build-tool/-/rxtrb3kOvKAJ.

Eugene Vigdorchik

unread,
Jul 6, 2012, 7:02:40 AM7/6/12
to simple-b...@googlegroups.com
On Fri, Jul 6, 2012 at 2:21 PM, Gerd Riesselmann
<gerd.rie...@gmail.com> wrote:
> I filed a bug report: https://github.com/harrah/xsbt/issues/497
I'm afraid declaring a bug solely on the basis of the fact it used to
work before doesn't convince.
So you either explain why you think it shouldn't hang or admit your
test has a leak and stop the actor after the test is done.

Eugene.
>
>
> On Wednesday, July 4, 2012 12:55:09 PM UTC+2, Gerd Riesselmann wrote:
>>
>> Hello,
>>
>> I noticed the following behaviour, which I think is a bug. It may as well
>> be an error of mine, of course. SBT is version 0.12-RC3.
>>
>> If there are objects in the code that are actors, and if they are started,
>> sbt test will never finish but wait for the actors to terminate. This was no
>> issue in SBT 0.7.
>>
>> Here's a test case:
>> https://github.com/gerdriesselmann/sbt-actor-object-testcase
>>
> --
> You received this message because you are subscribed to the Google Groups
> "simple-build-tool" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/simple-build-tool/-/X1fzPamoMEIJ.

jsuereth

unread,
Jul 6, 2012, 9:03:15 AM7/6/12
to simple-b...@googlegroups.com
Even in SBT and maven, it's a good idea to ensure you don't leak actor threads.  I know it's a PITA, but I've had to do this on a few codebases to ensure correct code.  I wouldn't call this a bug in SBT, more an annoyance of all actors libraries.   Some provide test-suite capabilities (like Akka) which will manage this for you.  I'd recommend making one for Scala actors if you're using them.   The minor investment of time is defintely worth it.   If you don't try to shut down the actor system at the end of the test, you'll actually *miss* a few potential issues in your system.    It's a very good idea to shutdown the actor system in your test, so much so I'd say to leave SBT as is.

- Josh

On Friday, July 6, 2012 7:02:40 AM UTC-4, Eugene Vigdorchik wrote:
On Fri, Jul 6, 2012 at 2:21 PM, Gerd Riesselmann
<gerd.rie...@gmail.com> wrote:
> I filed a bug report: https://github.com/harrah/xsbt/issues/497
I'm afraid declaring a bug solely on the basis of the fact it used to
work before doesn't convince.
So you either explain why you think it shouldn't hang or admit your
test has a leak and stop the actor after the test is done.

Eugene.
>
>
> On Wednesday, July 4, 2012 12:55:09 PM UTC+2, Gerd Riesselmann wrote:
>>
>> Hello,
>>
>> I noticed the following behaviour, which I think is a bug. It may as well
>> be an error of mine, of course. SBT is version 0.12-RC3.
>>
>> If there are objects in the code that are actors, and if they are started,
>> sbt test will never finish but wait for the actors to terminate. This was no
>> issue in SBT 0.7.
>>
>> Here's a test case:
>> https://github.com/gerdriesselmann/sbt-actor-object-testcase
>>
> --
> You received this message because you are subscribed to the Google Groups
> "simple-build-tool" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/simple-build-tool/-/X1fzPamoMEIJ.
>
> To post to this group, send email to simple-build-tool@googlegroups.com.
> To unsubscribe from this group, send email to

Martin Grigorov

unread,
Jul 6, 2012, 10:10:27 AM7/6/12
to simple-b...@googlegroups.com
Hi Gerd,

I'm also with the other guys on this.
In your code you may use "System.exit(0)" and this will stop the whole
VM and SBT cannot help you.

You can try to run the tests in a forked VM though.

On Fri, Jul 6, 2012 at 3:12 PM, Gerd Riesselmann
<gerd.rie...@gmail.com> wrote:
> Sight... I thought I did everyone a favor in tracing down what I think is a
> bug to a simple, reproducible test case. Instead all we do is talk about the
> code of the test case itself.
>
> Please, for a moment, abstract away from this code, and believe me I have an
> application which has objects that are actors and are always running,
> because they are started automatically by some complex logic. I know it is
> tempting to start a discussion about software architecture at this point,
> but please hesitate.
>
> It should be obvious, that I can't simply end them at the end of some test
> (which one?).
>
> And why should I? If I expect "sbt test" to compile, run the tests, and
> exit: Isn't this what it actually is supposed to do? It did right that in
> 0.7!
>
> However: I would also be satisfied it someone could show me how to execute
> code after the last test was run, so I could shutdown parts of the system
> manually.
>
> Cheers,
>
> Gerd
> https://groups.google.com/d/msg/simple-build-tool/-/_ICuG7lZ5DsJ.

Eugene Vigdorchik

unread,
Jul 6, 2012, 10:21:48 AM7/6/12
to simple-b...@googlegroups.com
On Fri, Jul 6, 2012 at 6:10 PM, Martin Grigorov
<martin....@gmail.com> wrote:
> Hi Gerd,
>
> I'm also with the other guys on this.
> In your code you may use "System.exit(0)" and this will stop the whole
> VM and SBT cannot help you.
>
> You can try to run the tests in a forked VM though.

As far as I understand, this won't help: the forked JVM will hang and
the main sbt process will hang waiting for it.
That said, I think the solution is simple, just mix in
org.scalatest.BeforeAndAfterAll and shutdown the actor system after
all the tests are run.

Eugene.
Reply all
Reply to author
Forward
0 new messages