Skip to content

Commit

Permalink
Iterating on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
farmdawgnation committed Aug 18, 2024
1 parent 1a81db7 commit 215b154
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
5 changes: 3 additions & 2 deletions core/src/test/scala/iterable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ with DispatchCleanup {

property("iterable future values") = forAll(Gen.alphaStr) {
(sampleL: String) =>
val sample = sampleL.take(10) // n^2 concurrent requests
val sample: String = sampleL.take(10) // n^2 concurrent requests
val values: Future[Iterable[(Int,Int)]] = for {
chr1 <- split(sample).values.flatten
chr2 <- split(sample.reverse).values
c1 <- value(chr1)
c2 <- value(chr2)
} yield (c1, c2)

values() ?= (for {
c1 <- sample
c2 <- sample.reverse
Expand All @@ -67,7 +68,7 @@ with DispatchCleanup {
chr1 <- split(sample).either.right.values
c1 <- value(chr1)
} yield Right(c1)
values().right.get ?= (for {
values().toOption.get ?= (for {
c1 <- sample
} yield c1.toInt)
}
Expand Down
12 changes: 6 additions & 6 deletions core/src/test/scala/retry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ with DispatchCleanup {
def succeedOn(successRetry: Int)() = {
Http.default(localhost << Map("echo" -> retried.getAndIncrement.toString)
OK as.String).either.map { eth =>
eth.right.flatMap { numstr =>
eth.flatMap { numstr =>
val num = numstr.toInt
if (num == successRetry)
Right(num)
Expand All @@ -55,19 +55,19 @@ with DispatchCleanup {

property("succeed on the first request") = forAll(smallNums) { maxRetries =>
val rc = new RetryCounter
val p = retry.Backoff(maxRetries)(() => rc.succeedOn(0))
val p = retry.Backoff(maxRetries)(() => rc.succeedOn(0)())
p() ?= Right(0)
}

property("succeed on the max retry") = forAll(smallNums) { maxRetries =>
val rc = new RetryCounter
val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries))
val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries)())
p() ?= Right(maxRetries)
}

property("fail after max retries") = forAll(smallNums) { maxRetries =>
val rc = new RetryCounter
val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries + 1))
val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries + 1)())
p() ?= Left(maxRetries)
}

Expand All @@ -76,7 +76,7 @@ with DispatchCleanup {
val p = retry.Backoff(
max,
Duration(2, TimeUnit.MICROSECONDS)
)(() => rc.succeedOn(max))
)(() => rc.succeedOn(max)())
p() ?= Right(max)
}

Expand All @@ -85,7 +85,7 @@ with DispatchCleanup {
val p = retry.Pause(
max,
Duration(500, TimeUnit.MICROSECONDS)
)(() => rc.succeedOn(max + 1))
)(() => rc.succeedOn(max + 1)())
p() ?= Left(max)
}
}
7 changes: 5 additions & 2 deletions json4sjackson/src/test/scala/json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ with DispatchCleanup {

object In extends Params.Extract("in", Params.first)
netty.Server.local(port).handler(netty.cycle.Planify {
case Params(In(in)) => Json(("out" -> in))
case Params(In(in)) => Json(("out" -> in)).asInstanceOf[ComposeResponse[io.netty.handler.codec.http.HttpResponse]]
}).start()
}

Expand All @@ -42,6 +42,9 @@ with DispatchCleanup {
val res = Http.default(
localhost <:< Map("Accept" -> "application/json") <<? Map("in" -> sample) > as.json4s.Json
)
sample == (for { JObject(fields) <- res(); JField("out", JString(o)) <- fields } yield o).head
sample == (for {
case JObject(fields) <- res()
case JField("out", JString(o)) <- fields
} yield o).head
}
}
8 changes: 6 additions & 2 deletions json4snative/src/test/scala/json.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dispatch.spec

import org.scalacheck._
import org.scalacheck.util.Pretty.prettyAny

object BasicSpecification
extends Properties("Json4s Native Json")
Expand Down Expand Up @@ -30,7 +31,7 @@ with DispatchCleanup {

object In extends Params.Extract("in", Params.first)
netty.Server.local(port).handler(netty.cycle.Planify {
case Params(In(in)) => Json(("out" -> in))
case Params(In(in)) => Json(("out" -> in)).asInstanceOf[ComposeResponse[io.netty.handler.codec.http.HttpResponse]]
}).start()
}

Expand All @@ -42,6 +43,9 @@ with DispatchCleanup {
val res = Http.default(
localhost <:< Map("Accept" -> "application/json") <<? Map("in" -> sample) > as.json4s.Json
)
sample == (for { JObject(fields) <- res(); JField("out", JString(o)) <- fields } yield o).head
sample == (for {
case JObject(fields) <- res()
case JField("out", JString(o)) <- fields
} yield o).head
}
}
2 changes: 1 addition & 1 deletion jsoup/src/test/scala/soup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ with DispatchCleanup {
object Echo extends Params.Extract("echo", Params.first)
netty.Server.local(port).handler(netty.cycle.Planify {
case Path("/echo") & Params(Echo(echo)) =>
Html(<html><head></head><body><div id="echo">{echo}</div></body></html>)
ResponseString(Html(<html><head></head><body><div id="echo">{echo}</div></body></html>).toString())
case Path("/unclean") & Params(Echo(echo)) =>
HtmlContent ~> ResponseString(UnsafeFormat format echo)
case Path("/relative") & Params(Echo(echo)) =>
Expand Down
2 changes: 1 addition & 1 deletion project/common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sbt._
object Common {
import Keys._

val defaultScalaVersion = "2.13.14"
val defaultScalaVersion = "3.4.2"

val testSettings:Seq[Setting[_]] = Seq(
Test / testOptions += Tests.Cleanup { loader =>
Expand Down
2 changes: 1 addition & 1 deletion tagsoup/src/test/scala/soup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with DispatchCleanup {
object Echo extends Params.Extract("echo", Params.first)
netty.Server.local(port).handler(netty.cycle.Planify {
case Path("/echo") & Params(Echo(echo)) =>
Html(<html><head></head><body><div id="echo">{echo}</div></body></html>)
ResponseString(Html(<html><head></head><body><div id="echo">{echo}</div></body></html>).toString())
}).start()
}

Expand Down

0 comments on commit 215b154

Please sign in to comment.