|
| 1 | +package integ |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "github.com/indeedeng/iwf/gen/iwfidl" |
| 6 | + "github.com/indeedeng/iwf/integ/workflow/reset" |
| 7 | + "github.com/indeedeng/iwf/service" |
| 8 | + "github.com/indeedeng/iwf/service/common/ptr" |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + "strconv" |
| 11 | + "testing" |
| 12 | + "time" |
| 13 | +) |
| 14 | + |
| 15 | +func TestResetByStateIdWorkflowTemporal(t *testing.T) { |
| 16 | + if !*temporalIntegTest { |
| 17 | + t.Skip() |
| 18 | + } |
| 19 | + for i := 0; i < *repeatIntegTest; i++ { |
| 20 | + doTestResetByStatIdWorkflow(t, service.BackendTypeTemporal, nil) |
| 21 | + smallWaitForFastTest() |
| 22 | + |
| 23 | + //TODO: uncomment below when IWF-403 implementation is done. |
| 24 | + //TODO cont.: Reset with state id & state execution id is broken for local activities. |
| 25 | + //doTestResetByStatIdWorkflow(t, service.BackendTypeTemporal, minimumContinueAsNewConfig(true)) |
| 26 | + //smallWaitForFastTest() |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func TestResetByStateIdWorkflowCadence(t *testing.T) { |
| 31 | + if !*cadenceIntegTest { |
| 32 | + t.Skip() |
| 33 | + } |
| 34 | + for i := 0; i < *repeatIntegTest; i++ { |
| 35 | + doTestResetByStatIdWorkflow(t, service.BackendTypeCadence, nil) |
| 36 | + smallWaitForFastTest() |
| 37 | + |
| 38 | + //TODO: uncomment below when IWF-403 implementation is done. |
| 39 | + //TODO cont.: Reset with state id & state execution id is broken for local activities. |
| 40 | + //doTestResetByStatIdWorkflow(t, service.BackendTypeCadence, minimumContinueAsNewConfig(false)) |
| 41 | + //smallWaitForFastTest() |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +func doTestResetByStatIdWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { |
| 46 | + // start test workflow server |
| 47 | + wfHandler := reset.NewHandler() |
| 48 | + closeFunc1 := startWorkflowWorker(wfHandler) |
| 49 | + defer closeFunc1() |
| 50 | + |
| 51 | + _, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ |
| 52 | + BackendType: backendType, |
| 53 | + }) |
| 54 | + defer closeFunc2() |
| 55 | + |
| 56 | + // start a workflow |
| 57 | + apiClient := iwfidl.NewAPIClient(&iwfidl.Configuration{ |
| 58 | + Servers: []iwfidl.ServerConfiguration{ |
| 59 | + { |
| 60 | + URL: "http://localhost:" + testIwfServerPort, |
| 61 | + }, |
| 62 | + }, |
| 63 | + }) |
| 64 | + wfId := reset.WorkflowType + strconv.Itoa(int(time.Now().UnixNano())) |
| 65 | + wfInput := &iwfidl.EncodedObject{ |
| 66 | + Encoding: iwfidl.PtrString("json"), |
| 67 | + Data: iwfidl.PtrString("1"), |
| 68 | + } |
| 69 | + req := apiClient.DefaultApi.ApiV1WorkflowStartPost(context.Background()) |
| 70 | + startReq := iwfidl.WorkflowStartRequest{ |
| 71 | + WorkflowId: wfId, |
| 72 | + IwfWorkflowType: reset.WorkflowType, |
| 73 | + WorkflowTimeoutSeconds: 100, |
| 74 | + IwfWorkerUrl: "http://localhost:" + testWorkflowServerPort, |
| 75 | + StartStateId: ptr.Any(reset.State1), |
| 76 | + StateInput: wfInput, |
| 77 | + WorkflowStartOptions: &iwfidl.WorkflowStartOptions{ |
| 78 | + WorkflowConfigOverride: config, |
| 79 | + WorkflowIDReusePolicy: ptr.Any(iwfidl.REJECT_DUPLICATE), |
| 80 | + }, |
| 81 | + StateOptions: &iwfidl.WorkflowStateOptions{ |
| 82 | + //Skipping wait until for state1 |
| 83 | + SkipWaitUntil: iwfidl.PtrBool(true), |
| 84 | + }, |
| 85 | + } |
| 86 | + startResp, httpResp, err := req.WorkflowStartRequest(startReq).Execute() |
| 87 | + panicAtHttpError(err, httpResp) |
| 88 | + |
| 89 | + assertions := assert.New(t) |
| 90 | + |
| 91 | + req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) |
| 92 | + resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ |
| 93 | + WorkflowId: wfId, |
| 94 | + }).Execute() |
| 95 | + panicAtHttpError(err, httpResp) |
| 96 | + |
| 97 | + history, _ := wfHandler.GetTestResult() |
| 98 | + //expect no starts in history as WaitUntil api is skipped. |
| 99 | + assertions.Equalf(map[string]int64{ |
| 100 | + "S1_decide": 1, |
| 101 | + "S2_decide": 5, |
| 102 | + }, history, "reset test fail, %v", history) |
| 103 | + |
| 104 | + assertions.Equal(iwfidl.COMPLETED, resp2.GetWorkflowStatus()) |
| 105 | + assertions.Equal(1, len(resp2.GetResults())) |
| 106 | + assertions.Equal("S2", resp2.GetResults()[0].CompletedStateId) |
| 107 | + assertions.Equal("S2-5", resp2.GetResults()[0].CompletedStateExecutionId) |
| 108 | + assertions.Equal("5", resp2.GetResults()[0].CompletedStateOutput.GetData()) |
| 109 | + |
| 110 | + //reset workflow by state id |
| 111 | + resetReq := apiClient.DefaultApi.ApiV1WorkflowResetPost(context.Background()) |
| 112 | + _, httpResp, err = resetReq.WorkflowResetRequest(iwfidl.WorkflowResetRequest{ |
| 113 | + WorkflowRunId: iwfidl.PtrString(startResp.GetWorkflowRunId()), |
| 114 | + WorkflowId: wfId, |
| 115 | + ResetType: iwfidl.STATE_ID, |
| 116 | + StateId: iwfidl.PtrString(reset.State2), |
| 117 | + }).Execute() |
| 118 | + panicAtHttpError(err, httpResp) |
| 119 | + |
| 120 | + req3 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) |
| 121 | + resp3, httpResp, err := req3.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ |
| 122 | + WorkflowId: wfId, |
| 123 | + }).Execute() |
| 124 | + panicAtHttpError(err, httpResp) |
| 125 | + |
| 126 | + resetHistory, _ := wfHandler.GetTestResult() |
| 127 | + //expect no starts in history as WaitUntil api is skipped. |
| 128 | + assertions.Equalf(map[string]int64{ |
| 129 | + "S1_decide": 1, |
| 130 | + "S2_decide": 10, |
| 131 | + }, resetHistory, "reset test fail, %v", resetHistory) |
| 132 | + |
| 133 | + assertions.Equal(iwfidl.COMPLETED, resp3.GetWorkflowStatus()) |
| 134 | + assertions.Equal(1, len(resp3.GetResults())) |
| 135 | + assertions.Equal("S2", resp3.GetResults()[0].CompletedStateId) |
| 136 | + assertions.Equal("S2-5", resp3.GetResults()[0].CompletedStateExecutionId) |
| 137 | + assertions.Equal("5", resp3.GetResults()[0].CompletedStateOutput.GetData()) |
| 138 | + |
| 139 | + //reset workflow by state execution id |
| 140 | + reset2Req := apiClient.DefaultApi.ApiV1WorkflowResetPost(context.Background()) |
| 141 | + _, httpResp, err = reset2Req.WorkflowResetRequest(iwfidl.WorkflowResetRequest{ |
| 142 | + WorkflowRunId: iwfidl.PtrString(startResp.GetWorkflowRunId()), |
| 143 | + WorkflowId: wfId, |
| 144 | + ResetType: iwfidl.STATE_EXECUTION_ID, |
| 145 | + StateExecutionId: iwfidl.PtrString(reset.State2 + "-4"), |
| 146 | + }).Execute() |
| 147 | + panicAtHttpError(err, httpResp) |
| 148 | + |
| 149 | + req4 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) |
| 150 | + resp4, httpResp, err := req4.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ |
| 151 | + WorkflowId: wfId, |
| 152 | + }).Execute() |
| 153 | + panicAtHttpError(err, httpResp) |
| 154 | + |
| 155 | + reset2History, _ := wfHandler.GetTestResult() |
| 156 | + //expect no starts in history as WaitUntil api is skipped. |
| 157 | + assertions.Equalf(map[string]int64{ |
| 158 | + "S1_decide": 1, |
| 159 | + "S2_decide": 12, |
| 160 | + }, reset2History, "reset test fail, %v", reset2History) |
| 161 | + |
| 162 | + assertions.Equal(iwfidl.COMPLETED, resp4.GetWorkflowStatus()) |
| 163 | + assertions.Equal(1, len(resp4.GetResults())) |
| 164 | + assertions.Equal("S2", resp4.GetResults()[0].CompletedStateId) |
| 165 | + assertions.Equal("S2-5", resp4.GetResults()[0].CompletedStateExecutionId) |
| 166 | + assertions.Equal("5", resp4.GetResults()[0].CompletedStateOutput.GetData()) |
| 167 | +} |
0 commit comments