Skip to content

Commit 39b4fcf

Browse files
committed
speed up weaver tests
1 parent 3226b7e commit 39b4fcf

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

tests/opentelemetry-test-utils/src/opentelemetry/test/weaver_live_check.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def test_my_telemetry(self):
252252

253253
def __init__(
254254
self,
255+
registry: str | None = None,
255256
schema_version: str | None = None,
256257
policies_dir: str | None = None,
257258
inactivity_timeout: int = 30,
@@ -285,13 +286,14 @@ def __init__(
285286
if policies_dir:
286287
command += ["--advice-policies", os.path.abspath(policies_dir)]
287288

288-
if schema_version is None:
289-
schema_version = list(Schemas)[-1].value.rsplit("/", 1)[-1]
289+
if registry is None:
290+
if schema_version is None:
291+
schema_version = list(Schemas)[-1].value.rsplit("/", 1)[-1]
292+
registry = f"https://github.com/open-telemetry/semantic-conventions/archive/refs/tags/v{schema_version}.tar.gz[model]"
293+
elif os.path.isdir(registry):
294+
registry = os.path.abspath(registry)
290295

291-
command += [
292-
"--registry",
293-
f"https://github.com/open-telemetry/semantic-conventions/archive/refs/tags/v{schema_version}.tar.gz[model]",
294-
]
296+
command += ["--registry", registry]
295297

296298
self._command = command
297299
logger.debug("Weaver command: %s", command)
@@ -304,15 +306,15 @@ def __exit__(self, exc_type: Any, *_: Any) -> None:
304306
self._stopped = True
305307
self.close()
306308

307-
def start(self, timeout: int = 60) -> "WeaverLiveCheck":
309+
def start(self) -> "WeaverLiveCheck":
308310
logger.debug("Starting WeaverLiveCheck process...")
309311
self._process = subprocess.Popen( # pylint: disable=consider-using-with
310312
self._command,
311313
stdout=subprocess.PIPE,
312314
stderr=subprocess.PIPE,
313315
)
314316
try:
315-
self._wait_for_ready(timeout=timeout)
317+
self._wait_for_ready()
316318
self._ready = True
317319
except Exception as exc: # pylint: disable=broad-except
318320
logs = self._read_weaver_logs()
@@ -322,22 +324,22 @@ def start(self, timeout: int = 60) -> "WeaverLiveCheck":
322324
raise
323325
return self
324326

325-
def _wait_for_ready(self, timeout: int = 60) -> None:
327+
def _wait_for_ready(self) -> None:
326328
retry = Retry(
327-
total=timeout,
329+
total=10,
328330
backoff_factor=1,
329331
backoff_max=1,
330332
# Any non-2xx response from /health means weaver isn't ready yet.
331333
status_forcelist=list(range(300, 600)),
334+
raise_on_status=True,
332335
allowed_methods=["GET"],
333336
)
334337
session = Session()
335338
session.mount("http://", HTTPAdapter(max_retries=retry))
336339
try:
337-
response = session.get(
340+
session.get(
338341
f"http://localhost:{self._admin_port}/health", timeout=5
339342
)
340-
response.raise_for_status()
341343
except Exception as exc: # pylint: disable=broad-except
342344
if self._process is not None and self._process.poll() is not None:
343345
raise RuntimeError(

tests/opentelemetry-test-utils/tests/test_weaver_live_check.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
_HAS_GRPC = False
4242

4343
_TESTDATA_DIR = os.path.join(os.path.dirname(__file__), "testdata")
44+
_REGISTRY_DIR = os.path.join(_TESTDATA_DIR, "registry")
4445

4546

4647
def _make_provider(otlp_endpoint: str) -> TracerProvider:
@@ -62,7 +63,7 @@ def _make_provider(otlp_endpoint: str) -> TracerProvider:
6263
class TestSDKInitLiveCheck(unittest.TestCase):
6364
def test_end_and_check_no_violations(self):
6465
"""end_and_check() returns a LiveCheckReport with no violations on conformant telemetry."""
65-
with WeaverLiveCheck() as weaver:
66+
with WeaverLiveCheck(registry=_REGISTRY_DIR) as weaver:
6667
provider = _make_provider(weaver.otlp_endpoint)
6768
with provider.get_tracer("test-tracer").start_as_current_span(
6869
"test-span"
@@ -76,7 +77,9 @@ def test_end_and_check_no_violations(self):
7677

7778
def test_end_and_check_raises_on_violations(self):
7879
"""end_and_check() raises LiveCheckError with the report attached."""
79-
with WeaverLiveCheck(policies_dir=_TESTDATA_DIR) as weaver:
80+
with WeaverLiveCheck(
81+
registry=_REGISTRY_DIR, policies_dir=_TESTDATA_DIR
82+
) as weaver:
8083
provider = _make_provider(weaver.otlp_endpoint)
8184
with provider.get_tracer("test-tracer").start_as_current_span(
8285
"test-span"
@@ -105,7 +108,7 @@ def test_end_and_check_raises_on_violations(self):
105108

106109
def test_end_no_violations(self):
107110
"""end() returns a LiveCheckReport with no violations on conformant telemetry."""
108-
with WeaverLiveCheck() as weaver:
111+
with WeaverLiveCheck(registry=_REGISTRY_DIR) as weaver:
109112
provider = _make_provider(weaver.otlp_endpoint)
110113
with provider.get_tracer("test-tracer").start_as_current_span(
111114
"test-span"
@@ -123,7 +126,9 @@ def test_end_no_violations(self):
123126

124127
def test_end_with_violations(self):
125128
"""end() returns a LiveCheckReport with violations without raising."""
126-
with WeaverLiveCheck(policies_dir=_TESTDATA_DIR) as weaver:
129+
with WeaverLiveCheck(
130+
registry=_REGISTRY_DIR, policies_dir=_TESTDATA_DIR
131+
) as weaver:
127132
provider = _make_provider(weaver.otlp_endpoint)
128133
with provider.get_tracer("test-tracer").start_as_current_span(
129134
"test-span"
@@ -150,7 +155,7 @@ def test_end_with_violations(self):
150155

151156
def test_report_span_statistics(self):
152157
"""The full report exposes span counts and individual span samples."""
153-
with WeaverLiveCheck() as weaver:
158+
with WeaverLiveCheck(registry=_REGISTRY_DIR) as weaver:
154159
provider = _make_provider(weaver.otlp_endpoint)
155160
with provider.get_tracer("test-tracer").start_as_current_span(
156161
"test-span"

0 commit comments

Comments
 (0)