From f831664ffac12026eb9b4e8327dcfe2bb13e5ef0 Mon Sep 17 00:00:00 2001 From: lwolczynski Date: Wed, 23 Oct 2024 21:08:47 -0500 Subject: [PATCH] IWF-208: Make test more complex --- ...til_search_attributes_optimization_test.go | 30 ++++-- .../routers.go | 102 +++++++++++++++--- 2 files changed, 105 insertions(+), 27 deletions(-) diff --git a/integ/wait_until_search_attributes_optimization_test.go b/integ/wait_until_search_attributes_optimization_test.go index 1eafc009..3c2921e5 100644 --- a/integ/wait_until_search_attributes_optimization_test.go +++ b/integ/wait_until_search_attributes_optimization_test.go @@ -69,7 +69,7 @@ func doTestWaitUntilHistoryCompleted( wfReq := iwfidl.WorkflowStartRequest{ WorkflowId: wfId, IwfWorkflowType: wait_until_search_attributes_optimization.WorkflowType, - WorkflowTimeoutSeconds: 10, + WorkflowTimeoutSeconds: 15, IwfWorkerUrl: "http://localhost:" + testWorkflowServerPort, StartStateId: ptr.Any(wait_until_search_attributes_optimization.State1), WorkflowStartOptions: &iwfidl.WorkflowStartOptions{ @@ -129,20 +129,30 @@ func doTestWaitUntilHistoryCompleted( switch mode := config.GetExecutingStateIdMode(); mode { case iwfidl.ENABLED_FOR_ALL: - assertions.Equal(6, len(upsertSAEvents)) + assertions.Equal(10, len(upsertSAEvents)) assertions.Equal("[\"S1\"]", historyEventSAs(upsertSAEvents[0])) assertions.Equal("[\"S2\"]", historyEventSAs(upsertSAEvents[1])) - assertions.Equal("[\"S3\",\"S4\"]", historyEventSAs(upsertSAEvents[2])) - assertions.Equal("[\"S4\"]", historyEventSAs(upsertSAEvents[3])) - assertions.Equal("[\"S5\"]", historyEventSAs(upsertSAEvents[4])) - assertions.Equal("null", historyEventSAs(upsertSAEvents[5])) + assertions.Equal("[\"S2\",\"S3\"]", historyEventSAs(upsertSAEvents[2])) + assertions.Equal("[\"S4\",\"S3\"]", historyEventSAs(upsertSAEvents[3])) + assertions.Equal("[\"S5\",\"S3\"]", historyEventSAs(upsertSAEvents[4])) + assertions.Equal("[\"S6\",\"S3\",\"S7\"]", historyEventSAs(upsertSAEvents[5])) + assertions.Equal("[\"S6\",\"S3\"]", historyEventSAs(upsertSAEvents[6])) + // TODO: This is unexpected; should not upsert the same SAs -- happens after "_SYS_GRACEFUL_COMPLETING_WORKFLOW" + assertions.Equal("[\"S3\"]", historyEventSAs(upsertSAEvents[7])) + assertions.Equal("[\"S3\"]", historyEventSAs(upsertSAEvents[8])) + assertions.Equal("null", historyEventSAs(upsertSAEvents[9])) case iwfidl.ENABLED_FOR_STATES_WITH_WAIT_UNTIL: - assertions.Equal(5, len(upsertSAEvents)) + assertions.Equal(9, len(upsertSAEvents)) assertions.Equal("[\"S1\"]", historyEventSAs(upsertSAEvents[0])) assertions.Equal("[\"S2\"]", historyEventSAs(upsertSAEvents[1])) - assertions.Equal("[\"S3\",\"S4\"]", historyEventSAs(upsertSAEvents[2])) - assertions.Equal("[\"S4\"]", historyEventSAs(upsertSAEvents[3])) - assertions.Equal("null", historyEventSAs(upsertSAEvents[4])) + assertions.Equal("[\"S2\",\"S3\"]", historyEventSAs(upsertSAEvents[2])) + assertions.Equal("[\"S4\",\"S3\"]", historyEventSAs(upsertSAEvents[3])) + assertions.Equal("[\"S3\"]", historyEventSAs(upsertSAEvents[4])) + assertions.Equal("[\"S6\",\"S3\"]", historyEventSAs(upsertSAEvents[5])) + // TODO: This is unexpected; should not upsert the same SAs -- happens after "_SYS_GRACEFUL_COMPLETING_WORKFLOW" + assertions.Equal("[\"S3\"]", historyEventSAs(upsertSAEvents[6])) + assertions.Equal("[\"S3\"]", historyEventSAs(upsertSAEvents[7])) + assertions.Equal("null", historyEventSAs(upsertSAEvents[8])) case iwfidl.DISABLED: assertions.Equal(0, len(upsertSAEvents)) } diff --git a/integ/workflow/wait_until_search_attributes_optimization/routers.go b/integ/workflow/wait_until_search_attributes_optimization/routers.go index 9e384ffc..4269baf1 100644 --- a/integ/workflow/wait_until_search_attributes_optimization/routers.go +++ b/integ/workflow/wait_until_search_attributes_optimization/routers.go @@ -15,18 +15,25 @@ import ( * This test workflow has 5 states, using REST controller to implement the workflow directly. * * State1: - * - Waits on nothing. Will execute momentarily - * - Executes method will loop back to State1 five times then execute method will go to State2 + * - Waits one second before executing + * - Execute method will loop back to State1 five times; then execute method will go to State2 * State2: - * - Waits 5 seconds - * - Execute method will go to State3 and State4 + * - First execution: loops back to State2 + goes to State3 + * - Second execution (after 1 second): goes to State3 and State4 * State3: - * - Does nothing + * - Waits 8 seconds + * - Execute method will gracefully complete workflow * State4: * - Waits on command trigger * - Execute method will go to State5 * State5: * - Skips waitUntil and executes momentarily + * - Execute method will go to State6 and State7 + * State6: + * - Waits 4 seconds + * - Execute method will gracefully complete workflow + * State7: + * - Skips waitUntil and executes momentarily * - Execute method will gracefully complete workflow */ const ( @@ -36,10 +43,10 @@ const ( State3 = "S3" State4 = "S4" State5 = "S5" + State6 = "S6" + State7 = "S7" SignalName = "test-signal" - - TestSearchAttributeExecutingStateIdsKey = "IwfExecutingStateIds" ) type handler struct { @@ -108,6 +115,22 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { }) return } + if req.GetWorkflowStateId() == State6 { + c.JSON(http.StatusOK, iwfidl.WorkflowStateStartResponse{ + CommandRequest: &iwfidl.CommandRequest{ + DeciderTriggerType: iwfidl.ALL_COMMAND_COMPLETED.Ptr(), + }, + }) + return + } + if req.GetWorkflowStateId() == State7 { + c.JSON(http.StatusOK, iwfidl.WorkflowStateStartResponse{ + CommandRequest: &iwfidl.CommandRequest{ + DeciderTriggerType: iwfidl.ALL_COMMAND_COMPLETED.Ptr(), + }, + }) + return + } } c.JSON(http.StatusBadRequest, struct{}{}) @@ -124,7 +147,6 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { if req.GetWorkflowType() == WorkflowType { h.invokeHistory[req.GetWorkflowStateId()+"_decide"]++ if req.GetWorkflowStateId() == State1 { - context := req.GetContext() if context.GetStateExecutionId() == "S1-5" { c.JSON(http.StatusOK, iwfidl.WorkflowStateDecideResponse{ @@ -150,36 +172,70 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { } return } else if req.GetWorkflowStateId() == State2 { + context := req.GetContext() + if context.GetStateExecutionId() == "S2-2" { + c.JSON(http.StatusOK, iwfidl.WorkflowStateDecideResponse{ + StateDecision: &iwfidl.StateDecision{ + NextStates: []iwfidl.StateMovement{ + { + StateId: State3, + }, + { + StateId: State4, + }, + }, + }, + }) + } else { + c.JSON(http.StatusOK, iwfidl.WorkflowStateDecideResponse{ + StateDecision: &iwfidl.StateDecision{ + NextStates: []iwfidl.StateMovement{ + { + StateId: State2, + }, + { + StateId: State3, + }, + }, + }, + }) + } + return + } else if req.GetWorkflowStateId() == State3 { + time.Sleep(time.Second * 8) c.JSON(http.StatusOK, iwfidl.WorkflowStateDecideResponse{ StateDecision: &iwfidl.StateDecision{ NextStates: []iwfidl.StateMovement{ { - StateId: State3, - }, - { - StateId: State4, + StateId: service.GracefulCompletingWorkflowStateId, }, }, }, }) return - } else if req.GetWorkflowStateId() == State3 { + } else if req.GetWorkflowStateId() == State4 { c.JSON(http.StatusOK, iwfidl.WorkflowStateDecideResponse{ StateDecision: &iwfidl.StateDecision{ NextStates: []iwfidl.StateMovement{ { - StateId: service.DeadEndWorkflowStateId, + StateId: State5, + StateOptions: &iwfidl.WorkflowStateOptions{ + SkipWaitUntil: iwfidl.PtrBool(true), + }, }, }, }, }) return - } else if req.GetWorkflowStateId() == State4 { + } else if req.GetWorkflowStateId() == State5 { c.JSON(http.StatusOK, iwfidl.WorkflowStateDecideResponse{ StateDecision: &iwfidl.StateDecision{ NextStates: []iwfidl.StateMovement{ { - StateId: State5, + StateId: State6, + }, + { + StateId: State7, StateOptions: &iwfidl.WorkflowStateOptions{ SkipWaitUntil: iwfidl.PtrBool(true), }, @@ -188,7 +244,19 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { }, }) return - } else if req.GetWorkflowStateId() == State5 { + } else if req.GetWorkflowStateId() == State6 { + time.Sleep(time.Second * 4) + c.JSON(http.StatusOK, iwfidl.WorkflowStateDecideResponse{ + StateDecision: &iwfidl.StateDecision{ + NextStates: []iwfidl.StateMovement{ + { + StateId: service.GracefulCompletingWorkflowStateId, + }, + }, + }, + }) + return + } else if req.GetWorkflowStateId() == State7 { c.JSON(http.StatusOK, iwfidl.WorkflowStateDecideResponse{ StateDecision: &iwfidl.StateDecision{ NextStates: []iwfidl.StateMovement{