Skip to content

Commit

Permalink
IWF-208: Make test more complex
Browse files Browse the repository at this point in the history
  • Loading branch information
lwolczynski committed Oct 24, 2024
1 parent 13668fb commit f831664
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 27 deletions.
30 changes: 20 additions & 10 deletions integ/wait_until_search_attributes_optimization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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))
}
Expand Down
102 changes: 85 additions & 17 deletions integ/workflow/wait_until_search_attributes_optimization/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -36,10 +43,10 @@ const (
State3 = "S3"
State4 = "S4"
State5 = "S5"
State6 = "S6"
State7 = "S7"

SignalName = "test-signal"

TestSearchAttributeExecutingStateIdsKey = "IwfExecutingStateIds"
)

type handler struct {
Expand Down Expand Up @@ -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{}{})
Expand All @@ -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{
Expand All @@ -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),
},
Expand All @@ -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{
Expand Down

0 comments on commit f831664

Please sign in to comment.