Skip to content

Commit 256578d

Browse files
committed
🧪 Remove sleeps where possible in tests
1 parent 97a429d commit 256578d

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

‎tests/functional/test_client.py

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import glob
88
import pathlib
99
import time
10+
11+
import requests
1012
import pytest_mock
1113
import tempfile
1214
import simvue.client as svc
@@ -15,14 +17,12 @@
1517
import simvue.api.objects as sv_api_obj
1618
from simvue.api.objects.alert.base import AlertBase
1719

18-
@pytest.mark.dependency
1920
@pytest.mark.client
2021
def test_get_events(create_test_run: tuple[sv_run.Run, dict]) -> None:
2122
client = svc.Client()
2223
assert client.get_events(run_id=create_test_run[1]["run_id"])
2324

2425

25-
@pytest.mark.dependency
2626
@pytest.mark.client
2727
@pytest.mark.parametrize(
2828
"from_run", (True, False), ids=("from_run", "all_runs")
@@ -90,7 +90,6 @@ def test_get_alerts(
9090
assert len(_alerts) == 2
9191
assert f"user_alert_2_{unique_id}" in _alerts
9292

93-
@pytest.mark.dependency
9493
@pytest.mark.client
9594
def test_get_run_id_from_name(create_test_run: tuple[sv_run.Run, dict]) -> None:
9695
client = svc.Client()
@@ -100,7 +99,6 @@ def test_get_run_id_from_name(create_test_run: tuple[sv_run.Run, dict]) -> None:
10099
)
101100

102101

103-
@pytest.mark.dependency
104102
@pytest.mark.client
105103
@pytest.mark.parametrize(
106104
"aggregate,use_name_labels",
@@ -138,7 +136,6 @@ def test_get_metric_values(
138136
assert create_test_run[1]["run_id"] in _runs
139137

140138

141-
@pytest.mark.dependency
142139
@pytest.mark.client
143140
def test_plot_metrics(create_test_run: tuple[sv_run.Run, dict]) -> None:
144141
try:
@@ -154,7 +151,6 @@ def test_plot_metrics(create_test_run: tuple[sv_run.Run, dict]) -> None:
154151
)
155152

156153

157-
@pytest.mark.dependency
158154
@pytest.mark.client
159155
@pytest.mark.parametrize(
160156
"sorting", ([("metadata.test_identifier", True)], [("name", True), ("created", True)], None),
@@ -166,7 +162,6 @@ def test_get_artifacts_entries(create_test_run: tuple[sv_run.Run, dict], sorting
166162
assert client.get_artifact(create_test_run[1]["run_id"], name="test_attributes")
167163

168164

169-
@pytest.mark.dependency
170165
@pytest.mark.client
171166
@pytest.mark.parametrize("file_id", (1, 2, 3), ids=lambda x: f"file_{x}")
172167
def test_get_artifact_as_file(
@@ -183,7 +178,6 @@ def test_get_artifact_as_file(
183178
assert pathlib.Path(tempd).joinpath(_file_name).exists(), f"Failed to download '{_file_name}'"
184179

185180

186-
@pytest.mark.dependency
187181
@pytest.mark.client
188182
@pytest.mark.parametrize("category", (None, "code", "input", "output"))
189183
def test_get_artifacts_as_files(
@@ -213,7 +207,6 @@ def test_get_artifacts_as_files(
213207
assert create_test_run[1][file] not in files
214208

215209

216-
@pytest.mark.dependency
217210
@pytest.mark.client
218211
@pytest.mark.parametrize(
219212
"output_format,sorting",
@@ -235,14 +228,12 @@ def test_get_runs(create_test_run: tuple[sv_run.Run, dict], output_format: str,
235228
assert _result
236229

237230

238-
@pytest.mark.dependency
239231
@pytest.mark.client
240232
def test_get_run(create_test_run: tuple[sv_run.Run, dict]) -> None:
241233
client = svc.Client()
242234
assert client.get_run(run_id=create_test_run[1]["run_id"])
243235

244236

245-
@pytest.mark.dependency
246237
@pytest.mark.client
247238
@pytest.mark.parametrize(
248239
"sorting", (None, [("metadata.test_identifier", True), ("path", True)], [("modified", False)]),
@@ -256,24 +247,32 @@ def test_get_folders(create_test_run: tuple[sv_run.Run, dict], sorting: list[tup
256247
assert client.get_folder(_folder.path)
257248

258249

259-
@pytest.mark.dependency
260250
@pytest.mark.client
261251
def test_get_metrics_names(create_test_run: tuple[sv_run.Run, dict]) -> None:
262252
client = svc.Client()
263-
time.sleep(1)
264-
assert list(client.get_metrics_names(create_test_run[1]["run_id"]))
253+
attempts: int = 0
254+
255+
while not list(client.get_metrics_names(create_test_run[1]["run_id"])) and attempts < 10:
256+
time.sleep(1)
257+
attempts += 1
258+
259+
if attempts >= 10:
260+
raise AssertionError("Failed to retrieve metric name.")
265261

266262

267-
@pytest.mark.dependency
268263
@pytest.mark.client
269264
def test_get_tag(create_plain_run: tuple[sv_run.Run, dict]) -> None:
270265
_, run_data = create_plain_run
271266
client = svc.Client()
272-
time.sleep(1.0)
273-
assert any(tag.name == run_data["tags"][-1] for _, tag in client.get_tags())
267+
attempts: int = 0
268+
while not any(tag.name == run_data["tags"][-1] for _, tag in client.get_tags()) and attempts < 10:
269+
time.sleep(1)
270+
attempts += 1
271+
272+
if attempts >= 10:
273+
raise AssertionError("Failed to retrieve tag.")
274274

275275

276-
@pytest.mark.dependency
277276
@pytest.mark.client
278277
def test_run_deletion() -> None:
279278
run = sv_run.Run()
@@ -286,7 +285,6 @@ def test_run_deletion() -> None:
286285
client.get_run(run.id)
287286

288287

289-
@pytest.mark.dependency
290288
@pytest.mark.client
291289
def test_runs_deletion() -> None:
292290
_runs = [sv_run.Run() for _ in range(5)]
@@ -300,19 +298,21 @@ def test_runs_deletion() -> None:
300298
client.get_run(run.id)
301299

302300

303-
@pytest.mark.dependency
304301
@pytest.mark.client
305302
def test_get_tags(create_plain_run: tuple[sv_run.Run, dict]) -> None:
306303
run, run_data = create_plain_run
307304
tags = run_data["tags"]
308305
run.close()
309-
time.sleep(1.0)
310306
client = svc.Client()
311-
retrieved = [t.name for _, t in client.get_tags()]
312-
assert all(t in retrieved for t in tags)
307+
attempts = 0
308+
while not all(f in [t.name for _, t in client.get_tags()] for f in tags) and attempts < 10:
309+
time.sleep(1)
310+
attempts += 1
311+
312+
if attempts >= 10:
313+
raise AssertionError("Failed to retrieve tags.")
313314

314315

315-
@pytest.mark.dependency
316316
@pytest.mark.client
317317
def test_folder_deletion() -> None:
318318
run = sv_run.Run()
@@ -359,7 +359,6 @@ def test_tag_deletion() -> None:
359359
client.get_tag(tag_identifier)
360360

361361

362-
@pytest.mark.dependency
363362
@pytest.mark.client
364363
@pytest.mark.parametrize("aggregate", (True, False), ids=("aggregated", "normal"))
365364
@pytest.mark.parametrize("output_format", ("dict", "dataframe"))
@@ -414,14 +413,11 @@ def test_abort_run(speedy_heartbeat, create_plain_run: tuple[sv_run.Run, dict])
414413
run.update_tags([f"delete_me_{_uuid}"])
415414
_client = svc.Client()
416415
_client.abort_run(run.id, reason="Test abort")
417-
time.sleep(2)
418-
419-
# On some machines it might take a little longer so
420-
# try twice before accepting the abort failed
421-
try:
422-
assert run._status == "terminated"
423-
except AssertionError:
424-
time.sleep(2)
425-
assert run._status == "terminated"
416+
_attempts: int = 0
426417

418+
while run.status != "terminated" and _attempts < 10:
419+
time.sleep(1)
420+
_attempts += 1
421+
if _attempts >= 10:
422+
raise AssertionError("Failed to terminate run.")
427423

0 commit comments

Comments
 (0)