From ccfbb2dfa792dff4cadb081d97a5df9b5db5af41 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Wed, 21 Sep 2022 13:54:22 +0100 Subject: [PATCH 1/8] Replace serial scalatest ExecutionContext with global Fix for #145 --- .../scala/cats/effect/testing/scalatest/AsyncIOSpec.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 8c385ed..3c3bc6f 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 @@ -19,20 +19,21 @@ package cats.effect.testing.scalatest import cats.effect.IO import cats.effect.testing.RuntimePlatform import cats.effect.unsafe.IORuntime - import org.scalactic.source.Position import org.scalatest.AsyncTestSuite import org.scalatest.enablers.Retrying import org.scalatest.time.Span +import scala.concurrent.ExecutionContext.global + trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport with RuntimePlatform { asyncTestSuite: AsyncTestSuite => - implicit lazy val ioRuntime: IORuntime = createIORuntime(executionContext) + implicit lazy val ioRuntime: IORuntime = createIORuntime(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](executionContext).retry(timeout, interval, pos)(fun.unsafeToFuture())), + IO(Retrying.retryingNatureOfFutureT[T](global).retry(timeout, interval, pos)(fun.unsafeToFuture())), ) } } From 29f898c9a7129f95601954b2e922ef6c145e06c4 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Fri, 23 Sep 2022 10:05:21 +0100 Subject: [PATCH 2/8] Use IORuntime.global rather than runtime based on context of scalatest --- .../scala/cats/effect/testing/scalatest/AsyncIOSpec.scala | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 3c3bc6f..5831d5a 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 @@ -24,16 +24,14 @@ import org.scalatest.AsyncTestSuite import org.scalatest.enablers.Retrying import org.scalatest.time.Span -import scala.concurrent.ExecutionContext.global - trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport with RuntimePlatform { asyncTestSuite: AsyncTestSuite => - implicit lazy val ioRuntime: IORuntime = createIORuntime(global) + 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](global).retry(timeout, interval, pos)(fun.unsafeToFuture())), + IO(Retrying.retryingNatureOfFutureT[T](IORuntime.global.compute).retry(timeout, interval, pos)(fun.unsafeToFuture())), ) } } From 697024c587f208979091f5ba518d8b33e0bd8cb2 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Fri, 23 Sep 2022 22:54:43 +0100 Subject: [PATCH 3/8] Remove unused RuntimePlatform from AsyncIOSpec --- .../main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 5831d5a..838ddaf 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 @@ -17,14 +17,13 @@ package cats.effect.testing.scalatest import cats.effect.IO -import cats.effect.testing.RuntimePlatform import cats.effect.unsafe.IORuntime 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 with RuntimePlatform { asyncTestSuite: AsyncTestSuite => +trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport { asyncTestSuite: AsyncTestSuite => implicit lazy val ioRuntime: IORuntime = IORuntime.global From 86f6504f6468839eb269f854033b9703c29f8b9d Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Fri, 23 Sep 2022 23:00:51 +0100 Subject: [PATCH 4/8] Revert "Remove unused RuntimePlatform from AsyncIOSpec" This reverts commit 697024c587f208979091f5ba518d8b33e0bd8cb2. --- .../main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 838ddaf..5831d5a 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 @@ -17,13 +17,14 @@ package cats.effect.testing.scalatest import cats.effect.IO +import cats.effect.testing.RuntimePlatform import cats.effect.unsafe.IORuntime 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 => +trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport with RuntimePlatform { asyncTestSuite: AsyncTestSuite => implicit lazy val ioRuntime: IORuntime = IORuntime.global From b74e9110a82769c3266d91db139b7d261c9afe40 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Fri, 23 Sep 2022 23:43:41 +0100 Subject: [PATCH 5/8] Add ScalatestRuntimePlatform for js/jvm --- .../scalatest/ScalatestRuntimePlatform.scala | 27 +++++++++++++++++++ .../scalatest/ScalatestRuntimePlatform.scala | 26 ++++++++++++++++++ .../testing/scalatest/AsyncIOSpec.scala | 5 +--- 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 scalatest/js/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala create mode 100644 scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala diff --git a/scalatest/js/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala b/scalatest/js/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala new file mode 100644 index 0000000..efc1ef6 --- /dev/null +++ b/scalatest/js/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala @@ -0,0 +1,27 @@ +/* + * Copyright 2020 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cats.effect.testing.scalatest + +import cats.effect.testing.RuntimePlatform +import cats.effect.unsafe.IORuntime +import org.scalatest.AsyncTestSuite + +private[testing] trait ScalatestRuntimePlatform extends RuntimePlatform { asyncTestSuite: AsyncTestSuite => + + implicit lazy val ioRuntime: IORuntime = createIORuntime(executionContext) + +} diff --git a/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala b/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala new file mode 100644 index 0000000..216ba6f --- /dev/null +++ b/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala @@ -0,0 +1,26 @@ +/* + * Copyright 2020 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cats.effect.testing.scalatest + +import cats.effect.testing.RuntimePlatform +import cats.effect.unsafe.IORuntime +import org.scalatest.AsyncTestSuite + +private[testing] trait ScalatestRuntimePlatform extends RuntimePlatform { asyncTestSuite: AsyncTestSuite => + + implicit lazy val ioRuntime: IORuntime = IORuntime.global + +} 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 5831d5a..d2fceff 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 @@ -17,16 +17,13 @@ package cats.effect.testing.scalatest import cats.effect.IO -import cats.effect.testing.RuntimePlatform import cats.effect.unsafe.IORuntime 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 with RuntimePlatform { asyncTestSuite: AsyncTestSuite => - - implicit lazy val ioRuntime: IORuntime = IORuntime.global +trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport with ScalatestRuntimePlatform { asyncTestSuite: AsyncTestSuite => 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] = From 974882001f0610b104f52ae997159df59cdb8211 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Fri, 23 Sep 2022 23:58:10 +0100 Subject: [PATCH 6/8] Create DeadlockTest.scala --- .../testing/scalatest/DeadlockTest.scala | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scalatest/jvm/src/test/scala/cats/effect/testing/scalatest/DeadlockTest.scala diff --git a/scalatest/jvm/src/test/scala/cats/effect/testing/scalatest/DeadlockTest.scala b/scalatest/jvm/src/test/scala/cats/effect/testing/scalatest/DeadlockTest.scala new file mode 100644 index 0000000..a8a9815 --- /dev/null +++ b/scalatest/jvm/src/test/scala/cats/effect/testing/scalatest/DeadlockTest.scala @@ -0,0 +1,29 @@ +/* + * Copyright 2020 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cats.effect.testing.scalatest + +import cats.effect.IO +import org.scalatest.freespec.AsyncFreeSpec + +class DeadlockTest extends AsyncFreeSpec with AsyncIOSpec { + + "should not deadlock" in { + IO.blocking {}.unsafeRunSync() + succeed + } + +} \ No newline at end of file From a4b9801cbad9bb7b90a9a37c723648366287b4d6 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Sat, 24 Sep 2022 00:04:13 +0100 Subject: [PATCH 7/8] Fix header --- .../cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala b/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala index 216ba6f..5839872 100644 --- a/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala +++ b/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package cats.effect.testing.scalatest import cats.effect.testing.RuntimePlatform From 05b796c91a6c7491441510f49196bae49962fc9d Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Sat, 24 Sep 2022 00:45:52 +0100 Subject: [PATCH 8/8] Fix binary compatibility --- ...untimePlatform.scala => AsyncIOSpec.scala} | 12 ++++++++- .../testing/scalatest/AsyncIOSpec.scala | 5 +++- .../scalatest/ScalatestRuntimePlatform.scala | 27 ------------------- 3 files changed, 15 insertions(+), 29 deletions(-) rename scalatest/js/src/main/scala/cats/effect/testing/scalatest/{ScalatestRuntimePlatform.scala => AsyncIOSpec.scala} (59%) rename scalatest/{shared => jvm}/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala (88%) delete mode 100644 scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala diff --git a/scalatest/js/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala b/scalatest/js/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala similarity index 59% rename from scalatest/js/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala rename to scalatest/js/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala index efc1ef6..8779021 100644 --- a/scalatest/js/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala +++ b/scalatest/js/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala @@ -16,12 +16,22 @@ package cats.effect.testing.scalatest +import cats.effect.IO import cats.effect.testing.RuntimePlatform import cats.effect.unsafe.IORuntime +import org.scalactic.source.Position import org.scalatest.AsyncTestSuite +import org.scalatest.enablers.Retrying +import org.scalatest.time.Span -private[testing] trait ScalatestRuntimePlatform extends RuntimePlatform { asyncTestSuite: AsyncTestSuite => +trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport with RuntimePlatform { asyncTestSuite: AsyncTestSuite => 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())), + ) + } } diff --git a/scalatest/shared/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala b/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala similarity index 88% rename from scalatest/shared/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala rename to scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala index d2fceff..5831d5a 100644 --- a/scalatest/shared/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala +++ b/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/AsyncIOSpec.scala @@ -17,13 +17,16 @@ package cats.effect.testing.scalatest import cats.effect.IO +import cats.effect.testing.RuntimePlatform import cats.effect.unsafe.IORuntime 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 with ScalatestRuntimePlatform { asyncTestSuite: AsyncTestSuite => +trait AsyncIOSpec extends AssertingSyntax with EffectTestSupport with RuntimePlatform { asyncTestSuite: AsyncTestSuite => + + 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] = diff --git a/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala b/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala deleted file mode 100644 index 5839872..0000000 --- a/scalatest/jvm/src/main/scala/cats/effect/testing/scalatest/ScalatestRuntimePlatform.scala +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020 Typelevel - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cats.effect.testing.scalatest - -import cats.effect.testing.RuntimePlatform -import cats.effect.unsafe.IORuntime -import org.scalatest.AsyncTestSuite - -private[testing] trait ScalatestRuntimePlatform extends RuntimePlatform { asyncTestSuite: AsyncTestSuite => - - implicit lazy val ioRuntime: IORuntime = IORuntime.global - -}