diff options
author | Piotr Gabara <piotr.gabara@hotmail.com> | 2017-08-27 20:06:52 +0200 |
---|---|---|
committer | Piotr Gabara <piotr.gabara@hotmail.com> | 2017-09-05 16:37:22 +0200 |
commit | e82346820797bb2d80d0fada7f17c5880871edce (patch) | |
tree | 1b972cfffadb9de0f6f0c99f842ada1d58662fb8 /tests/src/test/scala | |
parent | febcdbcb4448fe1e754ecd08fb4df4bf6c6a211c (diff) | |
download | sttp-e82346820797bb2d80d0fada7f17c5880871edce.tar.gz sttp-e82346820797bb2d80d0fada7f17c5880871edce.tar.bz2 sttp-e82346820797bb2d80d0fada7f17c5880871edce.zip |
Make read and connection timeout configurable
Diffstat (limited to 'tests/src/test/scala')
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 |