|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import json |
| 4 | +import logging |
4 | 5 | from unittest.mock import AsyncMock, patch |
5 | 6 |
|
6 | 7 | import httpx |
@@ -112,6 +113,59 @@ async def test_action_input_uses_codec_envelope(self, client: Client) -> None: |
112 | 113 | assert action_input["codec"] == "avro" |
113 | 114 | assert serializer.decode(action_input["blob"], codec="avro") == ["Alice", 42] |
114 | 115 |
|
| 116 | + @pytest.mark.asyncio |
| 117 | + async def test_action_input_warning_uses_client_policy( |
| 118 | + self, client: Client, caplog: pytest.LogCaptureFixture |
| 119 | + ) -> None: |
| 120 | + client.payload_size_warning_config = serializer.PayloadSizeWarningConfig( |
| 121 | + limit_bytes=10, |
| 122 | + threshold_percent=50, |
| 123 | + ) |
| 124 | + resp = _mock_response(201, {"schedule_id": "sched-large", "outcome": "created"}) |
| 125 | + with ( |
| 126 | + patch.object(client._http, "request", new_callable=AsyncMock, return_value=resp), |
| 127 | + caplog.at_level(logging.WARNING, logger="durable_workflow.serializer"), |
| 128 | + ): |
| 129 | + await client.create_schedule( |
| 130 | + schedule_id="sched-large", |
| 131 | + spec=ScheduleSpec(cron_expressions=["0 * * * *"]), |
| 132 | + action=ScheduleAction( |
| 133 | + workflow_type="greeter", |
| 134 | + task_queue="q1", |
| 135 | + input=["this payload is intentionally large"], |
| 136 | + ), |
| 137 | + ) |
| 138 | + |
| 139 | + payload = caplog.records[0].durable_workflow_payload |
| 140 | + assert payload["kind"] == "schedule_input" |
| 141 | + assert payload["workflow_type"] == "greeter" |
| 142 | + assert payload["schedule_id"] == "sched-large" |
| 143 | + assert payload["task_queue"] == "q1" |
| 144 | + assert payload["namespace"] == "ns1" |
| 145 | + assert payload["threshold_bytes"] == 5 |
| 146 | + |
| 147 | + @pytest.mark.asyncio |
| 148 | + async def test_action_input_warning_can_be_disabled( |
| 149 | + self, client: Client, caplog: pytest.LogCaptureFixture |
| 150 | + ) -> None: |
| 151 | + client.payload_size_warning_config = None |
| 152 | + resp = _mock_response(201, {"schedule_id": "sched-quiet", "outcome": "created"}) |
| 153 | + with ( |
| 154 | + patch.object(client._http, "request", new_callable=AsyncMock, return_value=resp), |
| 155 | + caplog.at_level(logging.WARNING, logger="durable_workflow.serializer"), |
| 156 | + ): |
| 157 | + await client.create_schedule( |
| 158 | + schedule_id="sched-quiet", |
| 159 | + spec=ScheduleSpec(cron_expressions=["0 * * * *"]), |
| 160 | + action=ScheduleAction( |
| 161 | + workflow_type="greeter", |
| 162 | + task_queue="q1", |
| 163 | + input=["this payload is intentionally large"], |
| 164 | + ), |
| 165 | + ) |
| 166 | + |
| 167 | + assert caplog.records == [] |
| 168 | + |
115 | 169 | @pytest.mark.asyncio |
116 | 170 | async def test_minimal(self, client: Client) -> None: |
117 | 171 | resp = _mock_response(201, {"schedule_id": "auto-id", "outcome": "created"}) |
@@ -255,6 +309,34 @@ async def test_update_note(self, client: Client) -> None: |
255 | 309 | body = mock.call_args.kwargs.get("json") or mock.call_args[1].get("json") |
256 | 310 | assert body["note"] == "Updated note" |
257 | 311 |
|
| 312 | + @pytest.mark.asyncio |
| 313 | + async def test_update_action_input_warning_uses_schedule_id( |
| 314 | + self, client: Client, caplog: pytest.LogCaptureFixture |
| 315 | + ) -> None: |
| 316 | + client.payload_size_warning_config = serializer.PayloadSizeWarningConfig( |
| 317 | + limit_bytes=10, |
| 318 | + threshold_percent=50, |
| 319 | + ) |
| 320 | + resp = _mock_response(200, {"schedule_id": "sched-1", "outcome": "updated"}) |
| 321 | + with ( |
| 322 | + patch.object(client._http, "request", new_callable=AsyncMock, return_value=resp), |
| 323 | + caplog.at_level(logging.WARNING, logger="durable_workflow.serializer"), |
| 324 | + ): |
| 325 | + await client.update_schedule( |
| 326 | + "sched-1", |
| 327 | + action=ScheduleAction( |
| 328 | + workflow_type="ticker", |
| 329 | + task_queue="q2", |
| 330 | + input=["this update payload is intentionally large"], |
| 331 | + ), |
| 332 | + ) |
| 333 | + |
| 334 | + payload = caplog.records[0].durable_workflow_payload |
| 335 | + assert payload["kind"] == "schedule_input" |
| 336 | + assert payload["workflow_type"] == "ticker" |
| 337 | + assert payload["schedule_id"] == "sched-1" |
| 338 | + assert payload["task_queue"] == "q2" |
| 339 | + |
258 | 340 | @pytest.mark.asyncio |
259 | 341 | async def test_not_found(self, client: Client) -> None: |
260 | 342 | resp = _mock_response(404, {"reason": "schedule_not_found", "message": "not found"}) |
|
0 commit comments