DO NOT MERGE YET: Helper functions for qe SGW tests#389
Closed
torcolvin wants to merge 5 commits into
Closed
Conversation
- Create CouchbaseCloud.drop_bucket function since this might be a Sync Gateway operation or a server operation - Change the behavior when creating the database to make sure all databases that are backed by a given bucket are actually gone. If you had multiple databases on the same bucket using different collections, then dropping all of them is necessary to avoid issues creating a database if the new databases targets different collections than the dropped one. - Add special rosmar option to sync gateway config support dropping rosmar buckets - Make sure to stop sync gateway if it was already running
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces new/updated helpers for QE Sync Gateway (SGW) tests to better support Rosmar/SG dev builds, improve bucket/database reset behavior, and standardize version-vector capability checks.
Changes:
- Replace packaging-based SGW version comparisons in several QE tests with a new
SyncGateway.supports_version_vectors()helper. - Refactor
SyncGateway.create_user_clientinto an async context manager to ensure automatic cleanup. - Add/adjust
CouchbaseCloudhelpers for dropping buckets and creating databases (including Rosmar-aware behavior), and updatetest_db_online_offline.pyto use them.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/QE/test_xattrs.py | Switches version-vector support checks to supports_version_vectors() |
| tests/QE/test_users_channels.py | Switches version-vector support checks to supports_version_vectors() |
| tests/QE/test_replication_multiple_clients.py | Switches version-vector support checks to supports_version_vectors() |
| tests/QE/test_multiple_servers.py | Switches version-vector support checks to supports_version_vectors() |
| tests/QE/test_db_online_offline.py | Uses simple_cloud() helpers; refactors endpoint scanning and user client handling |
| client/src/cbltest/api/syncgateway.py | Adds supports_version_vectors(), scheme property, and converts create_user_client to async context manager; moves Rosmar detection |
| client/src/cbltest/api/cloud.py | Enhances bucket-drop behavior (Rosmar-aware) and adds create_database()/create_bucket() helpers |
Comments suppressed due to low confidence (1)
client/src/cbltest/api/syncgateway.py:1967
create_user_clientis now an@asynccontextmanager, which is a breaking change for existing callers that doawait sg.create_user_client(...). Either update all call sites in this PR to useasync with sg.create_user_client(...) as client:, or keep backward compatibility by providing a non-context-manager helper as well. Also consider updating the return type annotation to reflect an async context manager/iterator.
@contextlib.asynccontextmanager
async def create_user_client(
self,
db_name: str,
username: str,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| sgw_version = Version(sgw_version_obj.version) | ||
| supports_version_vectors = sgw_version >= Version("4.0.0") | ||
| if supports_version_vectors: | ||
| if sg.supports_version_vectors(): |
| sgw_version_obj = await sg.get_version() | ||
| sgw_version = Version(sgw_version_obj.version) | ||
| supports_version_vectors = sgw_version >= Version("4.0.0") | ||
| supports_version_vectors = sg.supports_version_vectors() |
| sgw_version_obj = await sg.get_version() | ||
| sgw_version = Version(sgw_version_obj.version) | ||
| supports_version_vectors = sgw_version >= Version("4.0.0") | ||
| supports_version_vectors = sg.supports_version_vectors() |
Comment on lines
+65
to
+76
| assert e is not None, ( | ||
| f"Expected endpoint {test_name} but got exception: {e}" | ||
| ) | ||
| else: | ||
| # 404 is true for Sync Gateway 4.0.4+ CBG-5156 | ||
| # 403 will occur if Sync Gateway < 4.0.4 or using rosmar | ||
| assert e.code in [403, 404], ( | ||
| f"Expected 403 or 404 for endpoint {test_name} but got {e.code}" | ||
| ) | ||
| return | ||
| assert expected_online, ( | ||
| f"Expected endpoint {test_name} to fail with 404 if offline, but it succeeded with 200" |
Comment on lines
+642
to
+643
| for bucket in resp_data: | ||
| return bucket.get("enable_cross_cluster_versioning") |
Contributor
There was a problem hiding this comment.
Actually true, what if the field isn't there, atleast wrapping this in a try/catch is better.
Comment on lines
+1626
to
+1631
| self.using_rosmar = r.json()["bootstrap"]["server"].startswith("rosmar") | ||
| except AttributeError: | ||
| raise CblTestError( | ||
| "Unexpected response {r.json()} from Sync Gateway /_config endpoint, cannot determine if using Rosmar" | ||
| ) from None | ||
| self.using_rosmar = False |
Contributor
There was a problem hiding this comment.
Make this an formatted string genuinely.
| sgw_version = Version(sgw_version_obj.version) | ||
| supports_version_vectors = sgw_version >= Version("4.0.0") | ||
| if supports_version_vectors: | ||
| if sg.supports_version_vectors(): |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Collaborator
Author
|
This was a proof of concept, it will not be merged. |
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.
Do not merge until the following PRs are resolved
#386
#387
You can take or leave part of these PRs. I wanted to be able to run some QE tests with rosmar or a SG dev build in the test_db_online_offline.py.
Fixes:
create_user_clientto use a context manager so thatcloseis automatically called if a test failsCouchbaseCloudinstance.enable_cross_cluster_versioningin/_cluster_infowhich is only present in SG 4.0scan_rest_endpointsto provide a clear error if they fail for some reason. I believe that it should never return 500, but only 403 or 404 errors if offline.To test locally:
This PR you can take or leave but it has some interesting fixes. @vipbhardwaj you should test this with SG 3.3 and SG 4.0 if you want to merge this code. There are other places that could use these helper functions, but I only changed code that I could test.