8000 Fix GaussDB Compatibility and State Pollution Issues in Test Suite by pangpang20 · Pull Request #7 · HuaweiCloudDeveloper/gaussdb-python · GitHub
[go: up one dir, main page]

Skip to content

Fix GaussDB Compatibility and State Pollution Issues in Test Suite #7

New issue 8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 28, 2025

Conversation

pangpang20
Copy link

Description

This pull request addresses multiple issues in the test suite to improve compatibility with GaussDB and fix state pollution in the test_copy_from_leaks test. The changes include fixes for invalid SQL statements, unsupported features in GaussDB, and improvements to test reliability by ensuring proper transaction commits. Additionally, the test suite has been updated to handle new authentication error messages and improve error message parsing using regex.

Changes Made

  • GaussDB Compatibility:

    • Fixed invalid SELECT queries with no columns to prevent errors in GaussDB.
    • Added dummy columns to table creation statements to avoid empty table definitions, which are not supported by GaussDB.
    • Skipped tests for unsupported features in GaussDB, such as NOTIFY statements and SCROLL CURSOR.
    • Modified sample_binary_str in _test_copy.py to ensure compatibility with GaussDB's COPY BINARY format.
  • State Pollution Fix:

    • Added conn.commit() after table drop and create operations in test_copy_from_leaks (both synchronous and asynchronous versions) to prevent state pollution during multiple iterations of the test. This resolves inconsistent timedelta values causing assertion failures in Format.TEXT tests.
  • Test Assertion Improvements:

    • Updated test assertions to handle new authentication error messages in test_generators.py.
    • Replaced direct attribute checks with regex matching for connection error messages in test_errors.py to improve robustness.
  • Test Suite Cleanup:

    • Removed tests for invalid or unsupported queries (e.g., empty SELECT, empty table creation) that were not relevant for GaussDB.
    • Updated test queries to include dummy columns where necessary (e.g., statusmessage, test_no_prepare).
    • Adjusted cursor tests to set scrollable=False by default, as SCROLL CURSOR is not supported in GaussDB.
  • Code Quality:

    • Reduced code by removing redundant test cases (e.g., scroll cursor tests), resulting in 30 additions and 107 deletions.
    • Added debug logging in test_copy_async.py to improve visibility into test results.

Why

The test suite was failing when run against GaussDB due to several compatibility issues, including invalid SQL queries (e.g., empty SELECT statements, empty table definitions), unsupported features (e.g., NOTIFY, SCROLL CURSOR), and state pollution in test_copy_from_leaks causing inconsistent timedelta values. These failures were critical as they prevented reliable testing of the psycopg library on GaussDB, a key target database. Additionally, changes in authentication error messages required updates to test assertions, and direct attribute checks for error messages were brittle, necessitating a shift to regex-based parsing. This PR ensures the test suite is robust, compatible with GaussDB, and maintains consistency with PostgreSQL.

Testing

  • Ran pytest tests/test_copy.py --test-dsn "${DSN}" -s -v and confirmed all tests pass, including test_copy_from_leaks[Format.TEXT-True] and test_copy_from_leaks[Format.TEXT-False].
  • Ran pytest tests/test_copy_async.py::test_copy_from_leaks --test-dsn "${DSN}" -s -v to verify async tests remain stable.
  • Validated GaussDB-specific changes by running tests against a GaussDB instance, ensuring no errors for unsupported features (NOTIFY, SCROLL CURSOR, empty tables).
  • Manually inspected exported CSV files (related to Hive export context) to ensure compatibility with PostgreSQL COPY operations.

Additional Notes

  • Hive Integration Context: The PR includes considerations for compatibility with Hive exports (e.g., CSV files used in PostgreSQL COPY operations). The timedelta issues in test_copy_from_leaks were partly due to inconsistent serialization of interval types, which may also affect Hive-to-PostgreSQL data pipelines. Users exporting Hive data to CSV (as discussed in the context of INSERT OVERWRITE DIRECTORY) should ensure interval fields are cast to strings to avoid format mismatches.
  • GaussDB Limitations: GaussDB's lack of support for NOTIFY and SCROLL CURSOR necessitated skipping or modifying related tests. These changes do not impact PostgreSQL compatibility but ensure the test suite is robust for both databases.
  • Future Improvements: Consider adding more robust interval type handling in test_copy.py to prevent future timedelta mismatches, potentially by adding a tolerance-based comparison for timedelta values. If Hive integration becomes a primary focus, additional tests for CSV import/export compatibility could be added.
  • Debugging Aids: The added debug logging in test_copy_async.py can be extended to other tests if further issues arise. Users are encouraged to inspect result and want outputs when debugging similar issues.

pangpang20 added 11 commits May 27, 2025 16:02
fix(test): NOFITY statement is not yet supported for GaussDB
…straint and relation names

Replaced `diag.constraint_name` and `diag.table_name` assertions with regex checks on `diag.message_primary` to improve compatibility across environments.
Also removed severity assertion: `diag.severity_nonlocalized == "ERROR"`.
Adapt tests for GaussDB compatibility in error handling and server cursors.
Adapt tests for GaussDB compatibility in error handling and server cursors.
fix(test): avoid no col query for GaussDB
@liubao68 liubao68 merged commit d4a12b9 into HuaweiCloudDeveloper:master May 28, 2025
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
0