Skip to content

test(spanner): add async mock server test infrastructure and tests - #19168

Open
olavloite wants to merge 1 commit into
mainfrom
spanner-async-mock-server-tests
Open

olavloite wants to merge 1 commit into
mainfrom
spanner-async-mock-server-tests

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Only modifies test suites and internal test-only helpers; no production runtime code is changed.

Summary of changes:

  • Extend the async mock server test base class with client/database setup and automatic database/transport cleanup so async tests do not leak background tasks or channels across test cases.
  • Update the test-only async database and test interceptors to support multi-interface gRPC async interceptors, bytes header metadata, and async transaction abort/rollback simulation.
  • Add async mock server integration tests covering basic queries/streaming, aborted transaction retries, session pool binding, x-goog-spanner-request-id headers, and operation metrics, reusing shared assertion helpers across sync and async suites.
  • Replace wall-clock sleeps in the operation metrics tests with a deterministic fake clock.

@olavloite
olavloite requested a review from a team as a code owner November 21, 2026 14:52

@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 adds comprehensive async testing support for database interceptors and mock server tests, including new async integration tests for aborted transactions, operation metrics, pool binding, and request ID headers. The feedback suggests avoiding fragile post-creation channel hacking of private grpc.aio.Channel details by flattening multi-interface interceptors and passing them directly to standard gRPC channel creation APIs. Additionally, it is recommended to add an optional tz parameter to the mocked now() method in _FakeDatetime to ensure compatibility with standard datetime.now() usage.

@olavloite
olavloite force-pushed the spanner-async-mock-server-tests branch from 16be826 to f5b80f5 Compare November 21, 2026 15:03
@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 introduces comprehensive asynchronous testing support and refactoring across the Google Cloud Spanner Python client, including async interceptor support, refactored mock server test bases, and new async integration tests for aborted transactions, operation metrics, pool binding, and request ID headers. The review feedback suggests using getattr when appending to private interceptor lists on gRPC channels to prevent AttributeErrors on mocked channels, and inheriting the test _FakeDatetime class from datetime to avoid errors with other standard datetime methods.

@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 introduces comprehensive async support for testing utilities, mock server tests, and interceptors in the Google Cloud Spanner Python client. Key changes include adding async interceptor attachment, extending interceptors to support unary-stream calls, refactoring mock server test bases to cleanly manage async databases, and implementing extensive async test suites for aborted transactions, basic operations, operation metrics, pool binding, and request ID headers. The review feedback suggests three main improvements: defensively resolving the underlying gRPC channel before accessing private interceptor lists to prevent fragility with wrapped channels, adding a safety check for _transaction in MethodAbortAsyncInterceptor to avoid potential AttributeErrors, and subclassing datetime in the mock metrics tracer to make the fake datetime class more robust.

@olavloite
olavloite force-pushed the spanner-async-mock-server-tests branch from f5b80f5 to 61feb4c Compare November 21, 2026 15:21
@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 significantly expands async test coverage for the Google Cloud Spanner client by introducing async mock server tests, including tests for aborted transactions, basic operations, operation metrics, and pool bindings. It also updates async interceptors to support both unary-unary and unary-stream calls. The review feedback suggests improving robustness by using getattr to safely access private attributes of grpc.aio.Channel and self._connection. Additionally, it recommends enhancing the fake datetime class to handle timezones and utcnow(), and refining the _count_leading_session_requests helper to break on any non-session creation request.

Only modifies test suites and internal test-only helpers; no production
runtime code is changed.

Summary of changes:
- Extend the async mock server test base class with client/database setup
  and automatic database/transport cleanup so async tests do not leak
  background tasks or channels across test cases.
- Update the test-only async database and test interceptors to support
  multi-interface gRPC async interceptors, bytes header metadata, and
  async transaction abort/rollback simulation.
- Add async mock server integration tests covering basic queries/streaming,
  aborted transaction retries, session pool binding, x-goog-spanner-request-id
  headers, and operation metrics, reusing shared assertion helpers across
  sync and async suites.
- Replace wall-clock sleeps in the operation metrics tests with a
  deterministic fake clock.
@olavloite
olavloite force-pushed the spanner-async-mock-server-tests branch from 61feb4c to 3489306 Compare November 21, 2026 15:26
@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 significantly enhances the asynchronous testing infrastructure for Google Cloud Spanner by refactoring test interceptors to support both unary-unary and unary-stream async gRPC calls, and introducing a robust set of async mock server tests covering aborted transactions, pool binding, operation metrics, and request ID headers. Feedback on the changes suggests adding a guard clause and duplicate checks in _attach_async_interceptors to prevent duplicate interceptor registrations on the gRPC channel.

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