Skip to content

chore(spanner): remove test-only code from production package - #19269

Open
olavloite wants to merge 1 commit into
mainfrom
spanner-remove-test-only-code-from-prod
Open

olavloite wants to merge 1 commit into
mainfrom
spanner-remove-test-only-code-from-prod

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Remove internal test infrastructure (mock servers, generated test gRPC stubs, test database subclasses, and test interceptors) from the shipped Spanner package so test plumbing is no longer distributed to production users.

  • Keep enable_interceptors_in_tests as a deprecated no-op on database creation (sync and async), emitting a deprecation warning when enabled so callers have a grace period before removal.
  • Move the mock server and interceptor helpers into the test suite and attach test interceptors directly to standard database channels during test setup.
  • Migrate all existing mock server, system, and unit tests to standard databases and add tests covering the deprecation warning and moved test helpers.

@olavloite
olavloite requested a review from a team as a code owner November 30, 2026 10:23

@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 the test interceptor architecture by deprecating the enable_interceptors_in_tests parameter and removing the test-only TestDatabase class from the production package. It introduces a dedicated tests._interceptors module with gRPC client interceptors and channel attachment helpers, updating the test suite accordingly. The review feedback recommends normalizing gRPC method names (which can be str or bytes) to strings in both MethodCountInterceptor and MethodAbortInterceptor to prevent lookup and comparison failures during testing.

@olavloite
olavloite force-pushed the spanner-remove-test-only-code-from-prod branch from a230d45 to 5d0db24 Compare November 30, 2026 10:36
@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 deprecates the enable_interceptors_in_tests parameter in Instance.database and removes the test-only TestDatabase class and interceptors from the production package, refactoring them into a test-only module (tests/_interceptors.py). The mock server, system, and unit tests have been updated to use the new interceptor attachment helpers. The review feedback recommends adding explicit cleanup steps or assigning databases to self._database in several test cases to prevent gRPC channel resource leaks.

Remove internal test infrastructure (mock servers, generated test gRPC
stubs, test database subclasses, and test interceptors) from the shipped
Spanner package so test plumbing is no longer distributed to production
users.

- Keep `enable_interceptors_in_tests` as a deprecated no-op on database
  creation (sync and async), emitting a deprecation warning when enabled
  so callers have a grace period before removal.
- Move the mock server and interceptor helpers into the test suite,
  attaching test interceptors directly to standard database channels
  during test setup and enforcing request-ID headers on the mock server
  across both sync and async suites.
- Migrate all existing mock server, system, and unit tests to standard
  databases, ensure test databases and gRPC transports are closed on
  teardown, and add unit and mock server tests covering the deprecation
  warning and moved test helpers.
@olavloite
olavloite force-pushed the spanner-remove-test-only-code-from-prod branch from 5d0db24 to f6638a0 Compare November 30, 2026 13:42
@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 deprecates the enable_interceptors_in_tests parameter and removes the test-only TestDatabase class, replacing them with a new test-only helper module tests/_interceptors.py that provides thread-safe sync and async gRPC client interceptors and channel attachment helpers. Additionally, it updates mock server, system, and unit tests to use these new helpers and adds request-ID header validation to the mock Spanner server. The review feedback highlights a compatibility issue with Python versions prior to 3.10 due to the runtime use of the PEP 604 union operator | in isinstance checks, and suggests using getattr to safely access private attributes on mock or external objects to prevent potential AttributeErrors.

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