diff --git a/features/data_converter/binary/README.md b/features/data_converter/binary/README.md index e02773e7..6830f685 100644 --- a/features/data_converter/binary/README.md +++ b/features/data_converter/binary/README.md @@ -4,10 +4,13 @@ Binary values can be converted to and from `binary/plain` Payloads. Steps: -- run a workflow that returns binary value `0xdeadbeef` +- run a echo workflow that accepts and returns binary value `0xdeadbeef` - verify client result is binary `0xdeadbeef` - get result payload of WorkflowExecutionCompleted event from workflow history - load JSON payload from `./payload.json` and compare it to result payload +- get argument payload of WorkflowExecutionStarted event from workflow history +- verify that argument and result payloads are the same + # Detailed spec diff --git a/features/data_converter/binary/feature.go b/features/data_converter/binary/feature.go index c00cdb47..a4ced788 100644 --- a/features/data_converter/binary/feature.go +++ b/features/data_converter/binary/feature.go @@ -19,11 +19,13 @@ var expectedResult = []byte{0xde, 0xad, 0xbe, 0xef} var Feature = harness.Feature{ Workflows: Workflow, CheckResult: CheckResult, + // ExecuteDefault does not support workflow arguments + Execute: harness.ExecuteWithArgs(Workflow, expectedResult), } -// run a workflow that returns binary value `0xdeadbeef` -func Workflow(ctx workflow.Context) ([]byte, error) { - return expectedResult, nil +// run an echo workflow that returns binary value `0xdeadbeef` +func Workflow(ctx workflow.Context, res []byte) ([]byte, error) { + return res, nil } func CheckResult(ctx context.Context, runner *harness.Runner, run client.WorkflowRun) error { @@ -54,5 +56,13 @@ func CheckResult(ctx context.Context, runner *harness.Runner, run client.Workflo return err } runner.Require.Equal(expectedPayload, payload) + + payloadArg, err := harness.GetWorkflowArgumentPayload(ctx, runner.Client, run.GetID()) + if err != nil { + return err + } + + runner.Require.Equal(payload, payloadArg) + return nil } diff --git a/features/data_converter/binary/feature.java b/features/data_converter/binary/feature.java index f6a57c0d..8636d965 100644 --- a/features/data_converter/binary/feature.java +++ b/features/data_converter/binary/feature.java @@ -18,13 +18,18 @@ public interface feature extends Feature { byte[] DEAD_BEEF = new byte[] {(byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef}; @WorkflowMethod - byte[] workflow(); + byte[] workflow(byte[] res); class Impl implements feature { - /** run a workflow that returns binary value `0xdeadbeef` */ + /** run an echo workflow that returns binary value `0xdeadbeef` */ @Override - public byte[] workflow() { - return DEAD_BEEF; + public byte[] workflow(byte[] res) { + return res; + } + + @Override + public Run execute(Runner runner) throws Exception { + return runner.executeSingleWorkflow(null, DEAD_BEEF); } @Override @@ -50,6 +55,9 @@ public void checkResult(Runner runner, Run run) throws Exception { JsonFormat.parser().merge(new String(content), builder); var expected = builder.build(); assertEquals(expected, payload); + + var payloadArg = runner.getWorkflowArgumentPayload(run); + assertEquals(payload, payloadArg); } } } diff --git a/features/data_converter/binary/feature.py b/features/data_converter/binary/feature.py index 34189fe2..c61979ac 100644 --- a/features/data_converter/binary/feature.py +++ b/features/data_converter/binary/feature.py @@ -3,10 +3,16 @@ from google.protobuf.json_format import Parse from temporalio import workflow from temporalio.api.common.v1 import Payload -from temporalio.api.enums.v1 import EventType from temporalio.client import WorkflowHandle -from harness.python.feature import Runner, register_feature +from harness.python.feature import ( + Runner, + get_workflow_argument_payload, + get_workflow_result_payload, + register_feature, +) + +EXPECTED_RESULT = bytes.fromhex("deadbeef") @workflow.defn @@ -16,22 +22,17 @@ class Workflow: """ @workflow.run - async def run(self) -> bytes: - return bytes.fromhex("deadbeef") + async def run(self, res: bytes) -> bytes: + return res async def check_result(runner: Runner, handle: WorkflowHandle) -> None: # verify client result is binary `0xdeadbeef` result = await handle.result() - assert result == bytes.fromhex("deadbeef") + assert result == EXPECTED_RESULT # get result payload of WorkflowExecutionCompleted event from workflow history - event = await anext( - e - async for e in handle.fetch_history_events() - if e.event_type == EventType.EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED - ) - payload = event.workflow_execution_completed_event_attributes.result.payloads[0] + payload = await get_workflow_result_payload(handle) # load JSON payload from `./payload.json` and compare it to JSON representation of result payload with open( @@ -41,8 +42,12 @@ async def check_result(runner: Runner, handle: WorkflowHandle) -> None: expected_payload = Parse(f.read(), Payload()) assert payload == expected_payload + payload_arg = await get_workflow_argument_payload(handle) + assert payload == payload_arg + register_feature( workflows=[Workflow], check_result=check_result, + start_options={"arg": EXPECTED_RESULT}, ) diff --git a/features/data_converter/binary/feature.ts b/features/data_converter/binary/feature.ts index ffe87b2a..9323c178 100644 --- a/features/data_converter/binary/feature.ts +++ b/features/data_converter/binary/feature.ts @@ -5,13 +5,16 @@ import expectedPayload from './payload.json'; const deadbeef = new Uint8Array([0xde, 0xad, 0xbe, 0xef]); -// run a workflow that returns binary value `0xdeadbeef` -export async function workflow(): Promise { - return deadbeef; +// run an echo workflow that returns binary value `0xdeadbeef` +export async function workflow(res: Uint8Array): Promise { + return res; } export const feature = new Feature({ workflow, + workflowStartOptions: { + args: [deadbeef], + }, async checkResult(runner, handle) { // verify client result is binary `0xdeadbeef` const result = await handle.result(); @@ -23,5 +26,10 @@ export const feature = new Feature({ // load JSON payload from `./payload.json` and compare it to result payload assert.deepEqual(JSONToPayload(expectedPayload), payload); + + const payloadArg = await runner.getWorkflowArgumentPayload(handle); + assert.ok(payloadArg); + + assert.deepEqual(payload, payloadArg); }, });