From e65f88489ebecde9670053935cbba02234c526c0 Mon Sep 17 00:00:00 2001 From: Stephen Kennedy Date: Fri, 9 Jul 2021 10:48:01 +0100 Subject: [PATCH] Add support for scalatest eventually by implementing Retrying typeclass --- .../cats/effect/testing/scalatest/AsyncIOSpec.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scalatest/shared/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala b/scalatest/shared/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala index 6c8e9486..509a3e14 100644 --- a/scalatest/shared/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala +++ b/scalatest/shared/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala @@ -16,8 +16,12 @@ package cats.effect.testing.scalatest +import cats.effect.IO import cats.effect.unsafe.{IORuntime, IORuntimeConfig} +import org.scalactic.source.Position import org.scalatest.AsyncTestSuite +import org.scalatest.enablers.Retrying +import org.scalatest.time.Span trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport { asyncTestSuite: AsyncTestSuite => @@ -26,4 +30,11 @@ trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport { asyncTestSuit IORuntime(executionContext, executionContext, scheduler, sd, IORuntimeConfig()) } + + 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](executionContext).retry(timeout, interval, pos)(fun.unsafeToFuture())), + ) + } }