Skip to content

test(spanner): upgrade Spanner sample instance fixtures to session scope#17175

Merged
sakthivelmanii merged 1 commit into
mainfrom
optimize-spanner-test-shared-instances
May 19, 2026
Merged

test(spanner): upgrade Spanner sample instance fixtures to session scope#17175
sakthivelmanii merged 1 commit into
mainfrom
optimize-spanner-test-shared-instances

Conversation

@sakthivelmanii
Copy link
Copy Markdown
Contributor

Previously, standard and multi-region Spanner instance fixtures in conftest.py were module-scoped, meaning a brand-new Spanner instance was created and destroyed for every single test file, adding massive execution time (~2 minutes per file) in CI/CD runs.

This change upgrades the instance and config fixtures to session scope. To prevent ScopeMismatch exceptions, the dependencies on module-scoped sample_name are replaced with a generic shared-samples label. This allows the test suite to reuse a single shared Spanner instance, dramatically optimizing test execution times.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@sakthivelmanii sakthivelmanii requested a review from a team as a code owner May 19, 2026 10:38
Copy link
Copy Markdown
Contributor

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

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 removes the sample_name fixture across multiple test files and centralizes instance labeling in conftest.py by using a hardcoded "shared-samples" value. Additionally, several fixtures in conftest.py have been upgraded from module to session scope. A potential issue was identified regarding a ScopeMismatch error, as the newly session-scoped sample_instance fixture depends on other fixtures that might still be module-scoped.

Comment on lines 128 to 129
spanner_client,
cleanup_old_instances,
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.

high

The sample_instance fixture has been upgraded to session scope, but it depends on spanner_client and cleanup_old_instances. If these fixtures are still module-scoped (which was the previous scope for most fixtures in this file), pytest will raise a ScopeMismatch error. Please ensure that spanner_client, cleanup_old_instances, and any other dependencies of session-scoped fixtures are also upgraded to session scope.

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.

spanner_client and cleanup_old_instances were already session scope, so this should not cause any problems.

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.

Won't this cause race conditions if multiple integration test runs are started in parallel? They will now use the same instance, and potentially try to use the same database name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I fixed it. created a new unique db name

Previously, standard and multi-region Spanner instance fixtures in
conftest.py were module-scoped, meaning a brand-new Spanner instance
was created and destroyed for every single test file, adding massive
execution time (~2 minutes per file) in CI/CD runs.

This change upgrades the instance and config fixtures to session scope.
To prevent ScopeMismatch exceptions, the dependencies on module-scoped
sample_name are replaced with a generic shared-samples label. This
allows the test suite to reuse a single shared Spanner instance,
dramatically optimizing test execution times.
@sakthivelmanii sakthivelmanii force-pushed the optimize-spanner-test-shared-instances branch from a9e0f14 to 805dcd1 Compare May 19, 2026 11:08
@sakthivelmanii sakthivelmanii merged commit 8ebfde9 into main May 19, 2026
31 checks passed
@sakthivelmanii sakthivelmanii deleted the optimize-spanner-test-shared-instances branch May 19, 2026 11:55
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