Skip to content

kafka: add more unit test (#5969) - #6529

Closed
ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-5969-to-release-8.5
Closed

ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-5969-to-release-8.5

Conversation

@ti-chi-bot

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #5969

What problem does this PR solve?

Issue Number: close #5886

Kafka Sink tests do not precisely cover construction and cleanup, DML delivery,
DDL dispatch, or checkpoint fan-out. Regressions in routing, partition
selection, error propagation, and resource cleanup can therefore go
undetected.

The Sink test baseline must depend only on TiCDC-owned interfaces and remain
independent of Sarama and franz-go adapter details.

What is changed and how it works?

  • Add focused Kafka Sink tests for construction, cleanup, DML, DDL, and
    checkpoint handling.
  • Verify routed topics, partitions, encoded messages, callback ownership,
    context cancellation, and unchanged error propagation.
  • Generate a mock for the TiCDC-owned TopicManager interface and add it to the
    mock generation flow.
  • Use real stateless encoders and TiCDC-owned Kafka interfaces without importing
    Sarama or franz-go types.

Test coverage

Coverage was measured on the PR merge-base e1537bf21 and PR head 9f0599cb0
with the same command:

go test --tags=intest -count=1 -covermode=atomic \
  -coverprofile=coverage.out ./downstreamadapter/sink/kafka
Scope Before After Increase
Kafka Sink package 57.7% 75.7% +18.0 percentage points
sink.go 66.9% (168/251) 88.4% (222/251) +21.5 percentage points

The additional sink.go coverage exercises 54 previously uncovered statements
across Sink construction and cleanup, DML routing and delivery, DDL dispatch,
checkpoint fan-out, cancellation, and error propagation.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test
  • No code

Questions

Will it cause performance regression or break compatibility?

No. This PR only adds and strengthens unit tests.

Do you need to update user documentation, design documentation or monitoring documentation?

No.

Release note

None

Summary by CodeRabbit

  • Tests

    • Expanded Kafka sink coverage for construction, cleanup, DML and DDL processing, checkpoint handling, cancellation, partition routing, and error propagation.
    • Added coverage for producer runtime failures, construction errors, closure behavior, unsupported events, and missing encodings.
    • Improved validation of event handling and resource cleanup across common success and failure scenarios.
  • Chores

    • Added reusable topic-management mock support to improve automated test reliability.

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/cherry-pick-not-approved labels Oct 13, 2026
@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 13, 2026
@ti-chi-bot

ti-chi-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

This cherry pick PR is for a release branch and has not yet been approved by triage owners.
Adding the do-not-merge/cherry-pick-not-approved label.

To merge this cherry pick:

  1. It must be LGTMed and approved by the reviewers firstly.
  2. For pull requests to TiDB-x branches, it must have no failed tests.
  3. AFTER it has lgtm and approved labels, please wait for the cherry-pick merging approval from triage owners.
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot added lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. labels Oct 13, 2026
@ti-chi-bot ti-chi-bot mentioned this pull request Oct 13, 2026
1 of 4 tasks
@ti-chi-bot

ti-chi-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign 3aceshowhand for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot

Copy link
Copy Markdown
Member Author

@3AceShowHand This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot

ti-chi-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6176c412-deea-4439-b504-694e7a1a6733
📥 Commits

Reviewing files that changed from the base of the PR and between ca7d339 and cd48229.

📒 Files selected for processing (9)
  • downstreamadapter/sink/kafka/sink_test.go
  • downstreamadapter/sink/topicmanager/topic_manager_mock.go
  • pkg/sink/kafka/oauth2_token_provider_test.go
  • pkg/sink/kafka/sarama_admin_mock.go
  • pkg/sink/kafka/sarama_admin_test.go
  • pkg/sink/kafka/sarama_oauth2_token_provider.go
  • pkg/sink/kafka/sarama_oauth2_token_provider_test.go
  • pkg/sink/kafka/scram_client_test.go
  • scripts/generate-mock.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@3AceShowHand

Copy link
Copy Markdown
Collaborator

Closed by #6405. Consolidating these prerequisite backports into one PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/cherry-pick-not-approved do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants