Skip to content

Commit 7f6f6d2

Browse files
torcolvinCopilotborrrden
authored
Add some error reporting for usability (#369)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jim Borden <jim.borden@couchbase.com>
1 parent 55784a9 commit 7f6f6d2

4 files changed

Lines changed: 51 additions & 3 deletions

File tree

client/src/cbltest/api/couchbaseserver.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
BucketAlreadyExistsException,
2424
BucketDoesNotExistException,
2525
CollectionAlreadyExistsException,
26+
CouchbaseException,
2627
DocumentNotFoundException,
2728
QueryIndexAlreadyExistsException,
2829
ScopeAlreadyExistsException,
2930
)
3031
from couchbase.management.buckets import CreateBucketSettings
3132
from couchbase.management.options import CreatePrimaryQueryIndexOptions
32-
from couchbase.options import ClusterOptions
33+
from couchbase.options import ClusterOptions, ClusterTimeoutOptions
3334
from couchbase.subdocument import upsert
3435
from opentelemetry.trace import get_tracer
3536

@@ -113,10 +114,22 @@ def __init__(self, url: str, username: str, password: str):
113114
self._parse_connection_url(url)
114115

115116
auth = PasswordAuthenticator(username, password)
116-
opts = ClusterOptions(auth)
117+
opts = ClusterOptions(
118+
auth,
119+
timeout_options=ClusterTimeoutOptions(
120+
# mac dns resolution can be very slow, default timeout is 250ms
121+
dns_srv_timeout=timedelta(seconds=10)
122+
),
123+
)
117124
self.__username = username
118125
self.__password = password
119-
self.__cluster = Cluster(url, opts)
126+
try:
127+
self.__cluster = Cluster(url, opts)
128+
except CouchbaseException as e:
129+
cbl_warning(
130+
f"Initial connection to Couchbase Server {url} with {username=} password=<redacted> failed with: {e}"
131+
)
132+
raise
120133
self.__cluster.wait_until_ready(timedelta(seconds=10))
121134

122135
# Create a reusable HTTP session for REST API calls

client/src/cbltest/utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
import subprocess
13
import time
24
from collections.abc import Callable
35
from typing import Any, TypeVar, cast
@@ -37,3 +39,32 @@ def _try_n_times(
3739
def assert_not_null(input: T | None, msg: str) -> T:
3840
assert input is not None, msg
3941
return cast(T, input)
42+
43+
44+
def verify_lfs_checkout() -> None:
45+
"""
46+
This function is used to verify that the LFS files are being properly checked out.
47+
"""
48+
try:
49+
process_output = subprocess.run(
50+
["git", "lfs", "ls-files", "--json"],
51+
check=True,
52+
capture_output=True,
53+
text=True,
54+
)
55+
except subprocess.CalledProcessError as e:
56+
raise RuntimeError(
57+
f"Failed to run {e.cmd!r} (return code {e.returncode}). "
58+
f"stdout: {e.stdout!r} stderr: {e.stderr!r}"
59+
) from e
60+
try:
61+
lfs = json.loads(process_output.stdout)
62+
except json.JSONDecodeError as e:
63+
raise RuntimeError(f"Failed to parse git lfs output: {e}.") from e
64+
if not lfs["files"]:
65+
return
66+
for f in lfs["files"]:
67+
if f["checkout"] is False:
68+
raise RuntimeError(
69+
"git lfs is not configured. Please run 'git lfs install' and then 'git lfs pull'."
70+
)

tests/QE/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import pytest_asyncio
77
from cbltest.api.couchbaseserver import CouchbaseServer
88
from cbltest.api.syncgateway import SyncGateway
9+
from cbltest.utils import verify_lfs_checkout
910

1011

1112
# This is used to inject the full path to the dataset folder
1213
# into tests that need it.
1314
@pytest.fixture(scope="session")
1415
def dataset_path() -> Path:
16+
verify_lfs_checkout()
1517
script_path = os.path.abspath(os.path.dirname(__file__))
1618
return Path(script_path, "..", "..", "dataset", "sg")
1719

tests/dev_e2e/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
from pathlib import Path
33

44
import pytest
5+
from cbltest.utils import verify_lfs_checkout
56

67

78
# This is used to inject the full path to the dataset folder
89
# into tests that need it.
910
@pytest.fixture(scope="session")
1011
def dataset_path() -> Path:
12+
verify_lfs_checkout()
1113
script_path = os.path.abspath(os.path.dirname(__file__))
1214
return Path(script_path, "..", "..", "dataset", "sg")

0 commit comments

Comments
 (0)