diff --git a/core/shared/src/test/scala/fs2/StreamMergeSuite.scala b/core/shared/src/test/scala/fs2/StreamMergeSuite.scala index 282115c05a..6e3b24af37 100644 --- a/core/shared/src/test/scala/fs2/StreamMergeSuite.scala +++ b/core/shared/src/test/scala/fs2/StreamMergeSuite.scala @@ -243,14 +243,29 @@ class StreamMergeSuite extends Fs2Suite { } } - test("mergePreferred prefers") { - forAllF { (leftStream: Stream[Pure, Int], rightStream: Stream[Pure, Int]) => - val leftTagged = leftStream.covary[IO] - val rightTagged = rightStream.covary[IO].delayBy(10.milli) - leftTagged - .mergePreferred(rightTagged) - .assertEmitsSameAs(leftStream ++ rightStream) - } + test("mergePreferred prefers this over that") { + + val units = Stream.unit.covary[IO].repeat + val left = units.map(Left(_)) + val right = units.map(Right(_)) + + val stream = left.mergePreferred(right) + + stream + .take(10000) + .fold((0L, 0L)) { + case ((left, right), Left(_)) => (left + 1, right) + case ((left, right), Right(_)) => (left, right + 1) + } + .compile + .lastOrError + .map { case (left, right) => + val relLeft = left.toDouble / (left + right).toDouble + // Tolerate up to 2% elements of the non preferred stream. + // Increase the value, if the test (ocassionally) reports false positives. + val delta = 0.02d + assertEqualsDouble(relLeft, 1.0d, delta) + } } test("mergePreferred fully consumes this") {