test(spanner): disable pooling in mock server tests#16655
Closed
chalmerlowe wants to merge 1 commit into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request reorganizes imports and disables connection pooling in the create_engine method by using NullPool to ensure fresh sessions for each test. The review feedback recommends further organizing the import block to comply with PEP 8 alphabetical sorting and moving the NullPool import from the local method scope to the top level to improve code maintainability.
Comment on lines
16
to
+30
| import google.cloud.spanner_v1.types.result_set as result_set | ||
| import google.cloud.spanner_v1.types.type as spanner_type | ||
| import grpc | ||
| from google.api_core.client_options import ClientOptions | ||
| from google.auth.credentials import AnonymousCredentials | ||
| from google.cloud.spanner_dbapi.parsed_statement import AutocommitDmlMode | ||
| from google.cloud.spanner_v1 import ( | ||
| Client, | ||
| ResultSet, | ||
| TypeCode, | ||
| ) | ||
| from google.cloud.spanner_v1.database import Database | ||
| from google.cloud.spanner_v1.instance import Instance | ||
| import grpc | ||
| from sqlalchemy import Engine, create_engine | ||
| from sqlalchemy.testing.plugin.plugin_base import fixtures |
Contributor
There was a problem hiding this comment.
The import block is disorganized and does not follow PEP 8 alphabetical sorting. Additionally, NullPool should be imported at the top level rather than locally within a method to improve readability and maintainability.
Suggested change
| import google.cloud.spanner_v1.types.result_set as result_set | |
| import google.cloud.spanner_v1.types.type as spanner_type | |
| import grpc | |
| from google.api_core.client_options import ClientOptions | |
| from google.auth.credentials import AnonymousCredentials | |
| from google.cloud.spanner_dbapi.parsed_statement import AutocommitDmlMode | |
| from google.cloud.spanner_v1 import ( | |
| Client, | |
| ResultSet, | |
| TypeCode, | |
| ) | |
| from google.cloud.spanner_v1.database import Database | |
| from google.cloud.spanner_v1.instance import Instance | |
| import grpc | |
| from sqlalchemy import Engine, create_engine | |
| from sqlalchemy.testing.plugin.plugin_base import fixtures | |
| from google.api_core.client_options import ClientOptions | |
| from google.auth.credentials import AnonymousCredentials | |
| from google.cloud.spanner_dbapi.parsed_statement import AutocommitDmlMode | |
| from google.cloud.spanner_v1 import ( | |
| Client, | |
| ResultSet, | |
| TypeCode, | |
| ) | |
| from google.cloud.spanner_v1.database import Database | |
| from google.cloud.spanner_v1.instance import Instance | |
| import google.cloud.spanner_v1.types.result_set as result_set | |
| import google.cloud.spanner_v1.types.type as spanner_type | |
| import grpc | |
| from sqlalchemy import Engine, NullPool, create_engine | |
| from sqlalchemy.testing.plugin.plugin_base import fixtures |
Comment on lines
+165
to
166
| from sqlalchemy.pool import NullPool | ||
| return create_engine( |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR disables connection pooling in the mock server tests for
sqlalchemy-spanner.We observed that many tests were failing with an off-by-one error in the expected number of requests (e.g., expecting 6 but getting 5). This suggests that
CreateSessionRequestwas not being sent for every test, likely because sessions were being reused from the pool across tests.By setting
poolclass=NullPoolincreate_engine, we force a new connection and session for every test, ensuring predictable request counts.