Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ private[client4] object InterruptibleStreamPublisher {
*/
// zio-interop only stops requesting elements on cancel, so a stream waiting for its next element never ends
def apply[A](stream: ZStream[Any, Throwable, A]): UIO[Publisher[A]] =
ZIO.runtime[Any].map { runtime =>
// the captured runtime's flags are inherited by the stream's fibers; if interruption was disabled (e.g. `send` was
// called in an uninterruptible region), `interruptWhen` would wait forever for its promise-awaiting fiber to end
ZIO.interruptible(ZIO.runtime[Any]).map { runtime =>
new Publisher[A] {
override def subscribe(subscriber: Subscriber[_ >: A]): Unit = {
Objects.requireNonNull(subscriber)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package sttp.client4.impl.zio

import sttp.capabilities.zio.ZioStreams
import sttp.client4._
import sttp.client4.internal._
import sttp.client4.testing.ConvertToFuture
import sttp.client4.testing.HttpTest.endpoint
import sttp.client4.testing.streaming.StreamingTest
import sttp.model.sse.ServerSentEvent
import zio._
Expand Down Expand Up @@ -32,4 +34,18 @@ trait ZioStreamingTest extends StreamingTest[Task, ZioStreams] with ZioTestBase

override def failingBodyProducer(chunk: Array[Byte], error: Throwable): ZStream[Any, Throwable, Byte] =
ZStream.fromChunk(Chunk.fromArray(chunk)) ++ ZStream.fail(error)

"send a streamed request body when sending is uninterruptible" in {
convertToFuture.toFuture(
basicRequest
.post(uri"$endpoint/streaming/echo")
.streamBody(streams)(bodyProducer(List("hello".getBytes(Utf8))))
.response(asStringAlways)
// an uninterruptible effect can't be timed out, so the read timeout is the only way to end a hanging request
.readTimeout(scala.concurrent.duration.Duration(5, "s"))
.send(backend)
.uninterruptible
.map(_.body shouldBe "hello")
)
}
}
Loading