<commit_before>package org.scalatra

import scala.concurrent._
import ExecutionContext.Implicits.global
import test.scalatest.ScalatraWordSpec

class RouteConcurrencyServlet extends ScalatraServlet {
  for {
    i <- 0 until 250
    x = Future { get(false) { "/"} }
  } x

  val postRoutes = for {
    i <- 0 until 250
    x = Future { post(false) { "/"} }
  } yield x

  for {
    route <- postRoutes.take(250)
    x = Future { post(false) {}; post(false) {}} // add some more routes while we're removing
    y = Future { route.foreach { route => removeRoute("POST", route) }}
  } (x, y)

  get("/count/:method") {
    routes(HttpMethod(params("method"))).size.toString
  }
}

class RouteConcurrencySpec extends ScalatraWordSpec {
  addServlet(classOf[RouteConcurrencyServlet], "/*")

  "A scalatra kernel " should {
    "support adding routes concurrently" in {
      get("/count/get") {
        body should equal ("251") // the 500 we added in the future, plus this count route
      }
    }<commit_msg>Fix route concurrency spec<commit_after>package org.scalatra

import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits.global
import test.scalatest.ScalatraWordSpec

class RouteConcurrencyServlet extends ScalatraServlet {
  for {
    i <- 0 until 250
    x = Future { get(false) { "/"} }
  } x

  val postRoutes = for {
    i <- 0 until 250
    x = Future { post(false) { "/"} }
  } yield x

  val b = for {
    route <- postRoutes.take(250)
    x = Future { post(false) {}; post(false) {}} // add some more routes while we're removing
    y = Future { route.foreach { route => removeRoute("POST", route) }}
  } yield (x, y)
  Await.result(Future.sequence(b map (kv => kv._1.flatMap(_ => kv._2))), 1 second)

  get("/count/:method") {
    routes(HttpMethod(params("method"))).size.toString
  }
}

class RouteConcurrencySpec extends ScalatraWordSpec {
  addServlet(classOf[RouteConcurrencyServlet], "/*")

  "A scalatra kernel " should {
    "support adding routes concurrently" in {
      get("/count/get") {
        body should equal ("251") // the 500 we added in the future, plus this count route
      }
    }
{'fraction_non_alphanumeric': 0.13073713490959665, 'fraction_numerical': 0.017153453871117292, 'mean_word_length': 3.223091976516634, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '1789655', 'n_tokens_mistral': 709, 'n_tokens_neox': 660, 'n_words': 189}