Thanks to visit codestin.com
Credit goes to github.com

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
13 changes: 13 additions & 0 deletions streams-tests/shared/src/test/scala/zio/stream/ZStreamSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ object ZStreamSpec extends ZIOBaseSpec {
equalTo(Chunk(Right(List(2, 1, 1, 1, 1)), Right(List(2))))
)
},
testM("fails fast") {
for {
queue <- Queue.unbounded[Int]
_ <- ZStream
.range(1, 10)
.tap(i => ZIO.fail("BOOM!").when(i == 6) *> queue.offer(i))
.aggregateAsyncWithin(ZTransducer.foldUntil((), 5)((_, _) => ()), Schedule.forever)
.runDrain
.catchAll(_ => ZIO.succeedNow(()))
value <- queue.takeAll
_ <- queue.shutdown
} yield assert(value)(equalTo(List(1, 2, 3, 4, 5)))
} @@ zioTag(errors),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do a few runs with nonFlaky(50000) locally to verify the test is not flaky? Some parts of it (usage of TestClock with no advancing, use of takeAll which is not deterministic) make me a bit wary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just ran it locally with nonFlaky(50000) ten times. No failures.

testM("error propagation 1") {
val e = new RuntimeException("Boom")
assertM(
Expand Down
12 changes: 12 additions & 0 deletions streams/shared/src/main/scala/zio/stream/Take.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ case class Take[+E, +A](exit: Exit[Option[E], Chunk[A]]) extends AnyVal {
def isDone: Boolean =
exit.fold(Cause.sequenceCauseOption(_).isEmpty, _ => false)

/**
* Checks if this `take` is a failure.
*/
def isFailure: Boolean =
exit.fold(Cause.sequenceCauseOption(_).nonEmpty, _ => false)

/**
* Checks if this `take` is a success.
*/
def isSuccess: Boolean =
exit.fold(_ => false, _ => true)

/**
* Transforms `Take[E, A]` to `Take[E, B]` by applying function `f`.
*/
Expand Down
2 changes: 1 addition & 1 deletion streams/shared/src/main/scala/zio/stream/ZStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ abstract class ZStream[-R, +E, +O](val process: ZManaged[R, Nothing, ZIO[R, Opti
.makeManaged[Option[Fiber[Nothing, Take[E1, O]]]](None)
sdriver <- schedule.driver.toManaged_
lastChunk <- ZRef.makeManaged[Chunk[P]](Chunk.empty)
producer = Take.fromPull(pull).repeatWhileM(take => handoff.offer(take).as(!take.isDone))
producer = Take.fromPull(pull).repeatWhileM(take => handoff.offer(take).as(take.isSuccess))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix 👍

consumer = {
// Advances the state of the schedule, which may or may not terminate
val updateSchedule: URIO[R1 with Clock, Option[Q]] =
Expand Down