Skip to content

Commit 321c9fe

Browse files
author
Threepwood-7
committed
CI-168 wait past transitional ED2K connect response
1 parent f4194e7 commit 321c9fe

2 files changed

Lines changed: 70 additions & 8 deletions

File tree

scripts/deterministic-two-client-transfer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,10 @@ def add_and_connect_server(base_url: str, api_key: str, *, address: str, port: i
822822
)
823823
if int(connect_result.get("status", 0)) != 200:
824824
raise RuntimeError(f"Connecting local ED2K server failed: {rest_smoke.compact_http_result(connect_result)!r}")
825-
rest_smoke.require_json_object(connect_result, 200)
825+
connect_summary = rest_smoke.compact_http_result(connect_result)
826+
connect_payload = response_payload(connect_result, 200)
827+
if not isinstance(connect_payload, dict):
828+
raise RuntimeError(f"Connecting local ED2K server returned a non-object payload: {connect_summary!r}")
826829
connected = wait_for_emule_server_connected(
827830
base_url,
828831
api_key,
@@ -833,7 +836,7 @@ def add_and_connect_server(base_url: str, api_key: str, *, address: str, port: i
833836
"server": server,
834837
"servers_before_connect": rest_smoke.compact_http_result(servers_result),
835838
"add": add_summary,
836-
"connect": rest_smoke.compact_http_result(connect_result),
839+
"connect": connect_summary,
837840
"connected": connected,
838841
}
839842

tests/python/test_deterministic_two_client_transfer.py

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def test_resolve_manifest_repo_uses_workspace_deps(tmp_path: Path) -> None:
5757

5858

5959
def test_resolve_ed2k_server_exe_defaults_to_output_root(tmp_path: Path, monkeypatch) -> None:
60-
module = load_suite_module()
6160
workspace = tmp_path / "workspaces" / "workspace"
6261
output_root = tmp_path.parent / f"{tmp_path.name}-output"
6362
monkeypatch.setenv("EMULEBB_WORKSPACE_ROOT", str(tmp_path))
@@ -69,7 +68,6 @@ def test_resolve_ed2k_server_exe_defaults_to_output_root(tmp_path: Path, monkeyp
6968

7069

7170
def test_build_or_skip_ed2k_server_binary_honors_explicit_exe_without_manifest(tmp_path: Path) -> None:
72-
module = load_suite_module()
7371
workspace = tmp_path / "vm" / "workspace"
7472
server_exe = tmp_path / "harness" / "tools" / "goed2k-server.exe"
7573
server_exe.parent.mkdir(parents=True)
@@ -328,7 +326,6 @@ def test_write_server_met_creates_single_server_with_numeric_and_dynamic_ip(tmp_
328326

329327

330328
def test_build_server_config_uses_workspace_artifact_paths(tmp_path: Path) -> None:
331-
module = load_suite_module()
332329
config_path = tmp_path / "state" / "artifacts" / "server" / "config.json"
333330
catalog_path = tmp_path / "state" / "artifacts" / "server" / "catalog.json"
334331

@@ -354,7 +351,6 @@ def test_build_server_config_uses_workspace_artifact_paths(tmp_path: Path) -> No
354351

355352

356353
def test_build_server_config_allows_protocol_overrides(tmp_path: Path) -> None:
357-
module = load_suite_module()
358354
config_path = tmp_path / "server" / "config.json"
359355
catalog_path = tmp_path / "server" / "catalog.json"
360356

@@ -376,7 +372,6 @@ def test_build_server_config_allows_protocol_overrides(tmp_path: Path) -> None:
376372

377373

378374
def test_build_server_config_allows_admin_bind_override(tmp_path: Path) -> None:
379-
module = load_suite_module()
380375
config_path = tmp_path / "server" / "config.json"
381376
catalog_path = tmp_path / "server" / "catalog.json"
382377

@@ -410,7 +405,6 @@ def test_build_server_config_rejects_missing_ed2k_bind(tmp_path: Path) -> None:
410405

411406

412407
def test_build_server_config_allows_ed2k_bind_override(tmp_path: Path) -> None:
413-
module = load_suite_module()
414408
config_path = tmp_path / "server" / "config.json"
415409
catalog_path = tmp_path / "server" / "catalog.json"
416410

@@ -1162,6 +1156,71 @@ def fake_wait_for(resolve, *_args):
11621156
assert ("POST", "/api/v1/servers/10.1.2.3:4661/operations/connect") in calls
11631157

11641158

1159+
def test_add_and_connect_server_waits_past_transitional_connect_response(monkeypatch) -> None:
1160+
module = load_suite_module()
1161+
calls: list[tuple[str, str]] = []
1162+
status_payloads = [
1163+
{
1164+
"connected": False,
1165+
"connecting": True,
1166+
"currentServer": None,
1167+
"serverCount": 1,
1168+
},
1169+
{
1170+
"connected": True,
1171+
"connecting": False,
1172+
"currentServer": {"address": "10.1.2.3", "port": 4661, "name": "local"},
1173+
"serverCount": 1,
1174+
},
1175+
]
1176+
1177+
def fake_http_request(_base_url, path, *, method="GET", **_kwargs):
1178+
calls.append((method, path))
1179+
if path == "/api/v1/servers":
1180+
return {"status": 200, "json": [{"address": "10.1.2.3", "port": 4661, "name": "local"}]}
1181+
if path == "/api/v1/servers/10.1.2.3:4661/operations/connect":
1182+
payload = {
1183+
"connected": False,
1184+
"connecting": True,
1185+
"currentServer": None,
1186+
"serverCount": 1,
1187+
}
1188+
return {
1189+
"status": 200,
1190+
"content_type": "application/json; charset=utf-8",
1191+
"json": payload,
1192+
"raw_json": {"data": payload, "meta": {"apiVersion": "v1"}},
1193+
}
1194+
if path == "/api/v1/status":
1195+
payload = status_payloads.pop(0)
1196+
return {
1197+
"status": 200,
1198+
"content_type": "application/json; charset=utf-8",
1199+
"json": payload,
1200+
"raw_json": {"data": payload, "meta": {"apiVersion": "v1"}},
1201+
}
1202+
raise AssertionError(path)
1203+
1204+
def fake_wait_for(resolve, *_args):
1205+
return resolve() or resolve()
1206+
1207+
monkeypatch.setattr(module.rest_smoke, "http_request", fake_http_request)
1208+
monkeypatch.setattr(module.rest_smoke, "compact_http_result", lambda result: {"status": result["status"], "json": result["json"]})
1209+
monkeypatch.setattr(module.live_common, "wait_for", fake_wait_for)
1210+
1211+
result = module.add_and_connect_server(
1212+
"http://127.0.0.1:4711",
1213+
"key",
1214+
address="10.1.2.3",
1215+
port=4661,
1216+
timeout_seconds=2.0,
1217+
)
1218+
1219+
assert result["connect"]["json"]["connecting"] is True
1220+
assert result["connected"]["observations"][-1]["connected"] is True
1221+
assert calls.count(("GET", "/api/v1/status")) == 2
1222+
1223+
11651224
def test_wait_for_completed_file_timeout_carries_diagnostic_observations(tmp_path: Path) -> None:
11661225
module = load_suite_module()
11671226
snapshots = [{"transfer": {"status": 200, "json": {"state": "downloading"}}}]

0 commit comments

Comments
 (0)