Skip to content

test(spanner): consolidate admin system tests to reduce DDL and database churn - #18693

Open
olavloite wants to merge 1 commit into
mainfrom
spanner-simplify-db-admin-tests
Open

olavloite wants to merge 1 commit into
mainfrom
spanner-simplify-db-admin-tests

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Consolidate administrative system tests in test_database_api.py to eliminate redundant database creations, long-running operations (LROs), and schema churn:

  1. Consolidate Create & Update Tests:
    • Combine PITR database creation and subsequent DDL update into a single test (test_create_and_update_database_pitr), asserting both client properties and Information Schema catalog values.
    • Combine default leader creation and subsequent update into a single multi-region database test (test_create_and_update_database_with_default_leader).
    • Merge test_update_ddl_w_operation_id into test_create_database_and_update_ddl.
  2. Consolidate Database Roles & Permissions:
    • Merge test_create_role_grant_access_success and test_list_database_role_success into test_create_role_grant_access_and_list_roles.
    • Strip the 20-table schema down to only the single required table (contacts).
    • Eliminate redundant teardown DDL (revoking permissions and dropping roles) immediately prior to database deletion.
    • Fix a lazy evaluation bug where the parent role query was never iterated and therefore never dispatched over the wire.
  3. Remove Pure Server-Side DDL Parser Tests:
    • Drop test_create_database_pitr_invalid_retention_period and test_update_ddl_w_pitr_invalid, which tested Spanner backend syntax rejection of '0d' rather than client validation logic.
  4. Fix Multi-Region Database Timeout:
    • Replace the hardcoded 30-second timeout on multi-region database creation with DBAPI_OPERATION_TIMEOUT (240s) to prevent CI flakes under load.

Savings:

  • Eliminates 5 full database creations and drops (including 1 multi-region DB).
  • Eliminates ~8 long-running DDL operations.

@olavloite
olavloite requested a review from a team as a code owner October 14, 2026 10:50

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors and consolidates several system tests in test_database_api.py for Google Cloud Spanner. It merges separate creation and update tests for databases, PITR, default leaders, and database roles into combined, more efficient test cases, while removing redundant test definitions. A review comment correctly points out that using us-central1 as the new default leader in the multi-region test will fail because it is typically a witness replica, and suggests using us-east1 instead.

Comment thread packages/google-cloud-spanner/tests/system/test_database_api.py Outdated
…ase churn

Consolidate administrative system tests in `test_database_api.py` to eliminate
redundant database creations, long-running operations (LROs), and schema churn:
1. Consolidate Create & Update Tests:
   - Combine PITR database creation and subsequent DDL update into a single
     test (`test_create_and_update_database_pitr`), asserting both client
     properties and Information Schema catalog values.
   - Combine default leader creation and subsequent update into a single
     multi-region database test (`test_create_and_update_database_with_default_leader`).
   - Merge `test_update_ddl_w_operation_id` into `test_create_database_and_update_ddl`.
2. Consolidate Database Roles & Permissions:
   - Merge `test_create_role_grant_access_success` and `test_list_database_role_success`
     into `test_create_role_grant_access_and_list_roles`.
   - Strip the 20-table schema down to only the single required table (`contacts`).
   - Eliminate redundant teardown DDL (revoking permissions and dropping roles)
     immediately prior to database deletion.
   - Fix a lazy evaluation bug where the parent role query was never iterated
     and therefore never dispatched over the wire.
3. Remove Pure Server-Side DDL Parser Tests:
   - Drop `test_create_database_pitr_invalid_retention_period` and
     `test_update_ddl_w_pitr_invalid`, which tested Spanner backend syntax
     rejection of '0d' rather than client validation logic.
4. Fix Multi-Region Database Timeout:
   - Replace the hardcoded 30-second timeout on multi-region database creation
     with `DBAPI_OPERATION_TIMEOUT` (240s) to prevent CI flakes under load.

Savings:
- Eliminates 5 full database creations and drops (including 1 multi-region DB).
- Eliminates ~8 long-running DDL operations.
@olavloite
olavloite force-pushed the spanner-simplify-db-admin-tests branch from 200570c to d36a154 Compare October 14, 2026 11:55
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors and consolidates several system tests in test_database_api.py by combining database creation and DDL update tests (such as PITR and default leader updates) into single, unified test cases. It also removes redundant test cases and simplifies role creation and listing tests. The feedback suggests ensuring that database option queries do not silently pass if they return empty results by converting the query results to a list and asserting that exactly one row is returned.

Comment on lines +163 to +171
with temp_db.snapshot() as snapshot:
results = snapshot.execute_sql(
"SELECT OPTION_VALUE AS version_retention_period "
"FROM INFORMATION_SCHEMA.DATABASE_OPTIONS "
"WHERE SCHEMA_NAME = '' "
"AND OPTION_NAME = 'version_retention_period'"
)
for result in results:
assert result[0] == new_retention_period

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the query returns no rows, the for result in results: loop will not execute, and the assertion assert result[0] == new_retention_period will be silently skipped. To prevent a potential silent test pass, convert the results to a list and assert that exactly one row is returned.

Suggested change
with temp_db.snapshot() as snapshot:
results = snapshot.execute_sql(
"SELECT OPTION_VALUE AS version_retention_period "
"FROM INFORMATION_SCHEMA.DATABASE_OPTIONS "
"WHERE SCHEMA_NAME = '' "
"AND OPTION_NAME = 'version_retention_period'"
)
for result in results:
assert result[0] == new_retention_period
with temp_db.snapshot() as snapshot:
results = list(
snapshot.execute_sql(
"SELECT OPTION_VALUE AS version_retention_period "
"FROM INFORMATION_SCHEMA.DATABASE_OPTIONS "
"WHERE SCHEMA_NAME = '' "
"AND OPTION_NAME = 'version_retention_period'"
)
)
assert len(results) == 1
assert results[0][0] == new_retention_period

Comment on lines +222 to +229
with temp_db.snapshot() as snapshot:
results = snapshot.execute_sql(
"SELECT OPTION_VALUE AS default_leader "
"FROM INFORMATION_SCHEMA.DATABASE_OPTIONS "
"WHERE SCHEMA_NAME = '' AND OPTION_NAME = 'default_leader'"
)
for result in results:
assert result[0] == new_default_leader

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the query returns no rows, the for result in results: loop will not execute, and the assertion assert result[0] == new_default_leader will be silently skipped. To prevent a potential silent test pass, convert the results to a list and assert that exactly one row is returned.

Suggested change
with temp_db.snapshot() as snapshot:
results = snapshot.execute_sql(
"SELECT OPTION_VALUE AS default_leader "
"FROM INFORMATION_SCHEMA.DATABASE_OPTIONS "
"WHERE SCHEMA_NAME = '' AND OPTION_NAME = 'default_leader'"
)
for result in results:
assert result[0] == new_default_leader
with temp_db.snapshot() as snapshot:
results = list(
snapshot.execute_sql(
"SELECT OPTION_VALUE AS default_leader "
"FROM INFORMATION_SCHEMA.DATABASE_OPTIONS "
"WHERE SCHEMA_NAME = '' AND OPTION_NAME = 'default_leader'"
)
)
assert len(results) == 1
assert results[0][0] == new_default_leader

This branch has not been deployed

No deployments
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