Skip to content

fix(testing): TestKafkaBroker should mock a real tombstone too - #2939

Merged
Lancetnik merged 3 commits into
ag2ai:mainfrom
aradng:fix/confluent-testing-real-tombstone
Jul 15, 2026
Merged

fix(testing): TestKafkaBroker should mock a real tombstone too#2939
Lancetnik merged 3 commits into
ag2ai:mainfrom
aradng:fix/confluent-testing-real-tombstone

Conversation

@aradng

@aradng aradng commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

publish(None, topic, key=...) is supposed to simulate a real Kafka tombstone. Under TestKafkaBroker it never did. build_message ran None through the codec and got back b"", so message.value() was always bytes, never a true None.

This meant the tombstone path (message.value() is None) could never be exercised through the test broker at all, for confluent or kafka.

Fixed build_message in both faststream/confluent/testing.py and faststream/kafka/testing.py to skip the codec when message is None, same as the producer fix in #2932. Added a test for each driver confirming the mocked message now carries a real None value.

Follow up to #2932 and #2933.

@aradng
aradng requested a review from Lancetnik as a code owner July 14, 2026 16:11
@github-actions github-actions Bot added Confluent Issues related to `faststream.confluent` module AioKafka Issues related to `faststream.kafka` module labels Jul 14, 2026
publish(None, ..., key=...) always ran through the codec and became b, never a true None. Real consumers see message.value() is None on a Kafka tombstone, same as the producer fix in 2932, but the test broker could never simulate that.

Updated build_message in both confluent and kafka testing modules to skip the codec for message=None, mirroring 2932. Added tests for both drivers.

Follows 2932 and 2933.
@aradng
aradng force-pushed the fix/confluent-testing-real-tombstone branch from eaa5c85 to d202931 Compare July 14, 2026 16:15
Lancetnik and others added 2 commits July 15, 2026 12:20
Use the shared mock fixture and Context("message") idiom instead of an
asyncio.Queue, and assert synchronously after publish (the in-memory
TestBroker runs the handler inline), matching the other tests in these
files. Drops the now-unused typing.Any import.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Lancetnik
Lancetnik enabled auto-merge July 15, 2026 09:22
@Lancetnik
Lancetnik added this pull request to the merge queue Jul 15, 2026
Merged via the queue into ag2ai:main with commit d1e756f Jul 15, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AioKafka Issues related to `faststream.kafka` module Confluent Issues related to `faststream.confluent` module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants