Skip to content

Commit

Permalink
partially fixes #1389 Replace sleep in tests with Promises
Browse files Browse the repository at this point in the history
  • Loading branch information
vermas7988 committed Feb 12, 2025
1 parent 833a46d commit 425e207
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ object SubscriptionsSpec extends ZIOSpecDefaultSlf4j with KafkaRandom {
finalizersRef <- Ref.make(Chunk.empty[String])

consumer <- KafkaTestUtils.makeConsumer(client, Some(group))

consumer0IsRunning <- Promise.make[Nothing, Unit]
c1Fib <- consumer
.plainStream(Subscription.topics(topic1), Serde.string, Serde.string)
// Here we delay each message to be sure that `consumer1` will fail while `consumer0` is still running
.mapZIO { r =>
consumer0IsRunning.succeed(()) *> // Notify that `consumer0` is running
firstMessagesRef.updateSome { case ("", v) => ("First consumer0 message", v) } *>
ZIO
.logDebug(s"Consumed ${counter.getAndIncrement()} records")
Expand All @@ -146,7 +147,7 @@ object SubscriptionsSpec extends ZIOSpecDefaultSlf4j with KafkaRandom {
.zipLeft(finalizersRef.update(_ :+ "consumer0 finalized"))
.fork

_ <- ZIO.sleep(100.millis) // Wait to be sure that `consumer0` is running
_ <- consumer0IsRunning.await // Wait to be sure that `consumer0` is running

c2Fib <- consumer
.plainStream(
Expand Down

0 comments on commit 425e207

Please sign in to comment.