Skip to content

Commit 1413f53

Browse files
committed
Compute host more correctly in nexus utility
1 parent 5ef603c commit 1413f53

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/helpers/nexus.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dataclasses
22
from dataclasses import dataclass
33
from typing import Any, Mapping, Optional
4+
from urllib.parse import urlparse
45

56
import temporalio.api.failure.v1
67
import temporalio.api.nexus.v1
@@ -59,7 +60,7 @@ async def start_operation(
5960
# TODO(nexus-preview): Support callback URL as query param
6061
async with httpx.AsyncClient() as http_client:
6162
return await http_client.post(
62-
f"{self.server_address}/nexus/endpoints/{self.endpoint}/services/{self.service}/{operation}",
63+
f"http://{self.server_address}/nexus/endpoints/{self.endpoint}/services/{self.service}/{operation}",
6364
json=body,
6465
headers=headers,
6566
)
@@ -71,7 +72,7 @@ async def cancel_operation(
7172
) -> httpx.Response:
7273
async with httpx.AsyncClient() as http_client:
7374
return await http_client.post(
74-
f"{self.server_address}/nexus/endpoints/{self.endpoint}/services/{self.service}/{operation}/cancel",
75+
f"http://{self.server_address}/nexus/endpoints/{self.endpoint}/services/{self.service}/{operation}/cancel",
7576
# Token can also be sent as "Nexus-Operation-Token" header
7677
params={"token": token},
7778
)
@@ -80,8 +81,10 @@ async def cancel_operation(
8081
def default_server_address(env: WorkflowEnvironment) -> str:
8182
# TODO(nexus-preview): nexus tests are making http requests directly but this is
8283
# not officially supported.
84+
parsed = urlparse(env.client.service_client.config.target_host)
85+
host = parsed.hostname or "127.0.0.1"
8386
http_port = getattr(env, "_http_port", 7243)
84-
return f"http://127.0.0.1:{http_port}"
87+
return f"{host}:{http_port}"
8588

8689

8790
def dataclass_as_dict(dataclass: Any) -> dict[str, Any]:

0 commit comments

Comments
 (0)