Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw a custom exception for test timeouts #3551

Merged
merged 4 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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