Skip to content

Commit a878297

Browse files
committed
Create nexus endpoint before creating the worker. Fix up buffered metrics test to properly assert both counter updates
1 parent 2ff6063 commit a878297

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tests/worker/test_workflow.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3994,14 +3994,16 @@ async def run(self, task_queue: str) -> None:
39943994
async def test_workflow_custom_metrics(client: Client):
39953995
# Run worker with default runtime which is noop meter just to confirm it
39963996
# doesn't fail
3997+
task_queue = str(uuid.uuid4())
3998+
await create_nexus_endpoint(task_queue, client)
39973999
async with new_worker(
39984000
client,
39994001
CustomMetricsWorkflow,
4002+
task_queue=task_queue,
40004003
activities=[custom_metrics_activity],
40014004
nexus_service_handlers=[CustomMetricsService()],
40024005
nexus_task_executor=concurrent.futures.ThreadPoolExecutor(),
40034006
) as worker:
4004-
await create_nexus_endpoint(worker.task_queue, client)
40054007
await client.execute_workflow(
40064008
CustomMetricsWorkflow.run,
40074009
worker.task_queue,
@@ -4032,12 +4034,11 @@ async def test_workflow_custom_metrics(client: Client):
40324034
async with new_worker(
40334035
client,
40344036
CustomMetricsWorkflow,
4037+
task_queue=task_queue,
40354038
activities=[custom_metrics_activity],
40364039
nexus_service_handlers=[CustomMetricsService()],
40374040
nexus_task_executor=concurrent.futures.ThreadPoolExecutor(),
40384041
) as worker:
4039-
await create_nexus_endpoint(worker.task_queue, client)
4040-
40414042
# Record a gauge at runtime level
40424043
gauge = runtime.metric_meter.with_additional_attributes(
40434044
{"my-runtime-extra-attr1": "val1", "my-runtime-extra-attr2": True}
@@ -4219,14 +4220,16 @@ async def test_workflow_buffered_metrics(client: Client):
42194220
namespace=client.namespace,
42204221
runtime=runtime,
42214222
)
4223+
task_queue = str(uuid.uuid4())
4224+
await create_nexus_endpoint(task_queue, client)
42224225
async with new_worker(
42234226
client,
42244227
CustomMetricsWorkflow,
4228+
task_queue=task_queue,
42254229
activities=[custom_metrics_activity],
42264230
nexus_service_handlers=[CustomMetricsService()],
42274231
nexus_task_executor=concurrent.futures.ThreadPoolExecutor(),
42284232
) as worker:
4229-
await create_nexus_endpoint(worker.task_queue, client)
42304233
await client.execute_workflow(
42314234
CustomMetricsWorkflow.run,
42324235
worker.task_queue,
@@ -4290,19 +4293,31 @@ async def test_workflow_buffered_metrics(client: Client):
42904293
and update.attributes["nexus_operation"]
42914294
== CustomMetricsService.custom_metric_op.__name__
42924295
and update.attributes["task_queue"] == worker.task_queue
4293-
# and update.attributes["my-operation-extra-attr"] == "12.34"
4296+
and "my-operation-extra-attr" not in update.attributes
4297+
and update.value == 12
4298+
for update in updates
4299+
)
4300+
assert any(
4301+
update.metric.name == "my-operation-counter"
4302+
and update.attributes.get("my-operation-extra-attr") == 12.34
42944303
and update.value == 30
42954304
for update in updates
42964305
)
42974306
assert any(
42984307
update.metric.name == "my-executor-operation-counter"
42994308
and update.metric.description == "my-executor-operation-description"
43004309
and update.metric.kind == BUFFERED_METRIC_KIND_COUNTER
4301-
# and update.attributes["my_operation_extra_attr"] == "12.34"
43024310
and update.attributes["nexus_service"] == CustomMetricsService.__name__
43034311
and update.attributes["nexus_operation"]
43044312
== CustomMetricsService.custom_metric_op_executor.__name__
43054313
and update.attributes["task_queue"] == worker.task_queue
4314+
and "my-executor-operation-extra-attr" not in update.attributes
4315+
and update.value == 12
4316+
for update in updates
4317+
)
4318+
assert any(
4319+
update.metric.name == "my-executor-operation-counter"
4320+
and update.attributes.get("my-executor-operation-extra-attr") == 12.34
43064321
and update.value == 30
43074322
for update in updates
43084323
)

0 commit comments

Comments
 (0)