aboutsummaryrefslogtreecommitdiff
path: root/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
diff options
context:
space:
mode:
authorPiotr Gabara <piotr.gabara@hotmail.com>2017-08-27 20:06:52 +0200
committerPiotr Gabara <piotr.gabara@hotmail.com>2017-09-05 16:37:22 +0200
commite82346820797bb2d80d0fada7f17c5880871edce (patch)
tree1b972cfffadb9de0f6f0c99f842ada1d58662fb8 /tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
parentfebcdbcb4448fe1e754ecd08fb4df4bf6c6a211c (diff)
downloadsttp-e82346820797bb2d80d0fada7f17c5880871edce.tar.gz
sttp-e82346820797bb2d80d0fada7f17c5880871edce.tar.bz2
sttp-e82346820797bb2d80d0fada7f17c5880871edce.zip
Make read and connection timeout configurable
Diffstat (limited to 'tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala')
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
index aaa6f4c..f544750 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
@@ -26,6 +26,8 @@ import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{path => _, _}
import scala.concurrent.ExecutionContext.Implicits.global
+import scala.concurrent.Future
+import scala.concurrent.duration._
import scala.language.higherKinds
class BasicTests
@@ -163,13 +165,19 @@ class BasicTests
path("loop") {
redirect("/redirect/loop", StatusCodes.Found)
}
+ } ~ pathPrefix("timeout") {
+ complete {
+ akka.pattern.after(1.second, using = actorSystem.scheduler)(
+ Future.successful("Done"))
+ }
}
override def port = 51823
var closeHandlers: List[() => Unit] = Nil
- runTests("HttpURLConnection")(HttpURLConnectionHandler, ForceWrappedValue.id)
+ runTests("HttpURLConnection")(HttpURLConnectionHandler(),
+ ForceWrappedValue.id)
runTests("Akka HTTP")(AkkaHttpHandler.usingActorSystem(actorSystem),
ForceWrappedValue.future)
runTests("Async Http Client - Future")(AsyncHttpClientFutureHandler(),
@@ -211,6 +219,7 @@ class BasicTests
downloadFileTests()
multipartTests()
redirectTests()
+ timeoutTests()
def parseResponseTests(): Unit = {
name should "parse response as string" in {
@@ -633,6 +642,28 @@ class BasicTests
resp.history should have size (FollowRedirectsHandler.MaxRedirects)
}
}
+
+ def timeoutTests(): Unit = {
+ name should "fail if read timeout is not big enough" in {
+ val request = sttp
+ .get(uri"$endpoint/timeout")
+ .readTimeout(200.milliseconds)
+ .response(asString)
+
+ intercept[Throwable] {
+ request.send().force()
+ }
+ }
+
+ name should "not fail if read timeout is big enough" in {
+ val request = sttp
+ .get(uri"$endpoint/timeout")
+ .readTimeout(5.seconds)
+ .response(asString)
+
+ request.send().force().unsafeBody should be("Done")
+ }
+ }
}
override protected def afterAll(): Unit = {