Skip to content

Commit

Permalink
Merge pull request #3551 from armanbilge/issue/3503
Browse files Browse the repository at this point in the history
Throw a custom exception for test timeouts
  • Loading branch information
djspiewak authored Apr 24, 2023
2 parents 7e36fe5 + 70c908a commit a869178
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions tests/js/src/main/scala/cats/effect/DetectPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ trait DetectPlatform {
}

def isJS: Boolean = true
def isJVM: Boolean = false
def isNative: Boolean = false
}
1 change: 1 addition & 0 deletions tests/jvm/src/test/scala/cats/effect/DetectPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ package cats.effect
trait DetectPlatform {
def isWSL: Boolean = System.getProperty("os.version").contains("-WSL")
def isJS: Boolean = false
def isJVM: Boolean = true
def isNative: Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ package cats.effect
trait DetectPlatform {
def isWSL: Boolean = System.getProperty("os.version").contains("-WSL")
def isJS: Boolean = false
def isJVM: Boolean = false
def isNative: Boolean = true
}
7 changes: 5 additions & 2 deletions tests/shared/src/test/scala/cats/effect/Runners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.specs2.matcher.Matcher
import org.specs2.mutable.SpecificationLike
import org.specs2.specification.core.Execution

import scala.concurrent.{Future, Promise, TimeoutException}
import scala.concurrent.{Future, Promise}
import scala.concurrent.duration._
import scala.reflect.ClassTag

Expand Down Expand Up @@ -105,7 +105,8 @@ trait Runners extends SpecificationLike with TestInstances with RunnersPlatform
val r = runtime()
implicit val ec = r.compute

val cancel = r.scheduler.sleep(duration, { () => p.tryFailure(new TimeoutException); () })
val cancel =
r.scheduler.sleep(duration, { () => p.tryFailure(new TestTimeoutException); () })

f.onComplete { result =>
p.tryComplete(result)
Expand All @@ -115,3 +116,5 @@ trait Runners extends SpecificationLike with TestInstances with RunnersPlatform
p.future
}
}

class TestTimeoutException extends Exception
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import cats.syntax.all._

import scala.concurrent.duration._

class DeferredSpec extends BaseSpec { outer =>
class DeferredSpec extends BaseSpec with DetectPlatform { outer =>

"Deferred for Async" should {
tests(IO(Deferred.unsafe), IO(Deferred.unsafe))
Expand Down Expand Up @@ -180,7 +180,7 @@ class DeferredSpec extends BaseSpec { outer =>
d.get.as(1).parReplicateA(n).map(_.sum must be_==(n))
}
}
.replicateA_(100)
.replicateA_(if (isJVM) 100 else 1)
}
.as(true)
}
Expand Down
5 changes: 3 additions & 2 deletions tests/shared/src/test/scala/cats/effect/std/QueueSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ class BoundedQueueSpec extends BaseSpec with QueueTests[Queue] with DetectPlatfo
constructor(8) flatMap { q =>
val offerer = List.fill(8)(List.fill(8)(0)).parTraverse_(_.traverse(q.offer(_)))

(offerer &> 0.until(8 * 8).toList.traverse_(_ => q.take)).replicateA_(1000) *>
val iter = if (isJVM) 1000 else 1
(offerer &> 0.until(8 * 8).toList.traverse_(_ => q.take)).replicateA_(iter) *>
q.size.flatMap(s => IO(s mustEqual 0))
}
}
Expand All @@ -300,7 +301,7 @@ class BoundedQueueSpec extends BaseSpec with QueueTests[Queue] with DetectPlatfo
}
}

(offerer &> taker(0)).replicateA_(1000) *>
(offerer &> taker(0)).replicateA_(if (isJVM) 1000 else 1) *>
q.size.flatMap(s => IO(s mustEqual 0))
}
}
Expand Down

0 comments on commit a869178

Please sign in to comment.