Skip to content

Commit 965eb35

Browse files
committed
drop zio-test, override executioncontext
1 parent f6eb87f commit 965eb35

File tree

3 files changed

+52
-48
lines changed

3 files changed

+52
-48
lines changed

build.sbt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,7 @@ lazy val zio1 = (projectMatrix in file("zio1"))
232232
lazy val zio = (projectMatrix in file("zio"))
233233
.settings(
234234
name := "zio",
235-
libraryDependencies ++= Seq("dev.zio" %%% "zio-streams" % zio2Version, "dev.zio" %%% "zio" % zio2Version) ++
236-
Seq(
237-
"dev.zio" %%% "zio-test" % zio2Version % Test,
238-
"dev.zio" %%% "zio-test-sbt" % zio2Version % Test
239-
),
240-
testFrameworks += TestFrameworks.ZIOTest
235+
libraryDependencies ++= Seq("dev.zio" %%% "zio-streams" % zio2Version, "dev.zio" %%% "zio" % zio2Version)
241236
)
242237
.jvmPlatform(
243238
scalaVersions = scala2 ++ scala3,

fs2/src/test/scala/sttp/capabilities/fs2/Fs2StreamsTest.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@ package sttp.capabilities.fs2
22

33
import cats.effect.IO
44
import cats.effect.unsafe
5+
import cats.effect.unsafe.implicits.global
56
import fs2._
67
import org.scalatest.flatspec.AsyncFlatSpec
78
import org.scalatest.matchers.should.Matchers
89
import sttp.capabilities.StreamMaxLengthExceededException
10+
import scala.concurrent.ExecutionContext
911

1012
class Fs2StreamsTest extends AsyncFlatSpec with Matchers {
1113

12-
implicit val runtime: unsafe.IORuntime = unsafe.IORuntime(
13-
executionContext,
14-
executionContext,
15-
unsafe.IORuntime.global.scheduler,
16-
unsafe.IORuntime.global.shutdown,
17-
unsafe.IORuntime.global.config
18-
)
14+
override implicit val executionContext: ExecutionContext = unsafe.IORuntime.global.compute
1915

2016
behavior of "Fs2Streams"
2117

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,57 @@
11
package sttp.capabilities.zio
22

3+
import org.scalatest.flatspec.AsyncFlatSpec
4+
import org.scalatest.matchers.should.Matchers
35
import sttp.capabilities.StreamMaxLengthExceededException
46
import zio._
57
import zio.stream.ZStream
6-
import zio.test._
7-
8-
object ZioStreamsTest extends ZIOSpecDefault {
9-
def spec: Spec[TestEnvironment, Any] = suite("ZioStreams")(
10-
test("should Pass all bytes if limit is not exceeded") {
11-
// given
12-
val inputByteCount = 8192
13-
val maxBytes = 8192L
14-
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte))
15-
16-
// when
17-
val stream = ZioStreams.limitBytes(inputStream, maxBytes)
18-
19-
// then
20-
for {
21-
count <- stream.runFold(0L)((acc, _) => acc + 1)
22-
} yield assertTrue(count == inputByteCount)
23-
},
24-
test("should Fail stream if limit is exceeded") {
25-
val inputByteCount = 8192
26-
val maxBytes = 8191L
27-
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte))
28-
29-
// when
30-
val stream = ZioStreams.limitBytes(inputStream, maxBytes)
31-
32-
// then
33-
for {
34-
limit <- stream.runLast.flip
35-
.flatMap {
8+
import scala.concurrent.ExecutionContext
9+
10+
class ZioStreamsTest extends AsyncFlatSpec with Matchers {
11+
override implicit val executionContext: ExecutionContext = Runtime.defaultExecutor.asExecutionContext
12+
13+
behavior of "ZioStreams"
14+
15+
implicit val r: Runtime[Any] = Runtime.default
16+
17+
it should "Pass all bytes if limit is not exceeded" in {
18+
// given
19+
val inputByteCount = 8192
20+
val maxBytes = 8192L
21+
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte))
22+
23+
// when
24+
val stream = ZioStreams.limitBytes(inputStream, maxBytes)
25+
26+
// then
27+
Unsafe.unsafe(implicit u =>
28+
r.unsafe.runToFuture(stream.runFold(0L)((acc, _) => acc + 1).map { count =>
29+
count shouldBe inputByteCount
30+
})
31+
)
32+
}
33+
34+
it should "Fail stream if limit is exceeded" in {
35+
// given
36+
val inputByteCount = 8192
37+
val maxBytes = 8191L
38+
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte))
39+
40+
// when
41+
val stream = ZioStreams.limitBytes(inputStream, maxBytes)
42+
43+
// then
44+
Unsafe.unsafe(implicit u =>
45+
r.unsafe.runToFuture(
46+
stream.runLast
47+
.flatMap(_ => ZIO.succeed(fail("Unexpected end of stream")))
48+
.catchSome {
3649
case StreamMaxLengthExceededException(limit) =>
37-
ZIO.succeed(limit)
50+
ZIO.succeed(limit shouldBe maxBytes)
3851
case other =>
39-
ZIO.fail(s"Unexpected failure cause: $other")
52+
ZIO.succeed(fail(s"Unexpected failure cause: $other"))
4053
}
41-
} yield assertTrue(limit == maxBytes)
42-
}
43-
)
54+
)
55+
)
56+
}
4457
}

0 commit comments

Comments
 (0)