Skip to content

ci: add live-broker integration test harness (Kafka in CI)#706

Merged
wbarnha merged 6 commits into
masterfrom
claude/ci-kafka-integration
Jul 19, 2026
Merged

ci: add live-broker integration test harness (Kafka in CI)#706
wbarnha merged 6 commits into
masterfrom
claude/ci-kafka-integration

Conversation

@wbarnha

@wbarnha wbarnha commented Jul 19, 2026

Copy link
Copy Markdown
Member

What

faust had no way to exercise a real broker: tests/integration/ only shelled out to the CLI, and CI ran no Kafka at all. This adds the foundation so broker-dependent bugs — offset-commit gaps (#606), exactly-once duplicates (#517/#323), recovery races — can eventually get real regression tests.

How

tests/integration/broker/ (new):

  • conftest.py — a broker_url fixture that skips when no Kafka is reachable (quick TCP probe), so the suite stays green on developer machines and the normal broker-less jobs, and runs for real only in the dedicated job. Point it anywhere with FAUST_TEST_BROKER (default kafka://localhost:9092). Plus kafka_bootstrap, unique_topic, unique_group fixtures.
  • test_smoke.py — one round-trip per transport-client library faust ships a driver for:
    • test_aiokafka_roundtrip — produce→consume through aiokafka.
    • test_confluent_roundtrip — produce→consume through confluent-kafka (optional dep; importorskips when absent).

CI — a new advisory Integration (Kafka <version>) job that:

  • runs an apache/kafka KRaft container (single node, no Zookeeper),
  • installs the confluent-kafka extra,
  • waits for the broker, then runs pytest tests/integration/broker.

It is continue-on-error: true and not in the required check gate, so broker flakiness can't block the required checks or the merge queue.

Scope

This is deliberately the foundation: the raw round-trip anchors prove Kafka-in-CI works end to end for both client libraries. A full in-process faust App end-to-end test (start an app, drive an agent, shut it down) is left to a follow-up — embedding the app lifecycle in pytest hangs on teardown and needs its own hardening (a hard timeout guard + clean-shutdown fix), which shouldn't block landing the harness.

Locally and in the broker-less jobs the two tests skip (verified).

🤖 Generated with Claude Code

faust had no way to exercise a real broker: tests/integration only shells
out to the CLI, and CI ran no Kafka at all, so broker-dependent bugs
(offset-commit gaps, exactly-once duplicates, recovery races) couldn't be
verified anywhere.

Add the foundation:
- tests/integration/broker/: a broker_url fixture that skips when no Kafka
  is reachable (so the suite stays green on dev machines and the normal
  broker-less jobs), plus fixtures for bootstrap servers and unique
  topic/group names.
- test_smoke.py: an aiokafka produce->consume round-trip (robust anchor
  proving the CI broker is up) and a full faust App round-trip (send ->
  agent consumes) exercising the real stack end to end.
- A new advisory 'Integration (Kafka ...)' CI job that starts an
  apache/kafka KRaft service, waits for it, and runs the broker tests.
  It is continue-on-error and intentionally NOT in the required 'check'
  gate, so broker flakiness can't block the merge queue while we stabilise
  it.

This unblocks writing regression tests for the broker-only issues.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.15%. Comparing base (3073eb9) to head (443ccde).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #706   +/-   ##
=======================================
  Coverage   94.14%   94.15%           
=======================================
  Files         104      104           
  Lines       11136    11136           
  Branches     1201     1201           
=======================================
+ Hits        10484    10485    +1     
+ Misses        551      550    -1     
  Partials      101      101           

☔ 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.

wbarnha and others added 5 commits July 19, 2026 14:47
…t broker

- conftest.py: drop the ';' from the skip message.  On Python 3.12 (which
  the lint job uses) PEP 701 f-string tokenisation exposes the semicolon to
  the older pycodestyle, which flags it as E702; local flake8 on 3.11 did
  not.
- test_smoke.py: relax ResourceWarning to a non-error for these tests.  The
  suite escalates ResourceWarning (pyproject), but aiokafka/faust leave
  sockets/tasks that can emit it during live-broker teardown, which masked
  the real result.
- workflow: set KAFKA_LOG4J_ROOT_LOGLEVEL=WARN so the job log shows pytest
  output instead of thousands of lines of broker logging.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Two problems on the integration job:

1) Observability: as a GH services container the broker log floods the job
   log and hides the pytest output.  Run Kafka via 'docker run -d' instead
   so the broker log stays in the container (dumped via 'docker logs' only
   on failure) and the job log shows the test results.

2) The faust App round-trip timed out (assignment received, then LeaveGroup
   exactly RECV_TIMEOUT later): an embedded app.start() leaves flow control
   suspended, so the agent's stream never pulls.  Resume it explicitly after
   assignment, matching what faust's own worker / test helpers do.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
- Add confluent-kafka coverage: a raw confluent round-trip anchor and
  parametrise the faust App round-trip over both transports (kafka:// =
  aiokafka, confluent:// = confluent-kafka).  confluent-kafka is optional,
  so those tests importorskip when it's absent.  Install it in the CI job
  via requirements/extras/ckafka.txt.
- Stop dumping the full broker log on failure (it drowned the pytest output
  in the job log); tail it to 40 lines and add -ra --tb=short so the actual
  test result is visible.
- Shorten the round-trip timeouts so a hang fails fast.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Keep the foundation focused and reliably green: raw aiokafka and
confluent-kafka produce->consume round-trips that prove the CI Kafka broker
is up and each client library works.

Drop the in-process faust App end-to-end test for now -- embedding the app
lifecycle (start, drive an agent, shut down) in pytest hangs on teardown and
needs its own hardening, which shouldn't block landing the harness.  It will
return as a follow-up with a proper timeout guard.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Both raw round-trips pass, but the repo's autouse threads_not_lingering
guard failed them at teardown: talking to the broker makes asyncio resolve
localhost via getaddrinfo in its default ThreadPoolExecutor, and that
resolver thread (asyncio_0) outlives the test.  That is expected for
live-network tests and not a leak we can act on, so shadow the guard with a
no-op in the broker package's conftest.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
@wbarnha
wbarnha merged commit c95a518 into master Jul 19, 2026
23 checks passed
wbarnha added a commit that referenced this pull request Jul 19, 2026
Add tests/integration/broker/test_offset_commit.py, which drives faust's real
aiokafka consumer against a live Kafka broker (the #706 CI harness):

- test_does_not_commit_past_inflight_message reproduces #606 -- offset 2 is
  in-flight (tracked, unacked) while 3 and 4 are acked out of order -- and
  asserts the broker's committed offset never advances past 2.  Verified to
  fail without the fix (the buggy _new_offset returns 5 and commits it).
- test_commits_contiguous_acks is a positive control proving the real commit
  path does persist offset 5 to the broker when nothing is in-flight.

Both skip when no broker is reachable and run in the dedicated CI integration
job.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
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.

1 participant