Skip to content

Commit db10086

Browse files
Add PHP version marker replay fixture
Issue: zorporation/durable-workflow#495 Loop-ID: build-01
1 parent 4276a41 commit db10086

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

tests/integration/polyglot_fixtures.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@
1010

1111
from durable_workflow import activity, workflow
1212

13+
PHP_VERSION_MARKER_RECORDED_EVENT = {
14+
"event_type": "VersionMarkerRecorded",
15+
"payload": {
16+
"sequence": 1,
17+
"change_id": "polyglot-version-marker",
18+
"version": 2,
19+
"min_supported": 1,
20+
"max_supported": 2,
21+
},
22+
}
23+
24+
PHP_VERSION_MARKER_EXPECTED_KEYS = [
25+
"sequence",
26+
"change_id",
27+
"version",
28+
"min_supported",
29+
"max_supported",
30+
]
31+
1332

1433
@activity.defn(name="tests.polyglot.python-activity")
1534
async def polyglot_python_activity(input_data: dict) -> dict:
@@ -62,3 +81,15 @@ def run(self, ctx, data: dict): # type: ignore[no-untyped-def]
6281
"result_has_runtime": php_result.get("runtime") == "php" if isinstance(php_result, dict) else False,
6382
},
6483
}
84+
85+
86+
@workflow.defn(name="tests.polyglot.version-marker-python-workflow")
87+
class PolyglotVersionMarkerWorkflow:
88+
"""Python replay fixture for PHP-emitted VersionMarkerRecorded history."""
89+
90+
def run(self, ctx): # type: ignore[no-untyped-def]
91+
version = yield ctx.get_version("polyglot-version-marker", 1, 2)
92+
if version >= 2:
93+
return (yield ctx.schedule_activity("tests.polyglot.version-marker-new-path", []))
94+
95+
return (yield ctx.schedule_activity("tests.polyglot.version-marker-old-path", []))

tests/test_replay.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
WorkflowContext,
2323
replay,
2424
)
25+
from tests.integration.polyglot_fixtures import (
26+
PHP_VERSION_MARKER_EXPECTED_KEYS,
27+
PHP_VERSION_MARKER_RECORDED_EVENT,
28+
PolyglotVersionMarkerWorkflow,
29+
)
2530

2631

2732
@workflow.defn(name="simple-return")
@@ -701,6 +706,25 @@ def test_server_command_defaults(self) -> None:
701706

702707

703708
class TestVersionMarker:
709+
def test_replays_php_emitted_version_marker_wire_fixture(self) -> None:
710+
payload = PHP_VERSION_MARKER_RECORDED_EVENT["payload"]
711+
712+
assert sorted(payload) == sorted(PHP_VERSION_MARKER_EXPECTED_KEYS)
713+
assert payload == {
714+
"sequence": 1,
715+
"change_id": "polyglot-version-marker",
716+
"version": 2,
717+
"min_supported": 1,
718+
"max_supported": 2,
719+
}
720+
721+
outcome = replay(PolyglotVersionMarkerWorkflow, [PHP_VERSION_MARKER_RECORDED_EVENT], [])
722+
723+
assert len(outcome.commands) == 1
724+
cmd = outcome.commands[0]
725+
assert isinstance(cmd, ScheduleActivity)
726+
assert cmd.activity_type == "tests.polyglot.version-marker-new-path"
727+
704728
def test_first_replay_records_marker_and_continues(self) -> None:
705729
outcome = replay(VersionWorkflow, [], [])
706730
assert len(outcome.commands) == 2

0 commit comments

Comments
 (0)