-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly return 408 when timeout is hit
Previously, we would return 503 Service Unavailable, suggesting that failures should not be retried and leading to confusion with early timeout being hit. Now, we return 408 Request Timeout which is more explicit and easier to monitor.
- Loading branch information
Showing
3 changed files
with
94 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
core/src/test/scala/com.snowplowanalytics.snowplow.collector.core/HttpServerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.snowplowanalytics.snowplow.collector.core | ||
|
||
import org.specs2.mutable.Specification | ||
import cats.effect.IO | ||
|
||
import org.http4s.client.Client | ||
import org.http4s._ | ||
import org.http4s.dsl.io._ | ||
import org.http4s.implicits._ | ||
import scala.concurrent.duration._ | ||
import cats.effect.testing.specs2._ | ||
|
||
class HttpServerSpecification extends Specification with CatsEffect { | ||
|
||
"HttpServer" should { | ||
"manage request timeout" should { | ||
"timeout threshold is configured" in { | ||
val config = | ||
TestUtils | ||
.testConfig | ||
.copy(networking = TestUtils.testConfig.networking.copy(responseHeaderTimeout = 100.millis)) | ||
val routes = HttpRoutes.of[IO] { | ||
case _ -> Root / "fast" => | ||
Ok("Fast") | ||
case _ -> Root / "never" => | ||
IO.never[Response[IO]] | ||
} | ||
val healthRoutes = HttpRoutes.of[IO] { | ||
case _ -> Root / "health" => | ||
Ok("ok") | ||
} | ||
val httpApp = HttpServer.httpApp( | ||
routes, | ||
healthRoutes, | ||
config.hsts, | ||
config.networking, | ||
config.debug.http | ||
) | ||
val client: Client[IO] = Client.fromHttpApp(httpApp) | ||
val request: Request[IO] = Request(method = Method.GET, uri = uri"/never") | ||
val res: IO[String] = client.expect[String](request) | ||
|
||
res | ||
.attempt | ||
.map(_ must beLeft[Throwable].which { | ||
case org.http4s.client.UnexpectedStatus(Status.RequestTimeout, _, _) => true | ||
case _ => false | ||
}) | ||
} | ||
} | ||
} | ||
} |