elastic / apm-queue

Abstraction layer over Kafka / GCP PubSub Lite to produce and consume records
Apache License 2.0
6 stars 15 forks source link

test: fix flaky TestConsumerDelivery #488

Closed kruskall closed 2 months ago

kruskall commented 3 months ago

Processing happens in a separate goroutine so even if we cancel the context as soon as we start processing the first batch of records a second fetch might have completed already. The other scenario is that the context is canceled before the second fetch starts creating a +- tc.maxPollRecords variance in errored records and potentially causing extra records in processed record counter. Update the test to ignore extra records processed after the context has been canceled and account for an extra tc.maxPollRecords records when asserting processed records. Make the test more deterministic and assert for equality instead of comparing >=.

This issue only happens if tc.initialRecords != tc.maxPollRecords.

Mostly affecting 30_produced_2_poll_AMOD.

Example:

Scenario 1:

Scenario 2:

Scenario 3:

To reproduce:

go test -run=TestConsumerDelivery ./kafka/ -count 100 -race -failfast

github-actions[bot] commented 3 months ago

:warning: Warning

System-tests will not be executed for this PR because it is from a forked repository. But it will still create a successful run-system-tests status check.