test: add a integration test for foreign-key-check#1385
test: add a integration test for foreign-key-check#1385ti-chi-bot[bot] merged 5 commits intopingcap:masterfrom
Conversation
There was a problem hiding this comment.
Hello @hongyunyan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello! Gemini or gemini-code-assist here, providing a summary of this pull request.
This pull request introduces a new integration test focused on verifying TiCDC's behavior when replicating data that violates foreign key constraints. The test simulates a scenario where tables with a foreign key relationship are created, foreign key checks are disabled on the upstream database, and then data that violates the foreign key constraint is inserted. The changefeed replicates this data downstream, and the test uses the sync-diff tool to confirm that the final data state downstream is consistent with the upstream, ensuring CDC can handle such scenarios correctly.
Highlights
- New Integration Test: Adds a dedicated integration test suite under
tests/integration_tests/foreign_key_checkto specifically test foreign key replication scenarios. - Foreign Key Violation Scenario: The test creates tables with a foreign key constraint (
departmentsandemployees), disables foreign key checks on the upstream TiDB instance, and inserts data into theemployeestable with adept_idthat does not exist in thedepartmentstable, thus violating the FK. - Data Consistency Verification: Utilizes the
sync-difftool with a specific configuration (diff_config.toml) to compare the data between the upstream and downstream databases after replication, ensuring consistency despite the FK violation upstream. - CI Integration: Includes the newly added
foreign_key_checktest in the list of light integration tests (run_light_it_in_ci.sh) to be executed automatically in the CI pipeline.
Changelog
Click here to see the changelog
- tests/integration_tests/foreign_key_check/conf/diff_config.toml
- New file added.
- Contains configuration for the
sync-difftool, specifying source and target instances, output directory, and tables to check (test.*).
- tests/integration_tests/foreign_key_check/data/pre.sql
- New file added.
- SQL script to set up the test schema and data.
- Creates
departmentsandemployeestables with a foreign key constraint onemployees.dept_idreferencingdepartments.dept_id. - Inserts data, including a row in
employeeswith adept_id(999) that violates the foreign key constraint.
- tests/integration_tests/foreign_key_check/run.sh
- New file added.
- Main test script to orchestrate the integration test.
- Sets up a TiDB cluster.
- Disables global
foreign_key_checkson the upstream database. - Starts the CDC server and creates a changefeed.
- Executes the
pre.sqlscript on the upstream. - Runs
check_sync_diffusing the provided config to verify data consistency. - Includes comments explaining the test's purpose: verifying synchronization of FK-violating statements when upstream FK checks are disabled.
- tests/integration_tests/run_light_it_in_ci.sh
- Modified to add the
foreign_key_checktest to themysql_groupsarray (specifically group G15) for inclusion in light integration tests run in CI.
- Modified to add the
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Test added, checks FK,
Data flows the CDC way,
Consistency wins the day.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces a new integration test for foreign-key-check functionality. The test aims to verify that TiCDC can successfully replicate data that violates foreign key constraints when upstream has FK checks disabled, to a downstream MySQL sink that (presumably) has FK detection enabled. The setup involves disabling FK checks on the upstream, inserting data that violates FKs, and then using sync_diff_inspector to ensure the data is replicated correctly.
The overall structure of the test, including the shell script, SQL setup, and diff configuration, appears sound for its purpose. The addition of the test to the CI run is also appropriate.
I have one suggestion for improving the maintainability of the test script.
Summary of Findings
- Unused variables in test script: The
run.shscript definesCDC_COUNTandDB_COUNTwhich are not subsequently used. This was commented on withmediumseverity. - Non-English comment in SQL script: The
pre.sqlfile contains a comment in Chinese (-- 外键约束). While functional, using English for comments is generally preferred in projects with international contributors for better universal understanding. This was not commented on directly due to itslowseverity. - Missing newline at end of SQL file: The
pre.sqlfile is missing a newline character at the end. This is a minor stylistic issue. This was not commented on directly due to itslowseverity. - Hardcoded temporary path in config: The
diff_config.tomluses a hardcoded path in/tmpforoutput-dir. This is common and generally acceptable for test configurations. This was not commented on directly due to itslowseverity in a test context. - Naming in
diff_config.toml: Indiff_config.toml, the source TiDB (port 4000) is namedmysql1and the target MySQL (port 3306) is namedtidb0. This naming could be slightly counter-intuitive. This is a minor clarity point and was not commented on directly due to itslowseverity.
Merge Readiness
The pull request is generally in good shape and adds a valuable integration test. There is one medium-severity issue regarding unused variables in the run.sh script that should be addressed to improve code maintainability. Once that is resolved, the PR should be ready for merging. As an AI, I am not authorized to approve pull requests; please ensure further review and approval from authorized maintainers.
| CDC_COUNT=3 | ||
| DB_COUNT=4 |
|
@gemini-code-assist[bot]: adding LGTM is restricted to approvers and reviewers in OWNERS files. DetailsIn response to this:
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. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: asddongmen The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
/test pull-cdc-mysql-integration-heavy |
2 similar comments
|
/test pull-cdc-mysql-integration-heavy |
|
/test pull-cdc-mysql-integration-heavy |
|
/test pull-cdc-mysql-integration-heavy |
1 similar comment
|
/test pull-cdc-mysql-integration-heavy |
|
[FORMAT CHECKER NOTIFICATION] Notice: To remove the 📖 For more info, you can check the "Contribute Code" section in the development guide. |
|
/retest |
|
/test pull-cdc-mysql-integration-heavy |
|
@hongyunyan: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. I understand the commands that are listed here. |
|
/test pull-cdc-mysql-integration-heavy |
What problem does this PR solve?
Issue Number: close #xxx
What is changed and how it works?
Check List
Tests
Questions
Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?
Release note