Skip to content
Open
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
30 changes: 30 additions & 0 deletions core/shared/src/test/scala/fs2/concurrent/TopicSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,34 @@ class TopicSuite extends Fs2Suite {

TestControl.executeEmbed(program) // will fail if program is deadlocked
}

// https://github.com/typelevel/fs2/issues/3646
test(
"all subscribers should receive messages in the same order, even on concurrent publishers".flaky
) {
val nSubscribers = 100
val check =
Topic[IO, String]
.flatMap { t =>
t.subscribeAwaitUnbounded.replicateA(nSubscribers).use { subs =>
IO.both(t.publish1("foo"), t.publish1("bar")) // racing two publishers
.flatMap {
case (Right(()), Right(())) =>
subs
.traverse(s => s.take(2).compile.toList)
.map {
case xs :: xss =>
// all subscriptions must have received the events in the same order
xss.foreach(ys => assertEquals(ys, xs))
case Nil =>
fail(s"Impossible, there are $nSubscribers subscribers")
}
case _ =>
fail("There's no reason for either publish1 to reject the publication")
}
}
}

check.replicateA(10000)
}
}