aboutsummaryrefslogtreecommitdiff
path: root/tests/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/test')
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala33
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala2
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala5
3 files changed, 37 insertions, 3 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 = {
diff --git a/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala b/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
index 4e03fc2..53ea798 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
@@ -25,7 +25,7 @@ class IllTypedTests extends FlatSpec with Matchers {
val thrown = intercept[ToolBoxError] {
EvalScala("""
import com.softwaremill.sttp._
- implicit val sttpHandler = HttpURLConnectionHandler
+ implicit val sttpHandler = HttpURLConnectionHandler()
sttp.send()
""")
}
diff --git a/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala b/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala
index 6292ecd..7e4d5a9 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala
@@ -17,7 +17,10 @@ import scala.concurrent.duration._
import scala.language.higherKinds
import scalaz._
-trait TestHttpServer extends BeforeAndAfterAll with ScalaFutures with TestingPatience {
+trait TestHttpServer
+ extends BeforeAndAfterAll
+ with ScalaFutures
+ with TestingPatience {
this: Suite =>
protected implicit val actorSystem: ActorSystem = ActorSystem("sttp-test")
import actorSystem.dispatcher