Skip to content

DO NOT MERGE YET: Helper functions for qe SGW tests#389

Closed
torcolvin wants to merge 5 commits into
mainfrom
helper-functions-for-QE-tests
Closed

DO NOT MERGE YET: Helper functions for qe SGW tests#389
torcolvin wants to merge 5 commits into
mainfrom
helper-functions-for-QE-tests

Conversation

@torcolvin
Copy link
Copy Markdown
Collaborator

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:

  • Change create_user_client to use a context manager so that close is automatically called if a test fails
  • Create a more robust way to drop buckets, wait for SG dbs to be absent, create a new database. This needs to be a helper function in the case that rosmar is used, since it doesn't communicate with CBS to create a bucket and uses CouchbaseCloud instance.
  • A SG dev build doesn't have a version number, so create a different helper function for vv support relying on the presence of enable_cross_cluster_versioning in /_cluster_info which is only present in SG 4.0
  • Switch scan_rest_endpoints to 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:

uv run environment/local/start_local.py --build-testserver 4.0.3
uv run environment/local/run_sync_gateway.py --server rosmar --start
uv run pytest --config environment/local/rosmar_config.json tests/dev_e2e

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.

- 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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_client into an async context manager to ensure automatic cleanup.
  • Add/adjust CouchbaseCloud helpers for dropping buckets and creating databases (including Rosmar-aware behavior), and update test_db_online_offline.py to 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_client is now an @asynccontextmanager, which is a breaking change for existing callers that do await sg.create_user_client(...). Either update all call sites in this PR to use async 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():
Comment thread client/src/cbltest/api/syncgateway.py
Comment thread client/src/cbltest/api/cloud.py
Comment thread tests/QE/test_xattrs.py
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 thread tests/QE/test_xattrs.py
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")
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.

Actually true, what if the field isn't there, atleast wrapping this in a try/catch is better.

Comment thread client/src/cbltest/api/cloud.py
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
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.

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>
Base automatically changed from CBG-5213 to main April 21, 2026 00:11
@torcolvin
Copy link
Copy Markdown
Collaborator Author

This was a proof of concept, it will not be merged.

@torcolvin torcolvin closed this May 5, 2026
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.

3 participants