From 651af891813001c517c5c821b6b75fb13ca252b5 Mon Sep 17 00:00:00 2001 From: adamw Date: Fri, 28 Jul 2017 16:30:26 +0200 Subject: Closing handlers after tests --- tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala | 9 +++++++++ .../test/scala/com/softwaremill/sttp/StreamingTests.scala | 13 +++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'tests/src/test/scala') diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala index 262fd35..90aab02 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala @@ -114,6 +114,8 @@ class BasicTests override def port = 51823 + var closeHandlers: List[() => Unit] = Nil + runTests("HttpURLConnection")(HttpURLConnectionSttpHandler, ForceWrappedValue.id) runTests("Akka HTTP")(AkkaHttpSttpHandler.usingActorSystem(actorSystem), @@ -129,6 +131,8 @@ class BasicTests implicit handler: SttpHandler[R, Nothing], forceResponse: ForceWrappedValue[R]): Unit = { + closeHandlers = handler.close _ :: closeHandlers + val postEcho = sttp.post(uri"$endpoint/echo") val testBody = "this is the body" val testBodyBytes = testBody.getBytes("UTF-8") @@ -387,4 +391,9 @@ class BasicTests } } } + + override protected def afterAll(): Unit = { + closeHandlers.foreach(_()) + super.afterAll() + } } diff --git a/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala b/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala index 7bc842c..5f04126 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala @@ -35,13 +35,16 @@ class StreamingTests override def port = 51824 + val akkaHandler = AkkaHttpSttpHandler.usingActorSystem(actorSystem) + val monixHandler = MonixAsyncHttpClientHandler() + akkaStreamingTests() monixStreamingTests() val body = "streaming test" def akkaStreamingTests(): Unit = { - implicit val handler = AkkaHttpSttpHandler.usingActorSystem(actorSystem) + implicit val handler = akkaHandler "Akka HTTP" should "stream request body" in { val response = sttp @@ -68,7 +71,7 @@ class StreamingTests } def monixStreamingTests(): Unit = { - implicit val handler = MonixAsyncHttpClientHandler() + implicit val handler = monixHandler import monix.execution.Scheduler.Implicits.global val body = "streaming test" @@ -127,4 +130,10 @@ class StreamingTests new String(bytes, "utf-8") should include("") } } + + override protected def afterAll(): Unit = { + akkaHandler.close() + monixHandler.close() + super.afterAll() + } } -- cgit v1.2.3