Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Kafka flaky test #105

Merged
merged 3 commits into from
Apr 8, 2024
Merged
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 @@ -70,9 +70,10 @@ class KafkaSourceProviderImplSpec extends ScalaTestWithActorTestKit with LogCapt
val metadataClient = new TestMetadataClientAdapter(partitions)
val tp0 = new TopicPartition(topic, 0)
val tp1 = new TopicPartition(topic, 1)
val totalPerPartition = 10

val consumerRecords =
for (n <- 0 to 10; tp <- List(tp0, tp1))
for (n <- 0 to totalPerPartition; tp <- List(tp0, tp1))
yield new ConsumerRecord(tp.topic(), tp.partition(), n, n.toString, n.toString)

val consumerSource = Source(consumerRecords)
Expand Down Expand Up @@ -109,6 +110,12 @@ class KafkaSourceProviderImplSpec extends ScalaTestWithActorTestKit with LogCapt
records.count(_.partition() == tp1.partition()) shouldBe 5
}

// because source push to handle(probe) before sinkProbe request pull, it made probe cache random one record
val eagerMessage = probe.receiveMessage()
Copy link
Member Author

Choose a reason for hiding this comment

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

It's kind of like akka/akka-projection#462, i won't say this is best solution.

Copy link
Member Author

Choose a reason for hiding this comment

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

@He-Pin Is there any way to make the source and sink reach a consensus on the number of elements?

records = records ++ Set(eagerMessage)
val tp0Received = records.count(_.partition() == tp0.partition())
val tp0Expect = totalPerPartition - tp0Received

// assign only tp0 to this projection
provider.partitionHandler.onAssign(Set(tp0), null)
provider.partitionHandler.onRevoke(Set(tp1), null)
Expand All @@ -120,10 +127,10 @@ class KafkaSourceProviderImplSpec extends ScalaTestWithActorTestKit with LogCapt
// only records from partition 0 should remain, because the rest were filtered
sinkProbe.request(5)
sinkProbe.expectNextN(5)
records = probe.receiveMessages(5)
records = probe.receiveMessages(tp0Expect)

withClue("checking: after rebalance processed records should only have records from partition 0") {
records.count(_.partition() == tp0.partition()) shouldBe 5
records.count(_.partition() == tp0.partition()) shouldBe tp0Expect
records.count(_.partition() == tp1.partition()) shouldBe 0
}
}
Expand Down
Loading