Skip to content

Commit

Permalink
IWF-129: Simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
lwolczynski committed Oct 18, 2024
1 parent 3ebeee5 commit a5f926c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
20 changes: 5 additions & 15 deletions integ/wait_until_search_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ func TestWaitUntilSearchAttributesWorkflowTemporal(t *testing.T) {
smallWaitForFastTest()
}

// TODO: Rethink how this can be tested
// for i := 0; i < *repeatIntegTest; i++ {
// doTestWaitUntilSearchAttributes(t, service.BackendTypeTemporal, nil) // defaults to ExecutingStateIdMode: ENABLED_FOR_STATES_WITH_WAIT_UNTIL
// smallWaitForFastTest()
// }
for i := 0; i < *repeatIntegTest; i++ {
doTestWaitUntilSearchAttributes(t, service.BackendTypeTemporal, nil) // defaults to ExecutingStateIdMode: ENABLED_FOR_STATES_WITH_WAIT_UNTIL
smallWaitForFastTest()
}
}

func doTestWaitUntilSearchAttributes(
Expand Down Expand Up @@ -86,21 +85,12 @@ func doTestWaitUntilSearchAttributes(
assertSearch(fmt.Sprintf("WorkflowId='%v' AND %v='%v'", wfId, wait_until_search_attributes.TestSearchAttributeExecutingStateIdsKey, wait_until_search_attributes.State2), 1, apiClient, assertions)
case iwfidl.ENABLED_FOR_STATES_WITH_WAIT_UNTIL:
assertSearch(fmt.Sprintf("WorkflowId='%v'", wfId), 1, apiClient, assertions)
// TODO: Add search attribute assert
assertSearch(fmt.Sprintf("WorkflowId='%v' AND %v='%v'", wfId, wait_until_search_attributes.TestSearchAttributeExecutingStateIdsKey, wait_until_search_attributes.State2), 0, apiClient, assertions)
case iwfidl.DISABLED:
assertSearch(fmt.Sprintf("WorkflowId='%v'", wfId), 1, apiClient, assertions)
assertSearch(fmt.Sprintf("WorkflowId='%v' AND %v='%v'", wfId, wait_until_search_attributes.TestSearchAttributeExecutingStateIdsKey, wait_until_search_attributes.State2), 0, apiClient, assertions)
}

time.Sleep(time.Second * 5) // wait for a few seconds so that timer is ready to be skipped
req3 := apiClient.DefaultApi.ApiV1WorkflowTimerSkipPost(context.Background())
httpResp, err = req3.WorkflowSkipTimerRequest(iwfidl.WorkflowSkipTimerRequest{
WorkflowId: wfId,
WorkflowStateExecutionId: fmt.Sprintf("%v-1", wait_until_search_attributes.State2),
TimerCommandId: iwfidl.PtrString(wait_until_search_attributes.TimerId),
}).Execute()
panicAtHttpError(err, httpResp)

reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
_, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
WorkflowId: wfId,
Expand Down
22 changes: 9 additions & 13 deletions integ/workflow/wait_until_search_attributes/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/indeedeng/iwf/gen/iwfidl"
"github.com/indeedeng/iwf/integ/workflow/common"
"github.com/indeedeng/iwf/service"
"github.com/indeedeng/iwf/service/common/ptr"
"log"
"net/http"
"time"
Expand All @@ -18,14 +17,15 @@ import (
* - Waits on nothing. Will execute momentarily
* - Execute method will go to State2
* State2:
* - Waits for TimerCommand with TimerId to expire
* - Execute method will gracefully complete workflow
* - Waits on nothing. Will execute momentarily
* - Skips wait unit
* - 10-second delay is added before executing state
* - Execute method will gracefully complete workflow
*/
const (
WorkflowType = "wait_until_search_attributes"
State1 = "S1"
State2 = "S2"
TimerId = "test-timer"

TestSearchAttributeExecutingStateIdsKey = "IwfExecutingStateIds"
)
Expand All @@ -41,13 +41,6 @@ func NewHandler() common.WorkflowHandler {
}

func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) {
validTimerCommands := []iwfidl.TimerCommand{
{
CommandId: ptr.Any(TimerId),
FiringUnixTimestampSeconds: iwfidl.PtrInt64(time.Now().Unix() + 86400*365), // one year later
},
}

var req iwfidl.WorkflowStateStartRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
Expand All @@ -68,8 +61,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) {
if req.GetWorkflowStateId() == State2 {
c.JSON(http.StatusOK, iwfidl.WorkflowStateStartResponse{
CommandRequest: &iwfidl.CommandRequest{
TimerCommands: validTimerCommands,
CommandWaitingType: ptr.Any(iwfidl.ANY_COMPLETED),
DeciderTriggerType: iwfidl.ALL_COMMAND_COMPLETED.Ptr(),
},
})
return
Expand All @@ -95,12 +87,16 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) {
NextStates: []iwfidl.StateMovement{
{
StateId: State2,
StateOptions: &iwfidl.WorkflowStateOptions{
SkipWaitUntil: iwfidl.PtrBool(true),
},
},
},
},
})
return
} else if req.GetWorkflowStateId() == State2 {
time.Sleep(time.Second * 10)
c.JSON(http.StatusOK, iwfidl.WorkflowStateDecideResponse{
StateDecision: &iwfidl.StateDecision{
NextStates: []iwfidl.StateMovement{
Expand Down

0 comments on commit a5f926c

Please sign in to comment.