<commit_before>package org.http4s.client
package blaze

import cats.effect._
import cats.effect.concurrent.{Deferred, Ref}
import cats.implicits._
import fs2.Stream
import java.util.concurrent.TimeoutException
import javax.servlet.ServletOutputStream
import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}
import org.http4s._
import org.http4s.client.testroutes.GetRoutes
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.util.Random

class BlazeClientSpec extends Http4sSpec {

  private val timeout = 30.seconds

  def mkClient(
      maxConnectionsPerRequestKey: Int,
      responseHeaderTimeout: Duration = 1.minute,
      requestTimeout: Duration = 1.minute
  ) =
    BlazeClientBuilder[IO](testExecutionContext)
      .withSslContext(bits.TrustingSslContext)
      .withCheckEndpointAuthentication(false)
      .withResponseHeaderTimeout(responseHeaderTimeout)
      .withRequestTimeout(requestTimeout)
      .withMaxConnectionsPerRequestKey(Function.const(maxConnectionsPerRequestKey))
      .resource

  private def testServlet = new HttpServlet {
    override def doGet(req: HttpServletRequest, srv: HttpServletResponse): Unit =
      GetRoutes.getPaths.get(req.getRequestURI) match {
        case Some(resp) =>
          srv.setStatus(resp.status.code)
          resp.headers.foreach { h =>
            srv.addHeader(h.name.toString, h.value)
          }

          val os: ServletOutputStream = srv.getOutputStream

          val writeBody: IO[Unit] = resp.body
            .evalMap { byte =>
              IO(os.write(Array(byte)))
            }
            .compile
            .drain
          val flushOutputStream: IO[Unit] = IO(os.flush())
          (writeBody *> IO.sleep(Random.nextInt(1000).millis) *> flushOutputStream)
            .unsafeRunSync()

        case None => srv.sendError(404)
      }

    override def doPost(req: HttpServletRequest, resp: HttpServletResponse): Unit = {
      resp.setStatus(Status.Ok.code)
      req.getInputStream.close()
    }
  }
<commit_msg>Don't sleep randomly in test servlet<commit_after>package org.http4s.client
package blaze

import cats.effect._
import cats.effect.concurrent.{Deferred, Ref}
import cats.implicits._
import fs2.Stream
import java.util.concurrent.TimeoutException
import javax.servlet.ServletOutputStream
import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}
import org.http4s._
import org.http4s.client.testroutes.GetRoutes
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.util.Random

class BlazeClientSpec extends Http4sSpec {

  private val timeout = 30.seconds

  def mkClient(
      maxConnectionsPerRequestKey: Int,
      responseHeaderTimeout: Duration = 1.minute,
      requestTimeout: Duration = 1.minute
  ) =
    BlazeClientBuilder[IO](testExecutionContext)
      .withSslContext(bits.TrustingSslContext)
      .withCheckEndpointAuthentication(false)
      .withResponseHeaderTimeout(responseHeaderTimeout)
      .withRequestTimeout(requestTimeout)
      .withMaxConnectionsPerRequestKey(Function.const(maxConnectionsPerRequestKey))
      .resource

  private def testServlet = new HttpServlet {
    override def doGet(req: HttpServletRequest, srv: HttpServletResponse): Unit =
      GetRoutes.getPaths.get(req.getRequestURI) match {
        case Some(resp) =>
          srv.setStatus(resp.status.code)
          resp.headers.foreach { h =>
            srv.addHeader(h.name.toString, h.value)
          }

          val os: ServletOutputStream = srv.getOutputStream

          val writeBody: IO[Unit] = resp.body
            .evalMap { byte =>
              IO(os.write(Array(byte)))
            }
            .compile
            .drain
          val flushOutputStream: IO[Unit] = IO(os.flush())
          (writeBody *> flushOutputStream).unsafeRunSync()

        case None => srv.sendError(404)
      }

    override def doPost(req: HttpServletRequest, resp: HttpServletResponse): Unit = {
      resp.setStatus(Status.Ok.code)
      req.getInputStream.close()
    }
  }

{'fraction_non_alphanumeric': 0.09084213110729192, 'fraction_numerical': 0.006874539651362632, 'mean_word_length': 3.1741803278688523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6745586', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1144, 'n_words': 223}