Skip to content

Commit 5ca7fc6

Browse files
author
Nathan Givens
committed
IWF-921 ensure backward compatibility with binary/null encoding
1 parent 649658d commit 5ca7fc6

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed

iwf/tests/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
from iwf.registry import Registry
2-
from iwf.tests.workflows.java_duplicate_rpc_memo_workflow import (
3-
JavaDuplicateRpcMemoWorkflow,
4-
)
52
from iwf.tests.workflows.abnormal_exit_workflow import AbnormalExitWorkflow
63
from iwf.tests.workflows.basic_workflow import BasicWorkflow
74
from iwf.tests.workflows.conditional_complete_workflow import (
85
ConditionalCompleteWorkflow,
96
)
107
from iwf.tests.workflows.describe_workflow import DescribeWorkflow
8+
from iwf.tests.workflows.empty_data_workflow import EmptyDataWorkflow
119
from iwf.tests.workflows.internal_channel_workflow import InternalChannelWorkflow
1210
from iwf.tests.workflows.internal_channel_workflow_with_no_prefix_channel import (
1311
InternalChannelWorkflowWithNoPrefixChannel,
1412
)
13+
from iwf.tests.workflows.java_duplicate_rpc_memo_workflow import (
14+
JavaDuplicateRpcMemoWorkflow,
15+
)
1516
from iwf.tests.workflows.persistence_data_attributes_workflow import (
1617
PersistenceDataAttributesWorkflow,
1718
)
@@ -45,6 +46,7 @@
4546
registry.add_workflow(BasicWorkflow())
4647
registry.add_workflow(ConditionalCompleteWorkflow())
4748
registry.add_workflow(DescribeWorkflow())
49+
registry.add_workflow(EmptyDataWorkflow())
4850
registry.add_workflow(InternalChannelWorkflow())
4951
registry.add_workflow(InternalChannelWorkflowWithNoPrefixChannel())
5052
registry.add_workflow(JavaDuplicateRpcMemoWorkflow())
@@ -54,8 +56,8 @@
5456
registry.add_workflow(RecoveryWorkflow())
5557
registry.add_workflow(RpcMemoWorkflow())
5658
registry.add_workflow(RPCWorkflow())
57-
registry.add_workflow(TimerWorkflow())
5859
registry.add_workflow(StateOptionsOverrideWorkflow())
60+
registry.add_workflow(TimerWorkflow())
5961
registry.add_workflow(WaitForStateWithStateExecutionIdWorkflow())
6062
registry.add_workflow(WaitForStateWithWaitForKeyWorkflow())
6163
registry.add_workflow(WaitInternalChannelWorkflow())
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import inspect
2+
import time
3+
import unittest
4+
5+
import httpx
6+
7+
from iwf.client import Client
8+
from iwf.tests.worker_server import registry
9+
from iwf.worker_service import WorkerService
10+
11+
12+
class TestBinaryNullDecodesCorrectly(unittest.TestCase):
13+
@classmethod
14+
def setUpClass(cls):
15+
cls.client = Client(registry)
16+
17+
def test_binary_null_input_decodes_correctly(self):
18+
wf_id = f"{inspect.currentframe().f_code.co_name}-{time.time_ns()}"
19+
20+
response = httpx.post(
21+
f"http://0.0.0.0:8802/{WorkerService.api_path_workflow_state_execute}",
22+
json={
23+
"DataObjects": [
24+
{"key": "test-da", "value": {"encoding": "binary/null"}}
25+
],
26+
"commandResults": {
27+
"interStateChannelResults": [],
28+
"stateStartApiSucceeded": True,
29+
},
30+
"context": {
31+
"attempt": 1,
32+
"firstAttemptTimestamp": 1747935829,
33+
"stateExecutionId": "State1-1",
34+
"workflowId": wf_id,
35+
"workflowRunId": "0196f734-d037-7432-bd63-e1136cd34dbd",
36+
"workflowStartedTimestamp": 1747904155,
37+
},
38+
"stateInput": {"encoding": "binary/null"},
39+
"stateLocals": [],
40+
"workflowStateId": "State1",
41+
"workflowType": "EmptyDataWorkflow",
42+
},
43+
)
44+
assert response.is_success
45+
response_json = response.json()
46+
self.assertEqual(
47+
response_json,
48+
{
49+
"publishToInterStateChannel": [],
50+
"recordEvents": [],
51+
"stateDecision": {
52+
"nextStates": [
53+
{
54+
"stateId": "_SYS_GRACEFUL_COMPLETING_WORKFLOW",
55+
"stateInput": {
56+
"data": '"success"',
57+
"encoding": "json/plain",
58+
},
59+
}
60+
]
61+
},
62+
"upsertDataObjects": [],
63+
"upsertStateLocals": [],
64+
},
65+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from iwf.command_results import CommandResults
2+
from iwf.communication import Communication
3+
from iwf.persistence import Persistence
4+
from iwf.persistence_schema import PersistenceField, PersistenceSchema
5+
from iwf.state_decision import StateDecision
6+
from iwf.state_schema import StateSchema
7+
from iwf.workflow import ObjectWorkflow
8+
from iwf.workflow_context import WorkflowContext
9+
from iwf.workflow_state import WorkflowState
10+
11+
TEST_DA_KEY = "test-da"
12+
13+
14+
class State1(WorkflowState[None]):
15+
def execute(
16+
self,
17+
ctx: WorkflowContext,
18+
input: None,
19+
command_results: CommandResults,
20+
persistence: Persistence,
21+
communication: Communication,
22+
) -> StateDecision:
23+
assert input is None
24+
test_da = persistence.get_data_attribute(TEST_DA_KEY)
25+
assert test_da is None
26+
27+
return StateDecision.graceful_complete_workflow(output="success")
28+
29+
30+
class EmptyDataWorkflow(ObjectWorkflow):
31+
def get_workflow_states(self) -> StateSchema:
32+
return StateSchema.with_starting_state(State1())
33+
34+
def get_persistence_schema(self) -> PersistenceSchema:
35+
return PersistenceSchema.create(
36+
PersistenceField.data_attribute_def(TEST_DA_KEY, None),
37+
)

0 commit comments

Comments
 (0)