Skip to content

Stop the Kafka input-binding example test from losing messages - #1236

Merged
sicoyle merged 1 commit into
dapr:mainfrom
CasperGN:fix/invoke-binding-example-flake
Sep 28, 2026
Merged

sicoyle merged 1 commit into
dapr:mainfrom
CasperGN:fix/invoke-binding-example-flake

Conversation

@CasperGN

Copy link
Copy Markdown
Contributor

Description

tests/examples/test_invoke_binding.py failed on Python 3.14 in this run. The receiver printed only message 3, not 1 or 2.

Cause. The log shows daprd ready at 19:58:17.88. The test then published messages 1, 2 and 3 one second apart and stopped the receiver about a second after the last one. The Kafka binding's consumer group was still joining at that point: the broker waits 3 s by default (group.initial.rebalance.delay.ms) before assigning partitions to a new group. The binding uses the default initialOffset of newest, so a new group starts at the end of the topic and skips anything published before it joins. Messages 1 and 2 went out before the join, so they were never delivered. The old mechanical-markdown flow in the README got around this with sleep: 5 after starting the receiver. The pytest version lost that gap.

There was also a second race: the test stopped the receiver on a fixed schedule rather than once the messages had arrived. A slower join could lose all three.

Fix.

  • examples/invoke-binding/components/kafka-binding.yaml: set initialOffset: oldest. A new consumer group then starts at the beginning of the topic, so messages published before it joins are still delivered. The topic is created fresh by docker compose up for each test run. For someone running the example by hand against containers they keep, this only affects the group's first join, because later runs resume from the committed offset.
  • DaprRunner.wait_for_output() in tests/examples/conftest.py polls the background service's log every second until it contains every expected line. It gives up if the process exits or the timeout passes, the same way _wait_until_ready does.
  • test_invoke_binding no longer sleeps between publishes. It waits up to 60 s for all three messages before stopping the receiver, and the existing assertions still give the failure message.

No retries were added. The test passes for the same reason the example now works.

Issue reference

No issue. This is a CI flake seen on #1235.

Checklist

  • Code compiles correctly
  • Created/updated tests: unit tests for wait_for_output in tests/examples/test_dapr_runner.py (13 passed locally)
  • Extended the documentation: not needed, since only the example component and test tooling changed

I couldn't run the Kafka example end to end locally (no Docker daemon), so the example validation on this PR is the real check.

🤖 Generated with Claude Code

The consumer group used the default initialOffset of newest and was still
joining when the sidecar reported ready, so messages published right away
were skipped. The test also stopped the receiver after a fixed delay.

Start the example's consumer group at the oldest offset and wait for all
three messages before stopping the receiver.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Casper Nielsen <casper@diagrid.io>
@CasperGN
CasperGN requested review from a team as code owners September 25, 2026 09:35
@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.89%. Comparing base (fb229bc) to head (09cd4cd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1236   +/-   ##
=======================================
  Coverage   83.89%   83.89%           
=======================================
  Files         123      123           
  Lines       10265    10265           
=======================================
  Hits         8612     8612           
  Misses       1653     1653           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sicoyle
sicoyle added this pull request to the merge queue Sep 28, 2026
Merged via the queue into dapr:main with commit e86ac34 Sep 28, 2026
31 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants