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

Make ScalaTest retrying effect generic #472

Open
wants to merge 2 commits into
base: series/1.x
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package cats.effect.testing.scalatest

import cats.effect.IO
import cats.effect.{Async, IO}
import cats.effect.std.Dispatcher
import cats.effect.testing.RuntimePlatform
import cats.effect.unsafe.IORuntime
import cats.syntax.all._
import org.scalactic.source.Position
import org.scalatest.AsyncTestSuite
import org.scalatest.enablers.Retrying
Expand All @@ -28,10 +30,16 @@ trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport with RuntimePla

implicit lazy val ioRuntime: IORuntime = createIORuntime(executionContext)

implicit def ioRetrying[T]: Retrying[IO[T]] = new Retrying[IO[T]] {
override def retry(timeout: Span, interval: Span, pos: Position)(fun: => IO[T]): IO[T] =
IO.fromFuture(
IO(Retrying.retryingNatureOfFutureT[T](IORuntime.global.compute).retry(timeout, interval, pos)(fun.unsafeToFuture())),
)
implicit def ioRetrying[T]: Retrying[IO[T]] = fRetrying

implicit def fRetrying[F[_], T](implicit F: Async[F]): Retrying[F[T]] = new Retrying[F[T]] {
override def retry(timeout: Span, interval: Span, pos: Position)(fun: => F[T]): F[T] =
Dispatcher.sequential[F].use { dispatcher =>
F.fromFuture(
F.executionContext.map(
Retrying.retryingNatureOfFutureT[T](_).retry(timeout, interval, pos)(dispatcher.unsafeToFuture(fun))
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package cats.effect.testing.scalatest

import cats.effect.IO
import cats.effect.{Async, IO}
import cats.effect.std.Dispatcher
import cats.effect.testing.RuntimePlatform
import cats.effect.unsafe.IORuntime
import cats.syntax.all._
import org.scalactic.source.Position
import org.scalatest.AsyncTestSuite
import org.scalatest.enablers.Retrying
Expand All @@ -28,10 +30,16 @@ trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport with RuntimePla

implicit lazy val ioRuntime: IORuntime = IORuntime.global

implicit def ioRetrying[T]: Retrying[IO[T]] = new Retrying[IO[T]] {
override def retry(timeout: Span, interval: Span, pos: Position)(fun: => IO[T]): IO[T] =
IO.fromFuture(
IO(Retrying.retryingNatureOfFutureT[T](IORuntime.global.compute).retry(timeout, interval, pos)(fun.unsafeToFuture())),
)
implicit def ioRetrying[T]: Retrying[IO[T]] = fRetrying

implicit def fRetrying[F[_], T](implicit F: Async[F]): Retrying[F[T]] = new Retrying[F[T]] {
override def retry(timeout: Span, interval: Span, pos: Position)(fun: => F[T]): F[T] =
Dispatcher.sequential[F].use { dispatcher =>
F.fromFuture(
F.executionContext.map(
Retrying.retryingNatureOfFutureT[T](_).retry(timeout, interval, pos)(dispatcher.unsafeToFuture(fun))
)
)
}
}
}