Writing tests using dispatch-reboot 0.9.5

85 views
Skip to first unread message

Helen Williamson

unread,
Mar 20, 2013, 9:11:30 AM3/20/13
to dispatc...@googlegroups.com
Hiya,

I've got a project that I'm upgrading from dispatch-classic to dispatch-reboot. In my project I use dispatch in two cases:
  1. To call external services from my source code
  2. To call a server containing my source backed by unfiltered (for testing)
After a bit of trial and error, the source and tests have been successfully converted. However there's a bit of an issue. When I run the whole suite of tests, sbt hangs and doesn't complete after the last test is run.

I thought this might be something to do with threads from Http still hanging around, so I've added the following to all my tests:

class MySpecification extends FeatureSpec with BeforeAndAfterAll {

  override def afterAll() {
    Http.shutdown()
  }

  ...

}

However I now get the following exception for the second and subsequent tests:

Scenario: My test *** FAILED ***
[info]   java.io.IOException: Closed
[info]   at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.doConnect(NettyAsyncHttpProvider.java:873)
[info]   at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.execute(NettyAsyncHttpProvider.java:858)
[info]   at com.ning.http.client.AsyncHttpClient.executeRequest(AsyncHttpClient.java:512)
[info]   at dispatch.HttpExecutor$$anonfun$apply$2.apply(execution.scala:78)
[info]   at dispatch.HttpExecutor$$anonfun$apply$2.apply(execution.scala:78)
[info]   at dispatch.ListenableFuturePromise.underlying(promise.scala:228)
[info]   at dispatch.ListenableFuturePromise.claim(promise.scala:231)
[info]   at dispatch.Promise$$anonfun$result$1.apply(promise.scala:64)
[info]   at scala.util.control.Exception$Catch$$anonfun$either$1.apply(Exception.scala:110)
[info]   at scala.util.control.Exception$Catch$$anonfun$either$1.apply(Exception.scala:110)

I've looked at the tests in dispatch-reboot and they seem to be shutting down Http using cleanup from sbt. I've done the same but just added a simple println statement (to see if it's being called). Unfortunately this doesn't print out anything.

Has anyone had any success at using dispatch-reboot in tests and if so, have you done anything different?

Thanks, Helen

Nathan Hamblen

unread,
Mar 20, 2013, 10:19:55 AM3/20/13
to dispatc...@googlegroups.com
On 03/20/2013 09:11 AM, Helen Williamson wrote:
> Has anyone had any success at using dispatch-reboot in tests and if so,
> have you done anything different?

Dispatch uses scalacheck to test itself. The trick is to shut it down
only one time. After that you won't be able to use it again, since by
default it's sharing executors across all instances.

But now that dispatch uses all daemon threads you usually don't have to
shut it down at all. If you use dispatch in a console you should be able
to exit without shutting it down. So, if you can figure out what actions
from your tests are causing Dispatch (or something else?) to spin a
non-daemon thread, then you could perhaps work around the need to call
shutdown explicitly.

Nathan
Reply all
Reply to author
Forward
0 new messages