diff --git a/.github/workflows/ci-all-tests.yml b/.github/workflows/ci-all-tests.yml index 0ab72acc..8d6471b5 100644 --- a/.github/workflows/ci-all-tests.yml +++ b/.github/workflows/ci-all-tests.yml @@ -23,4 +23,6 @@ jobs: if: always() uses: jwalton/gh-docker-logs@v2 - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 \ No newline at end of file + uses: codecov/codecov-action@v5 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/Makefile b/Makefile index cd385a2f..adbd3419 100644 --- a/Makefile +++ b/Makefile @@ -189,9 +189,7 @@ ci-temporal-integ-test-disable-sticky: $Q go test -v ./integ -run "(?i)^Test[${startsWith}]" -cover -coverprofile coverage.out -coverpkg ./service/... -search=false -cadence=false -dependencyWaitSeconds=60 -disableStickyCache ci-all-tests: - # Fails CI when used with -coverprofile flag due to tests that panic; see https://go.dev/doc/build-cover#panicprof - # $Q go test -v ./... -timeout 15m -cover -coverprofile coverage.out -coverpkg ./service/... - $Q go test -v ./... -timeout 15m + $Q go test -v ./... -timeout 15m -cover -coverprofile coverage.out -coverpkg ./service/... integTestsNoSearch: $Q go test -v ./integ -search=false -timeout 15m diff --git a/integ/any_command_close_test.go b/integ/any_command_close_test.go index 11084bbd..00a4615a 100644 --- a/integ/any_command_close_test.go +++ b/integ/any_command_close_test.go @@ -55,7 +55,7 @@ func TestAnyCommandCloseWorkflowCadenceContinueAsNew(t *testing.T) { func doTestAnyCommandCloseWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := anycommandclose.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -81,7 +81,7 @@ func doTestAnyCommandCloseWorkflow(t *testing.T, backendType service.BackendType WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) signalValue := iwfidl.EncodedObject{ Encoding: iwfidl.PtrString("json"), @@ -94,14 +94,14 @@ func doTestAnyCommandCloseWorkflow(t *testing.T, backendType service.BackendType SignalChannelName: anycommandclose.SignalName2, SignalValue: &signalValue, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) _, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, data := wfHandler.GetTestResult() assertions := assert.New(t) diff --git a/integ/any_command_combination_test.go b/integ/any_command_combination_test.go index db67d7d7..085c44e7 100644 --- a/integ/any_command_combination_test.go +++ b/integ/any_command_combination_test.go @@ -3,6 +3,7 @@ package integ import ( "context" "encoding/json" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/service/common/ptr" "strconv" "testing" @@ -59,7 +60,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe assertions := assert.New(t) // start test workflow server wfHandler := anycommandconbination.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -85,7 +86,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) signalValue := iwfidl.EncodedObject{ Encoding: iwfidl.PtrString("json"), @@ -99,13 +100,13 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe SignalChannelName: anycommandconbination.SignalNameAndId1, SignalValue: &signalValue, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) httpResp, err = req2.WorkflowSignalRequest(iwfidl.WorkflowSignalRequest{ WorkflowId: wfId, SignalChannelName: anycommandconbination.SignalNameAndId1, SignalValue: &signalValue, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // skip the timer for S1 time.Sleep(time.Second * 5) // wait for a few seconds so that timer is ready to be skipped @@ -115,7 +116,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe WorkflowStateExecutionId: "S1-1", TimerCommandId: iwfidl.PtrString(anycommandconbination.TimerId1), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // now it should be running at S2 // Future: we can check it is already done S1 @@ -126,7 +127,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe SignalChannelName: anycommandconbination.SignalNameAndId1, SignalValue: &signalValue, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait and check the workflow, it should be still running time.Sleep(time.Second) @@ -134,7 +135,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe descResp, httpResp, err := reqDesc.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equal(iwfidl.RUNNING, descResp.GetWorkflowStatus()) httpResp, err = req2.WorkflowSignalRequest(iwfidl.WorkflowSignalRequest{ @@ -142,7 +143,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe SignalChannelName: anycommandconbination.SignalNameAndId3, SignalValue: &signalValue, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // send 2nd signal for s2 httpResp, err = req2.WorkflowSignalRequest(iwfidl.WorkflowSignalRequest{ @@ -150,7 +151,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe SignalChannelName: anycommandconbination.SignalNameAndId2, SignalValue: &signalValue, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // workflow should be completed now if config == nil { @@ -158,14 +159,14 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe descResp, httpResp, err = reqDesc.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equal(iwfidl.COMPLETED, descResp.GetWorkflowStatus()) } else { reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) respWait, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, respWait) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, respWait, t) } history, data := wfHandler.GetTestResult() @@ -189,7 +190,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe "\"stateStartApiSucceeded\":true}" err = json.Unmarshal([]byte(s1ResultJsonStr), &s1CommandResults) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } s2ResultsJsonStr := "{\"signalResults\":[" + "{\"commandId\":\"test-signal-name1\",\"signalChannelName\":\"test-signal-name1\",\"signalRequestStatus\":\"RECEIVED\",\"signalValue\":{\"data\":\"test-data-1\",\"encoding\":\"json\"}}, " + @@ -201,7 +202,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe "\"stateStartApiSucceeded\":true}" err = json.Unmarshal([]byte(s2ResultsJsonStr), &s2CommandResults) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } expectedData := map[string]interface{}{ "s1_commandResults": s1CommandResults, diff --git a/integ/any_timer_signal_test.go b/integ/any_timer_signal_test.go index ee2c2810..6f931d9a 100644 --- a/integ/any_timer_signal_test.go +++ b/integ/any_timer_signal_test.go @@ -55,7 +55,7 @@ func TestAnyTimerSignalWorkflowCadenceContinueAsNew(t *testing.T) { func doTestAnyTimerSignalWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := anytimersignal.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -83,7 +83,7 @@ func doTestAnyTimerSignalWorkflow(t *testing.T, backendType service.BackendType, WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for 3 secs and send the signal time.Sleep(time.Second * 3) @@ -97,14 +97,14 @@ func doTestAnyTimerSignalWorkflow(t *testing.T, backendType service.BackendType, SignalChannelName: anytimersignal.SignalName, SignalValue: &signalValue, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) _, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, data := wfHandler.GetTestResult() assertions := assert.New(t) diff --git a/integ/basic_test.go b/integ/basic_test.go index e34a1f7d..c1c55cce 100644 --- a/integ/basic_test.go +++ b/integ/basic_test.go @@ -47,7 +47,7 @@ func TestBasicWorkflowCadence(t *testing.T) { func doTestBasicWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := basic.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ @@ -107,7 +107,7 @@ func doTestBasicWorkflow(t *testing.T, backendType service.BackendType, config * }, } _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // start it again should return already started error _, _, err = req.WorkflowStartRequest(startReq).Execute() @@ -126,7 +126,7 @@ func doTestBasicWorkflow(t *testing.T, backendType service.BackendType, config * resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // use a wrong workflowId to test the error case _, _, err = req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ diff --git a/integ/conditional_close_test.go b/integ/conditional_close_test.go index 8530fb2d..ca260973 100644 --- a/integ/conditional_close_test.go +++ b/integ/conditional_close_test.go @@ -66,7 +66,7 @@ func doTestConditionalForceCompleteOnChannelEmptyWorkflow( assertions := assert.New(t) // start test workflow server wfHandler := conditionalClose.NewHandler() - closeFunc1 := startWorkflowWorkerWithRpc(wfHandler) + closeFunc1 := startWorkflowWorkerWithRpc(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceWithClient(backendType) @@ -105,7 +105,7 @@ func doTestConditionalForceCompleteOnChannelEmptyWorkflow( } _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for a second so that query handler is ready for executing PRC time.Sleep(time.Second) @@ -126,7 +126,7 @@ func doTestConditionalForceCompleteOnChannelEmptyWorkflow( }).Execute() } - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) if i == 0 { // wait for a second so that the workflow is in execute state time.Sleep(time.Second) @@ -138,7 +138,7 @@ func doTestConditionalForceCompleteOnChannelEmptyWorkflow( resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, _ := wfHandler.GetTestResult() diff --git a/integ/create_test.go b/integ/create_test.go index c84e94c3..9a9e239d 100644 --- a/integ/create_test.go +++ b/integ/create_test.go @@ -3,6 +3,7 @@ package integ import ( "context" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/rpc" "github.com/indeedeng/iwf/service" "github.com/stretchr/testify/assert" @@ -55,7 +56,7 @@ func doTestCreateWithoutStartingState(t *testing.T, backendType service.BackendT assertions := assert.New(t) // start test workflow server wfHandler := rpc.NewHandler() - closeFunc1 := startWorkflowWorkerWithRpc(wfHandler) + closeFunc1 := startWorkflowWorkerWithRpc(wfHandler, t) defer closeFunc1() uclient, closeFunc2 := startIwfServiceWithClient(backendType) @@ -82,13 +83,13 @@ func doTestCreateWithoutStartingState(t *testing.T, backendType service.BackendT WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // workflow shouldn't executed any state var dump service.DebugDumpResponse err = uclient.QueryWorkflow(context.Background(), &dump, wfId, "", service.DebugDumpQueryType) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } assertions.Equal(service.StateExecutionCounterInfo{ StateIdStartedCount: make(map[string]int), @@ -110,14 +111,14 @@ func doTestCreateWithoutStartingState(t *testing.T, backendType service.BackendT }, TimeoutSeconds: iwfidl.PtrInt32(2), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) respWait, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, respWait) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, respWait, t) history, _ := wfHandler.GetTestResult() assertions.Equalf(map[string]int64{ diff --git a/integ/deadend_test.go b/integ/deadend_test.go index 8ecfa8bf..73859728 100644 --- a/integ/deadend_test.go +++ b/integ/deadend_test.go @@ -55,7 +55,7 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config assertions := assert.New(t) // start test workflow server wfHandler := deadend.NewHandler() - closeFunc1 := startWorkflowWorkerWithRpc(wfHandler) + closeFunc1 := startWorkflowWorkerWithRpc(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceWithClient(backendType) @@ -82,7 +82,7 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqRpc := apiClient.DefaultApi.ApiV1WorkflowRpcPost(context.Background()) @@ -93,7 +93,7 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config WorkflowId: wfId, RpcName: deadend.RPCWriteData, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) } if config != nil { @@ -101,7 +101,7 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config descResp, httpResp, err := reqDesc.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.True(startResp.GetWorkflowRunId() != descResp.GetWorkflowRunId()) } @@ -112,7 +112,7 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config WorkflowId: wfId, RpcName: deadend.RPCTriggerState, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) } time.Sleep(time.Second * 2) @@ -121,7 +121,7 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config httpResp, err = reqCancel.WorkflowStopRequest(iwfidl.WorkflowStopRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, _ := wfHandler.GetTestResult() assertions.Equalf(map[string]int64{ diff --git a/integ/get_with_wait_timeout_test.go b/integ/get_with_wait_timeout_test.go index 0dfc4e8d..b97600c1 100644 --- a/integ/get_with_wait_timeout_test.go +++ b/integ/get_with_wait_timeout_test.go @@ -39,7 +39,7 @@ func doTestWorkflowWithWaitTimeout(t *testing.T, backendType service.BackendType // start test workflow server wfHandler := signal.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -65,7 +65,7 @@ func doTestWorkflowWithWaitTimeout(t *testing.T, backendType service.BackendType WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) diff --git a/integ/headers_test.go b/integ/headers_test.go index c752e59b..71349f21 100644 --- a/integ/headers_test.go +++ b/integ/headers_test.go @@ -47,7 +47,7 @@ func TestHeadersWorkflowCadence(t *testing.T) { func doTestWorkflowWithHeaders(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := headers.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ @@ -84,13 +84,13 @@ func doTestWorkflowWithHeaders(t *testing.T, backendType service.BackendType, co }, } _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) _, httpResp2, err2 := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err2, httpResp2) + failTestAtHttpError(err2, httpResp2, t) assertions := assert.New(t) diff --git a/integ/helpers/errors.go b/integ/helpers/errors.go new file mode 100644 index 00000000..bd140b6d --- /dev/null +++ b/integ/helpers/errors.go @@ -0,0 +1,11 @@ +package helpers + +import "testing" + +func FailTestWithError(error error, t *testing.T) { + t.Fatalf("%s - Test failed with error: %v", t.Name(), error) +} + +func FailTestWithErrorMessage(errorMessage string, t *testing.T) { + t.Fatalf("%s - Test failed with error: %s", t.Name(), errorMessage) +} diff --git a/integ/internalchannel_test.go b/integ/internalchannel_test.go index 3d44b805..837be977 100644 --- a/integ/internalchannel_test.go +++ b/integ/internalchannel_test.go @@ -39,7 +39,7 @@ func TestInterStateWorkflowCadence(t *testing.T) { func doTestInterStateWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := interstate.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -65,13 +65,13 @@ func doTestInterStateWorkflow(t *testing.T, backendType service.BackendType, con WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, data := wfHandler.GetTestResult() assertions := assert.New(t) diff --git a/integ/large_data_attributes_test.go b/integ/large_data_attributes_test.go index 99f851cf..b061cdaa 100644 --- a/integ/large_data_attributes_test.go +++ b/integ/large_data_attributes_test.go @@ -33,7 +33,7 @@ func doTestLargeQueryAttributes(t *testing.T, backendType service.BackendType, c // start test workflow server wfHandler := signal.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceWithClient(backendType) @@ -63,7 +63,7 @@ func doTestLargeQueryAttributes(t *testing.T, backendType service.BackendType, c WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equal(httpResp.StatusCode, http.StatusOK) @@ -90,7 +90,7 @@ func doTestLargeQueryAttributes(t *testing.T, backendType service.BackendType, c }, }).Execute() - panicAtHttpError(err, httpResp2) + failTestAtHttpError(err, httpResp2, t) } // signal the workflow to complete @@ -107,7 +107,7 @@ func doTestLargeQueryAttributes(t *testing.T, backendType service.BackendType, c SignalValue: &signalVal, }).Execute() - panicAtHttpError(err, httpResp2) + failTestAtHttpError(err, httpResp2, t) } // wait for the workflow @@ -115,5 +115,5 @@ func doTestLargeQueryAttributes(t *testing.T, backendType service.BackendType, c _, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) } diff --git a/integ/locking_test.go b/integ/locking_test.go index fffd4777..8cd927e9 100644 --- a/integ/locking_test.go +++ b/integ/locking_test.go @@ -17,6 +17,9 @@ import ( ) func TestLockingWorkflowTemporal(t *testing.T) { + // TODO: Remove this line to enable the test + t.Skip("TestLockingWorkflowTemporal - Skipping this test - See: https://github.com/indeedeng/iwf/issues/536") + if !*temporalIntegTest { t.Skip() } @@ -27,6 +30,9 @@ func TestLockingWorkflowTemporal(t *testing.T) { } func TestLockingWorkflowTemporalContinueAsNew(t *testing.T) { + // TODO: Remove this line to enable the test + t.Skip("TestLockingWorkflowTemporal - Skipping this test - See: https://github.com/indeedeng/iwf/issues/536") + if !*temporalIntegTest { t.Skip() } @@ -60,7 +66,7 @@ func TestLockingWorkflowCadenceContinueAsNew(t *testing.T) { func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := locking.NewHandler() - closeFunc1 := startWorkflowWorkerWithRpc(wfHandler) + closeFunc1 := startWorkflowWorkerWithRpc(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ @@ -91,7 +97,7 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config }, } _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) for i := 0; i < locking.NumUnusedSignals; i++ { // send 4 unused signals at the beginning to validate the ChannelInfo feature @@ -101,7 +107,7 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config SignalChannelName: locking.UnusedSignalChannelName, SignalValue: nil, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) } assertions := assert.New(t) @@ -168,7 +174,7 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config rpcLockingFailure++ continue } else { - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) } } fmt.Println("rpc execution succeeded") @@ -187,14 +193,14 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config RpcName: locking.RPCName, Input: locking.UnblockValue, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(time.Second * 20) req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) s2StartsDecides := locking.InParallelS2 + rpcIncrease // locking.InParallelS2 original state executions, and a new trigger from rpc finalCounterValue := int64(locking.InParallelS2 + 2*rpcIncrease) @@ -222,7 +228,7 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config }, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) expectedSearchAttributeInt := iwfidl.SearchAttribute{ Key: iwfidl.PtrString(locking.TestSearchAttributeIntKey), @@ -244,7 +250,7 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config }, UseMemoForDataAttributes: ptr.Any(useMemo), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) expected1 := []iwfidl.KeyValue{ { @@ -262,16 +268,15 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config _, httpResp, err = resetReq.WorkflowResetRequest(iwfidl.WorkflowResetRequest{ WorkflowId: wfId, ResetType: iwfidl.BEGINNING, - //SkipSignalReapply: ptr.Any(true), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(time.Second * 20) req2Reset := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp2Reset, httpResp, err := req2Reset.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equal(iwfidl.COMPLETED, resp2Reset.GetWorkflowStatus()) @@ -283,14 +288,14 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config // RpcName: locking.RPCName, // Input: locking.UnblockValue, //}).Execute() - //panicAtHttpError(err, httpResp) + //failTestAtHttpError(err, httpResp, t) //time.Sleep(time.Second * 20) //req2Reset := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) //resp2Reset, httpResp, err := req2Reset.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ // WorkflowId: wfId, //}).Execute() - //panicAtHttpError(err, httpResp) + //failTestAtHttpError(err, httpResp, t) //s2StartsDecides := locking.InParallelS2 + rpcIncrease // locking.InParallelS2 original state executions, and a new trigger from rpc //finalCounterValue := int64(locking.InParallelS2 + 2*rpcIncrease) @@ -318,7 +323,7 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config // }, // }, //}).Execute() - //panicAtHttpError(err, httpResp) + //failTestAtHttpError(err, httpResp, t) // //expectedSearchAttributeIntReset := iwfidl.SearchAttribute{ // Key: iwfidl.PtrString(locking.TestSearchAttributeIntKey), diff --git a/integ/parallel_test.go b/integ/parallel_test.go index 6ac51aec..7f38815c 100644 --- a/integ/parallel_test.go +++ b/integ/parallel_test.go @@ -39,7 +39,7 @@ func TestParallelWorkflowCadence(t *testing.T) { func doTestParallelWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := parallel.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -65,14 +65,14 @@ func doTestParallelWorkflow(t *testing.T, backendType service.BackendType, confi WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, _ := wfHandler.GetTestResult() assertions := assert.New(t) diff --git a/integ/persistence_loading_policy_test.go b/integ/persistence_loading_policy_test.go index 813d822e..142a5fda 100644 --- a/integ/persistence_loading_policy_test.go +++ b/integ/persistence_loading_policy_test.go @@ -3,6 +3,7 @@ package integ import ( "context" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/persistence" "github.com/indeedeng/iwf/integ/workflow/persistence_loading_policy" "github.com/indeedeng/iwf/service" @@ -63,7 +64,7 @@ func doTestPersistenceLoadingPolicy( assertions := assert.New(t) wfHandler := persistence_loading_policy.NewHandler() - closeFunc1 := startWorkflowWorkerWithRpc(wfHandler) + closeFunc1 := startWorkflowWorkerWithRpc(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) defer closeFunc2() @@ -100,11 +101,11 @@ func doTestPersistenceLoadingPolicy( _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() if rpcUseMemo && backendType == service.BackendTypeCadence { if err == nil { - panic("err should not be nil when Memo is not supported with Cadence") + helpers.FailTestWithErrorMessage("err should not be nil when Memo is not supported with Cadence", t) } return } - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(time.Second * 2) @@ -140,11 +141,11 @@ func doTestPersistenceLoadingPolicy( _, httpResp, err = reqRpc.WorkflowRpcRequest(rpcReq).Execute() if loadingType == iwfidl.PARTIAL_WITH_EXCLUSIVE_LOCK && backendType == service.BackendTypeCadence { if err == nil { - panic("err should not be nil when Locking is not supported with Cadence") + helpers.FailTestWithErrorMessage("err should not be nil when Locking is not supported with Cadence", t) } return } - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(time.Second * 2) diff --git a/integ/persistence_test.go b/integ/persistence_test.go index 1cb3a580..dc0e59b1 100644 --- a/integ/persistence_test.go +++ b/integ/persistence_test.go @@ -102,7 +102,7 @@ func doTestPersistenceWorkflow( ) { assertions := assert.New(t) wfHandler := persistence.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() uclient, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ @@ -163,7 +163,7 @@ func doTestPersistenceWorkflow( }, } _, httpResp, err := reqStart.WorkflowStartRequest(wfReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) initReqQry := apiClient.DefaultApi.ApiV1WorkflowDataobjectsGetPost(context.Background()) @@ -184,7 +184,7 @@ func doTestPersistenceWorkflow( } } - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assert.Contains(t, queryResult.GetObjects(), expectedDataAttribute) @@ -192,7 +192,7 @@ func doTestPersistenceWorkflow( wfResponse, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqQry := apiClient.DefaultApi.ApiV1WorkflowDataobjectsGetPost(context.Background()) queryResult1, httpResp, err := reqQry.WorkflowGetDataObjectsRequest(iwfidl.WorkflowGetDataObjectsRequest{ @@ -202,13 +202,13 @@ func doTestPersistenceWorkflow( }, UseMemoForDataAttributes: ptr.Any(useMemo), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) queryResult2, httpResp, err := reqQry.WorkflowGetDataObjectsRequest(iwfidl.WorkflowGetDataObjectsRequest{ WorkflowId: wfId, UseMemoForDataAttributes: ptr.Any(useMemo), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqSearch := apiClient.DefaultApi.ApiV1WorkflowSearchattributesGetPost(context.Background()) searchResult1, httpResp, err := reqSearch.WorkflowGetSearchAttributesRequest(iwfidl.WorkflowGetSearchAttributesRequest{ @@ -221,7 +221,7 @@ func doTestPersistenceWorkflow( }, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) searchResult2, httpResp, err := reqSearch.WorkflowGetSearchAttributesRequest(iwfidl.WorkflowGetSearchAttributesRequest{ WorkflowId: wfId, @@ -233,7 +233,7 @@ func doTestPersistenceWorkflow( }, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // assertion history, data := wfHandler.GetTestResult() @@ -330,7 +330,7 @@ func doTestPersistenceWorkflow( } _, httpResp, err := reqStart.WorkflowStartRequest(wfReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) wfReq.WorkflowId = firstWfId + "-2" newSa = iwfidl.SearchAttribute{ @@ -341,7 +341,7 @@ func doTestPersistenceWorkflow( wfReq.WorkflowStartOptions.SearchAttributes = append(wfReq.WorkflowStartOptions.SearchAttributes, newSa) _, httpResp, err = reqStart.WorkflowStartRequest(wfReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) wfReq.WorkflowId = firstWfId + "-3" newSa = iwfidl.SearchAttribute{ @@ -351,7 +351,7 @@ func doTestPersistenceWorkflow( } wfReq.WorkflowStartOptions.SearchAttributes = append(wfReq.WorkflowStartOptions.SearchAttributes, newSa) _, httpResp, err = reqStart.WorkflowStartRequest(wfReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) wfReq.WorkflowId = firstWfId + "-4" newSa = iwfidl.SearchAttribute{ @@ -361,39 +361,39 @@ func doTestPersistenceWorkflow( } wfReq.WorkflowStartOptions.SearchAttributes = append(wfReq.WorkflowStartOptions.SearchAttributes, newSa) _, httpResp, err = reqStart.WorkflowStartRequest(wfReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for all completed resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: firstWfId + "-1", }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t) resp, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: firstWfId + "-2", }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t) resp, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: firstWfId + "-3", }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t) resp, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: firstWfId + "-4", }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t) // wait for the search attribute index to be ready in ElasticSearch time.Sleep(time.Duration(*searchWaitTimeIntegTest) * time.Millisecond) if config != nil { - assertSearch(fmt.Sprintf("CustomDatetimeField='%v'", nowTimeStr), 15, apiClient, assertions) - assertSearch(fmt.Sprintf("CustomDatetimeField='%v' AND CustomStringField='%v'", nowTimeStr, "Quanzheng"), 3, apiClient, assertions) - assertSearch(fmt.Sprintf("CustomDatetimeField='%v' AND CustomDoubleField='%v'", nowTimeStr, "0.01"), 9, apiClient, assertions) - assertSearch(fmt.Sprintf("CustomDatetimeField='%v' AND CustomBoolField='%v'", nowTimeStr, "true"), 0, apiClient, assertions) // Note that the bool field got changed during WF execution + assertSearch(t, fmt.Sprintf("CustomDatetimeField='%v'", nowTimeStr), 15, apiClient, assertions) + assertSearch(t, fmt.Sprintf("CustomDatetimeField='%v' AND CustomStringField='%v'", nowTimeStr, "Quanzheng"), 3, apiClient, assertions) + assertSearch(t, fmt.Sprintf("CustomDatetimeField='%v' AND CustomDoubleField='%v'", nowTimeStr, "0.01"), 9, apiClient, assertions) + assertSearch(t, fmt.Sprintf("CustomDatetimeField='%v' AND CustomBoolField='%v'", nowTimeStr, "true"), 0, apiClient, assertions) // Note that the bool field got changed during WF execution } else { - assertSearch(fmt.Sprintf("CustomDatetimeField='%v'", nowTimeStr), 5, apiClient, assertions) - assertSearch(fmt.Sprintf("CustomDatetimeField='%v' AND CustomStringField='%v'", nowTimeStr, "Quanzheng"), 1, apiClient, assertions) - assertSearch(fmt.Sprintf("CustomDatetimeField='%v' AND CustomDoubleField='%v'", nowTimeStr, "0.01"), 3, apiClient, assertions) - assertSearch(fmt.Sprintf("CustomDatetimeField='%v' AND CustomBoolField='%v'", nowTimeStr, "true"), 0, apiClient, assertions) // Note that the bool field got changed during WF execution + assertSearch(t, fmt.Sprintf("CustomDatetimeField='%v'", nowTimeStr), 5, apiClient, assertions) + assertSearch(t, fmt.Sprintf("CustomDatetimeField='%v' AND CustomStringField='%v'", nowTimeStr, "Quanzheng"), 1, apiClient, assertions) + assertSearch(t, fmt.Sprintf("CustomDatetimeField='%v' AND CustomDoubleField='%v'", nowTimeStr, "0.01"), 3, apiClient, assertions) + assertSearch(t, fmt.Sprintf("CustomDatetimeField='%v' AND CustomBoolField='%v'", nowTimeStr, "true"), 0, apiClient, assertions) // Note that the bool field got changed during WF execution } // TODO?? research how to use text @@ -414,7 +414,7 @@ func getDataAttributes( }).Execute() } -func assertSearch(query string, expectedCount int, apiClient *iwfidl.APIClient, assertions *assert.Assertions) { +func assertSearch(t *testing.T, query string, expectedCount int, apiClient *iwfidl.APIClient, assertions *assert.Assertions) { // search through all wfs using search API with pagination search := apiClient.DefaultApi.ApiV1WorkflowSearchPost(context.Background()) @@ -426,7 +426,7 @@ func assertSearch(query string, expectedCount int, apiClient *iwfidl.APIClient, PageSize: iwfidl.PtrInt32(2), NextPageToken: &nextPageToken, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) currentCount += len(searchResp.WorkflowExecutions) if currentCount < expectedCount { @@ -444,7 +444,7 @@ func assertSearch(query string, expectedCount int, apiClient *iwfidl.APIClient, PageSize: iwfidl.PtrInt32(2), NextPageToken: &nextPageToken, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equal(0, len(searchResp.WorkflowExecutions)) assertions.True(len(searchResp.GetNextPageToken()) == 0) } diff --git a/integ/reset_by_state_id_test.go b/integ/reset_by_state_id_test.go index 9f1d5323..d825cbde 100644 --- a/integ/reset_by_state_id_test.go +++ b/integ/reset_by_state_id_test.go @@ -45,7 +45,7 @@ func TestResetByStateIdWorkflowCadence(t *testing.T) { func doTestResetByStatIdWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := reset.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ @@ -84,7 +84,7 @@ func doTestResetByStatIdWorkflow(t *testing.T, backendType service.BackendType, }, } startResp, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions := assert.New(t) @@ -92,7 +92,7 @@ func doTestResetByStatIdWorkflow(t *testing.T, backendType service.BackendType, resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, _ := wfHandler.GetTestResult() //expect no starts in history as WaitUntil api is skipped. @@ -115,13 +115,13 @@ func doTestResetByStatIdWorkflow(t *testing.T, backendType service.BackendType, ResetType: iwfidl.STATE_ID, StateId: iwfidl.PtrString(reset.State2), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) req3 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp3, httpResp, err := req3.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) resetHistory, _ := wfHandler.GetTestResult() //expect no starts in history as WaitUntil api is skipped. @@ -144,13 +144,13 @@ func doTestResetByStatIdWorkflow(t *testing.T, backendType service.BackendType, ResetType: iwfidl.STATE_EXECUTION_ID, StateExecutionId: iwfidl.PtrString(reset.State2 + "-4"), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) req4 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp4, httpResp, err := req4.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reset2History, _ := wfHandler.GetTestResult() //expect no starts in history as WaitUntil api is skipped. diff --git a/integ/rpc_test.go b/integ/rpc_test.go index 23add52c..89e6d5b2 100644 --- a/integ/rpc_test.go +++ b/integ/rpc_test.go @@ -100,7 +100,7 @@ func doTestRpcWorkflow( assertions := assert.New(t) // start test workflow server wfHandler := rpc.NewHandler() - closeFunc1 := startWorkflowWorkerWithRpc(wfHandler) + closeFunc1 := startWorkflowWorkerWithRpc(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ @@ -132,7 +132,7 @@ func doTestRpcWorkflow( UseMemoForDataAttributes: ptr.Any(useMemo), }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) allSearchAttributes := []iwfidl.SearchAttributeKeyAndType{ { @@ -164,7 +164,7 @@ func doTestRpcWorkflow( UseMemoForDataAttributes: ptr.Any(useMemo), SearchAttributes: allSearchAttributes, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqRpc = apiClient.DefaultApi.ApiV1WorkflowRpcPost(context.Background()) _, httpResp, err = reqRpc.WorkflowRpcRequest(iwfidl.WorkflowRpcRequest{ @@ -210,14 +210,14 @@ func doTestRpcWorkflow( UseMemoForDataAttributes: ptr.Any(useMemo), SearchAttributes: allSearchAttributes, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) respWait, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, respWait) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, respWait, t) history, data := wfHandler.GetTestResult() assertions.Equalf(map[string]int64{ @@ -287,7 +287,7 @@ func doTestRpcWorkflow( allDos, httpResp, err := reqQry.WorkflowGetDataObjectsRequest(iwfidl.WorkflowGetDataObjectsRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqSearch := apiClient.DefaultApi.ApiV1WorkflowSearchattributesGetPost(context.Background()) allSAs, httpResp, err := reqSearch.WorkflowGetSearchAttributesRequest(iwfidl.WorkflowGetSearchAttributesRequest{ @@ -307,7 +307,7 @@ func doTestRpcWorkflow( }, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equalf([]iwfidl.KeyValue{ { diff --git a/integ/set_data_attributes_test.go b/integ/set_data_attributes_test.go index 2c149cc5..1a9e89b9 100644 --- a/integ/set_data_attributes_test.go +++ b/integ/set_data_attributes_test.go @@ -22,7 +22,7 @@ func TestSetDataAttributesTemporal(t *testing.T) { // start test workflow server wfHandler := signal.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceWithClient(service.BackendTypeTemporal) @@ -46,7 +46,7 @@ func TestSetDataAttributesTemporal(t *testing.T) { IwfWorkerUrl: "http://localhost:" + testWorkflowServerPort, StartStateId: ptr.Any(signal.State1), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equal(httpResp.StatusCode, http.StatusOK) @@ -67,7 +67,7 @@ func TestSetDataAttributesTemporal(t *testing.T) { Objects: smallDataObjects, }).Execute() - panicAtHttpError(err, httpResp2) + failTestAtHttpError(err, httpResp2, t) time.Sleep(time.Second) @@ -77,7 +77,7 @@ func TestSetDataAttributesTemporal(t *testing.T) { Keys: []string{ persistence.TestDataObjectKey, persistence.TestDataObjectKey2, }}).Execute() - panicAtHttpError(err, httpRespGet) + failTestAtHttpError(err, httpRespGet, t) assertions.ElementsMatch(smallDataObjects, getResult.Objects) } diff --git a/integ/set_search_attributes_test.go b/integ/set_search_attributes_test.go index 4ab3782a..3b7e3456 100644 --- a/integ/set_search_attributes_test.go +++ b/integ/set_search_attributes_test.go @@ -22,7 +22,7 @@ func TestSetSearchAttributes(t *testing.T) { // start test workflow server wfHandler := signal.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceWithClient(service.BackendTypeTemporal) @@ -46,7 +46,7 @@ func TestSetSearchAttributes(t *testing.T) { IwfWorkerUrl: "http://localhost:" + testWorkflowServerPort, StartStateId: ptr.Any(signal.State1), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equal(httpResp.StatusCode, http.StatusOK) @@ -73,7 +73,7 @@ func TestSetSearchAttributes(t *testing.T) { SearchAttributes: signalVals, }).Execute() - panicAtHttpError(err, httpResp2) + failTestAtHttpError(err, httpResp2, t) time.Sleep(time.Second) @@ -94,7 +94,7 @@ func TestSetSearchAttributes(t *testing.T) { ValueType: ptr.Any(iwfidl.KEYWORD_ARRAY), }, }}).Execute() - panicAtHttpError(err, httpRespGet) + failTestAtHttpError(err, httpRespGet, t) assertions.ElementsMatch(signalVals, searchResult.SearchAttributes) } diff --git a/integ/signal_test.go b/integ/signal_test.go index d1bcb5f7..83b0e93c 100644 --- a/integ/signal_test.go +++ b/integ/signal_test.go @@ -6,6 +6,7 @@ import ( "fmt" config2 "github.com/indeedeng/iwf/config" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/signal" "github.com/indeedeng/iwf/service" "github.com/indeedeng/iwf/service/common/ptr" @@ -61,7 +62,7 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config // start test workflow server wfHandler := signal.NewHandler() - closeFunc1 := startWorkflowWorkerWithRpc(wfHandler) + closeFunc1 := startWorkflowWorkerWithRpc(wfHandler, t) defer closeFunc1() uclient, closeFunc2 := startIwfServiceWithClient(backendType) @@ -87,13 +88,13 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // test update config var debugDump service.DebugDumpResponse err = uclient.QueryWorkflow(context.Background(), &debugDump, wfId, "", service.DebugDumpQueryType) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } expectedConfig := *config2.DefaultWorkflowConfig if config != nil { @@ -109,14 +110,14 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config DisableSystemSearchAttribute: iwfidl.PtrBool(true), }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) if config != nil { time.Sleep(2 * time.Second) } err = uclient.QueryWorkflow(context.Background(), &debugDump, wfId, "", service.DebugDumpQueryType) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } expectedConfig.DisableSystemSearchAttribute = iwfidl.PtrBool(true) assertions.Equal(expectedConfig, debugDump.Config) @@ -129,11 +130,11 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config ContinueAsNewPageSizeInBytes: iwfidl.PtrInt32(3000000), }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) err = uclient.QueryWorkflow(context.Background(), &debugDump, wfId, "", service.DebugDumpQueryType) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } expectedConfig.ContinueAsNewPageSizeInBytes = iwfidl.PtrInt32(3000000) assertions.Equal(expectedConfig, debugDump.Config) @@ -160,10 +161,10 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config WorkflowId: wfId, RpcName: signal.RPCNameGetSignalChannelInfo, }).Execute() - panicAtHttpError(err2, httpResp2) + failTestAtHttpError(err2, httpResp2, t) var infos map[string]iwfidl.ChannelInfo err = json.Unmarshal([]byte(rpcResp.Output.GetData()), &infos) - panicAtError(err) + failTestAtError(err, t) assertions.Equal( map[string]iwfidl.ChannelInfo{signal.UnhandledSignalName: {Size: ptr.Any(int32(i + 1))}}, infos) } @@ -173,10 +174,10 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config WorkflowId: wfId, RpcName: signal.RPCNameGetInternalChannelInfo, }).Execute() - panicAtHttpError(err2, httpResp2) + failTestAtHttpError(err2, httpResp2, t) var infos map[string]iwfidl.ChannelInfo err = json.Unmarshal([]byte(rpcResp.Output.GetData()), &infos) - panicAtError(err) + failTestAtError(err, t) assertions.Equal( map[string]iwfidl.ChannelInfo{signal.InternalChannelName: {Size: ptr.Any(int32(10))}}, infos) @@ -196,7 +197,7 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config SignalValue: &signalVal, }).Execute() - panicAtHttpError(err, httpResp2) + failTestAtHttpError(err, httpResp2, t) } // wait for the workflow @@ -204,7 +205,7 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config _, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, data := wfHandler.GetTestResult() assertions.Equalf(map[string]int64{ @@ -225,7 +226,7 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config var dump service.DebugDumpResponse err = uclient.QueryWorkflow(context.Background(), &dump, wfId, "", service.DebugDumpQueryType) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } assertions.Equal(unhandledSignalVals, dump.Snapshot.SignalsReceived[signal.UnhandledSignalName]) assertions.True(len(unhandledSignalVals) > 0) @@ -240,13 +241,13 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config WorkflowId: wfId, ResetType: iwfidl.BEGINNING, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqWait = apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t) // reset to STATE_EXECUTION_ID req4 = apiClient.DefaultApi.ApiV1WorkflowResetPost(context.Background()) @@ -255,13 +256,13 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config ResetType: iwfidl.STATE_EXECUTION_ID, StateExecutionId: iwfidl.PtrString("S2-1"), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqWait = apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t) // reset to STATE_ID req4 = apiClient.DefaultApi.ApiV1WorkflowResetPost(context.Background()) @@ -270,13 +271,13 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config ResetType: iwfidl.STATE_ID, StateId: iwfidl.PtrString("S2"), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqWait = apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t) } } diff --git a/integ/skip_start_test.go b/integ/skip_start_test.go index cffdc872..29dff184 100644 --- a/integ/skip_start_test.go +++ b/integ/skip_start_test.go @@ -56,7 +56,7 @@ func TestSkipStartWorkflowCadenceContinueAsNew(t *testing.T) { func doTestSkipStartWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := skipstart.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -91,7 +91,7 @@ func doTestSkipStartWorkflow(t *testing.T, backendType service.BackendType, conf }, } _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions := assert.New(t) @@ -99,7 +99,7 @@ func doTestSkipStartWorkflow(t *testing.T, backendType service.BackendType, conf resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, _ := wfHandler.GetTestResult() assertions.Equalf(map[string]int64{ diff --git a/integ/start_delay_test.go b/integ/start_delay_test.go index ec07442b..99dc9518 100644 --- a/integ/start_delay_test.go +++ b/integ/start_delay_test.go @@ -29,7 +29,7 @@ func TestStartDelayCadence(t *testing.T) { func doTestStartDelay(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := basic.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ @@ -89,14 +89,14 @@ func doTestStartDelay(t *testing.T, backendType service.BackendType, config *iwf timeSentReq := time.Now() _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(5 * time.Second) req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) _, httpResp, err = req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // here the delay is startDelay + execution time period, and the execution time period is negligible delay := time.Since(timeSentReq) diff --git a/integ/start_with_no_options_test.go b/integ/start_with_no_options_test.go index 06d57e89..836a5b2e 100644 --- a/integ/start_with_no_options_test.go +++ b/integ/start_with_no_options_test.go @@ -33,7 +33,7 @@ func doTestStartWorkflowWithoutStartOptions(t *testing.T, backendType service.Ba } wfHandler := basic.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() client, closeFunc2 := startIwfServiceWithClient(backendType) @@ -62,7 +62,7 @@ func doTestStartWorkflowWithoutStartOptions(t *testing.T, backendType service.Ba StateInput: wfInput, } _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) requestedSAs := []iwfidl.SearchAttributeKeyAndType{ { diff --git a/integ/timer_test.go b/integ/timer_test.go index 35681e1e..91da84fa 100644 --- a/integ/timer_test.go +++ b/integ/timer_test.go @@ -58,7 +58,7 @@ func TestTimerWorkflowCadenceContinueAsNew(t *testing.T) { func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := timer.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() uclient, closeFunc2 := startIwfServiceWithClient(backendType) @@ -88,7 +88,7 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config * WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(time.Second * 1) timerInfos := service.GetCurrentTimerInfosQueryResponse{} @@ -128,7 +128,7 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config * WorkflowStateExecutionId: "S1-1", TimerCommandId: iwfidl.PtrString("timer-cmd-id-2"), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(time.Second * 1) timerInfos = service.GetCurrentTimerInfosQueryResponse{} @@ -145,7 +145,7 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config * WorkflowStateExecutionId: "S1-1", TimerCommandIndex: iwfidl.PtrInt32(2), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(time.Second * 1) timerInfos = service.GetCurrentTimerInfosQueryResponse{} @@ -161,7 +161,7 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config * _, httpResp, err = req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, data := wfHandler.GetTestResult() assertions.Equalf(map[string]int64{ @@ -181,7 +181,7 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config * WorkflowId: wfId, ResetType: iwfidl.BEGINNING, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) err = uclient.QueryWorkflow(context.Background(), &timerInfos, wfId, "", service.GetCurrentTimerInfosQueryType) if err != nil { @@ -195,7 +195,7 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config * resp, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t) } func assertTimerQueryResponseEqual( diff --git a/integ/util.go b/integ/util.go index 6fdef79e..0614f618 100644 --- a/integ/util.go +++ b/integ/util.go @@ -1,10 +1,13 @@ package integ import ( + "fmt" + "github.com/indeedeng/iwf/integ/helpers" cadenceapi "github.com/indeedeng/iwf/service/client/cadence" temporalapi "github.com/indeedeng/iwf/service/client/temporal" "log" "net/http" + "testing" "time" "github.com/gin-gonic/gin" @@ -36,19 +39,25 @@ func createTemporalClient(dataConverter converter.DataConverter) client.Client { return temporalClient } -func startWorkflowWorkerWithRpc(handler common.WorkflowHandlerWithRpc) (closeFunc func()) { +func startWorkflowWorkerWithRpc(handler common.WorkflowHandlerWithRpc, t *testing.T) (closeFunc func()) { router := gin.Default() - router.POST(service.WorkflowWorkerRpcApi, handler.ApiV1WorkflowWorkerRpc) - return doStartWorkflowWorker(handler, router) + router.POST(service.WorkflowWorkerRpcApi, func(c *gin.Context) { + handler.ApiV1WorkflowWorkerRpc(c, t) + }) + return doStartWorkflowWorker(handler, t, router) } -func startWorkflowWorker(handler common.WorkflowHandler) (closeFunc func()) { +func startWorkflowWorker(handler common.WorkflowHandler, t *testing.T) (closeFunc func()) { router := gin.Default() - return doStartWorkflowWorker(handler, router) + return doStartWorkflowWorker(handler, t, router) } -func doStartWorkflowWorker(handler common.WorkflowHandler, router *gin.Engine) (closeFunc func()) { - router.POST(service.StateStartApi, handler.ApiV1WorkflowStateStart) - router.POST(service.StateDecideApi, handler.ApiV1WorkflowStateDecide) +func doStartWorkflowWorker(handler common.WorkflowHandler, t *testing.T, router *gin.Engine) (closeFunc func()) { + router.POST(service.StateStartApi, func(c *gin.Context) { + handler.ApiV1WorkflowStateStart(c, t) + }) + router.POST(service.StateDecideApi, func(c *gin.Context) { + handler.ApiV1WorkflowStateDecide(c, t) + }) wfServer := &http.Server{ Addr: ":" + testWorkflowServerPort, @@ -178,30 +187,30 @@ func doStartIwfServiceWithClient(config IwfServiceTestConfig) (uclient uclient.U } } -func panicAtError(err error) { +func failTestAtError(err error, t *testing.T) { if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } } -func panicAtHttpError(err error, httpResp *http.Response) { +func failTestAtHttpError(err error, httpResp *http.Response, t *testing.T) { if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } if httpResp.StatusCode != http.StatusOK { - panic("Status not success" + httpResp.Status) + helpers.FailTestWithErrorMessage(fmt.Sprintf("HTTP status not success: %v", httpResp.Status), t) } } -func panicAtHttpErrorOrWorkflowUncompleted(err error, httpResp *http.Response, resp *iwfidl.WorkflowGetResponse) { +func failTestAtHttpErrorOrWorkflowUncompleted(err error, httpResp *http.Response, resp *iwfidl.WorkflowGetResponse, t *testing.T) { if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } if httpResp.StatusCode != http.StatusOK { - panic("Status not success" + httpResp.Status) + helpers.FailTestWithErrorMessage(fmt.Sprintf("HTTP status not success: %v", httpResp.Status), t) } if resp.WorkflowStatus != iwfidl.COMPLETED { - panic("Workflow uncompleted:" + resp.WorkflowStatus) + helpers.FailTestWithErrorMessage(fmt.Sprintf("Workflow uncompleted: %v", resp.WorkflowStatus), t) } } diff --git a/integ/wait_for_state_completion_test.go b/integ/wait_for_state_completion_test.go index cab9417c..b8e005e9 100644 --- a/integ/wait_for_state_completion_test.go +++ b/integ/wait_for_state_completion_test.go @@ -44,7 +44,7 @@ func doTestWaitForStateCompletion( ) { // start test workflow server wfHandler := wait_for_state_completion.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -81,7 +81,7 @@ func doTestWaitForStateCompletion( startReq.WaitForCompletionStateIds = []string{"S2"} _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) req := apiClient.DefaultApi.ApiV1WorkflowWaitForStateCompletionPost(context.Background()) _, httpResp, err = req.WorkflowWaitForStateCompletionRequest( @@ -91,7 +91,7 @@ func doTestWaitForStateCompletion( StateId: ptr.Any("S2"), WaitTimeSeconds: iwfidl.PtrInt32(30), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equal(200, httpResp.StatusCode) // read httpResp body @@ -105,7 +105,7 @@ func doTestWaitForStateCompletion( startReq.WaitForCompletionStateExecutionIds = []string{"S1-1"} _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) req := apiClient.DefaultApi.ApiV1WorkflowWaitForStateCompletionPost(context.Background()) _, httpResp, err = req.WorkflowWaitForStateCompletionRequest( @@ -114,7 +114,7 @@ func doTestWaitForStateCompletion( StateExecutionId: ptr.Any("S1-1"), WaitTimeSeconds: iwfidl.PtrInt32(30), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equal(200, httpResp.StatusCode) // read httpResp body @@ -131,7 +131,7 @@ func doTestWaitForStateCompletion( _, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, data := wfHandler.GetTestResult() assertions.Equalf(map[string]int64{ diff --git a/integ/wait_until_search_attributes_optimization_test.go b/integ/wait_until_search_attributes_optimization_test.go index 7e0f9038..d8d59306 100644 --- a/integ/wait_until_search_attributes_optimization_test.go +++ b/integ/wait_until_search_attributes_optimization_test.go @@ -2,6 +2,7 @@ package integ import ( "context" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/wait_until_search_attributes_optimization" "github.com/indeedeng/iwf/service/common/ptr" "go.temporal.io/api/common/v1" @@ -48,7 +49,7 @@ func doTestWaitUntilHistoryCompleted( ) { assertions := assert.New(t) wfHandler := wait_until_search_attributes_optimization.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() uclient, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ @@ -78,7 +79,7 @@ func doTestWaitUntilHistoryCompleted( }, } _, httpResp, err := reqStart.WorkflowStartRequest(wfReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(time.Second * 5) @@ -94,19 +95,19 @@ func doTestWaitUntilHistoryCompleted( SignalValue: &signalValue, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) _, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for workflow to complete resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t) api := uclient.GetApiService().(workflowservice.WorkflowServiceClient) reqHistory := &workflowservice.GetWorkflowExecutionHistoryRequest{ @@ -117,7 +118,7 @@ func doTestWaitUntilHistoryCompleted( } eventHistory, err := api.GetWorkflowExecutionHistory(context.Background(), reqHistory) if err != nil { - panic("couldn't load eventHistory") + helpers.FailTestWithErrorMessage("couldn't load eventHistory", t) } var upsertSAEvents []*history.HistoryEvent diff --git a/integ/wait_until_search_attributes_test.go b/integ/wait_until_search_attributes_test.go index a65ae6e7..64060c88 100644 --- a/integ/wait_until_search_attributes_test.go +++ b/integ/wait_until_search_attributes_test.go @@ -43,7 +43,7 @@ func doTestWaitUntilSearchAttributes( ) { assertions := assert.New(t) wfHandler := wait_until_search_attributes.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ @@ -73,32 +73,32 @@ func doTestWaitUntilSearchAttributes( }, } _, httpResp, err := reqStart.WorkflowStartRequest(wfReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the search attribute index to be ready in ElasticSearch time.Sleep(time.Duration(*searchWaitTimeIntegTest) * time.Millisecond) switch mode := config.GetExecutingStateIdMode(); mode { case iwfidl.ENABLED_FOR_ALL: - 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), 1, apiClient, assertions) + assertSearch(t, fmt.Sprintf("WorkflowId='%v'", wfId), 1, apiClient, assertions) + assertSearch(t, 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) - assertSearch(fmt.Sprintf("WorkflowId='%v' AND %v='%v'", wfId, wait_until_search_attributes.TestSearchAttributeExecutingStateIdsKey, wait_until_search_attributes.State2), 0, apiClient, assertions) + assertSearch(t, fmt.Sprintf("WorkflowId='%v'", wfId), 1, apiClient, assertions) + assertSearch(t, 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) + assertSearch(t, fmt.Sprintf("WorkflowId='%v'", wfId), 1, apiClient, assertions) + assertSearch(t, fmt.Sprintf("WorkflowId='%v' AND %v='%v'", wfId, wait_until_search_attributes.TestSearchAttributeExecutingStateIdsKey, wait_until_search_attributes.State2), 0, apiClient, assertions) } reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) _, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for workflow to complete resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp) + failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t) } diff --git a/integ/wf_force_fail_test.go b/integ/wf_force_fail_test.go index d8b0ecde..0599da68 100644 --- a/integ/wf_force_fail_test.go +++ b/integ/wf_force_fail_test.go @@ -39,7 +39,7 @@ func TestWorkflowForceFailCadence(t *testing.T) { func doTestWorkflowForceFail(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := wf_force_fail.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -65,14 +65,14 @@ func doTestWorkflowForceFail(t *testing.T, backendType service.BackendType, conf WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions := assert.New(t) diff --git a/integ/wf_ignore_already_started_test.go b/integ/wf_ignore_already_started_test.go index d38b3e53..3ebebdc2 100644 --- a/integ/wf_ignore_already_started_test.go +++ b/integ/wf_ignore_already_started_test.go @@ -91,7 +91,7 @@ func TestIgnoreAlreadyStartedWorkflowCadence(t *testing.T) { func doIgnoreAlreadyStartedWorkflow(t *testing.T, backendType service.BackendType, firstReqConfig *iwfidl.WorkflowAlreadyStartedOptions, secondReqConfig *iwfidl.WorkflowAlreadyStartedOptions, errorExpected bool) { // start test workflow server wfHandler := wf_ignore_already_started.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() _, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ @@ -113,7 +113,7 @@ func doIgnoreAlreadyStartedWorkflow(t *testing.T, backendType service.BackendTyp firstReq := createReq(wfId, firstReqConfig) firstRes, firstHttpResp, err := req.WorkflowStartRequest(firstReq).Execute() - panicAtHttpError(err, firstHttpResp) + failTestAtHttpError(err, firstHttpResp, t) secondReq := createReq(wfId, secondReqConfig) secondRes, secondHttpResp, err := req.WorkflowStartRequest(secondReq).Execute() @@ -135,6 +135,13 @@ func doIgnoreAlreadyStartedWorkflow(t *testing.T, backendType service.BackendTyp assertions.Equal(firstRes.GetWorkflowRunId(), secondRes.GetWorkflowRunId()) assertions.Equal(200, secondHttpResp.StatusCode) } + + // Terminate the workflow once tests completed + stopReq := apiClient.DefaultApi.ApiV1WorkflowStopPost(context.Background()) + _, err = stopReq.WorkflowStopRequest(iwfidl.WorkflowStopRequest{ + WorkflowId: wfId, + StopType: iwfidl.TERMINATE.Ptr(), + }).Execute() } func createReq(wfId string, options *iwfidl.WorkflowAlreadyStartedOptions) iwfidl.WorkflowStartRequest { diff --git a/integ/wf_state_api_fail_test.go b/integ/wf_state_api_fail_test.go index 26e3cd14..4d4b0030 100644 --- a/integ/wf_state_api_fail_test.go +++ b/integ/wf_state_api_fail_test.go @@ -40,7 +40,7 @@ func TestStateApiFailCadence(t *testing.T) { func doTestStateApiFail(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := wf_state_api_fail.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -71,14 +71,14 @@ func doTestStateApiFail(t *testing.T, backendType service.BackendType, config *i WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, _ := wfHandler.GetTestResult() assertions := assert.New(t) diff --git a/integ/wf_state_api_timeout_test.go b/integ/wf_state_api_timeout_test.go index 5e76cbf4..6302c282 100644 --- a/integ/wf_state_api_timeout_test.go +++ b/integ/wf_state_api_timeout_test.go @@ -40,7 +40,7 @@ func TestStateApiTimeoutCadence(t *testing.T) { func doTestStateApiTimeout(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := wf_state_api_timeout.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -72,14 +72,14 @@ func doTestStateApiTimeout(t *testing.T, backendType service.BackendType, config WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, _ := wfHandler.GetTestResult() assertions := assert.New(t) diff --git a/integ/wf_state_execute_api_fail_and_proceed_test.go b/integ/wf_state_execute_api_fail_and_proceed_test.go index 177f7909..4081b9a1 100644 --- a/integ/wf_state_execute_api_fail_and_proceed_test.go +++ b/integ/wf_state_execute_api_fail_and_proceed_test.go @@ -40,7 +40,7 @@ func TestStateExecuteApiFailAndProceedCadence(t *testing.T) { func doTestStateExecuteApiFailAndProceed(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := wf_execute_api_fail_and_proceed.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -84,14 +84,14 @@ func doTestStateExecuteApiFailAndProceed(t *testing.T, backendType service.Backe Encoding: ptr.Any(wf_execute_api_fail_and_proceed.InputDataEncoding), }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, _ := wfHandler.GetTestResult() assertions := assert.New(t) diff --git a/integ/wf_state_options_data_attributes_loading_test.go b/integ/wf_state_options_data_attributes_loading_test.go index ecc63a79..3cb7e477 100644 --- a/integ/wf_state_options_data_attributes_loading_test.go +++ b/integ/wf_state_options_data_attributes_loading_test.go @@ -40,7 +40,7 @@ func doTestWfStateOptionsDataAttributesLoading( assertions := assert.New(t) wfHandler := wf_state_options_data_attributes_loading.NewHandler() - closeFunc1 := startWorkflowWorkerWithRpc(wfHandler) + closeFunc1 := startWorkflowWorkerWithRpc(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) defer closeFunc2() @@ -72,7 +72,7 @@ func doTestWfStateOptionsDataAttributesLoading( } _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(time.Second * 2) diff --git a/integ/wf_state_options_search_attributes_loading_test.go b/integ/wf_state_options_search_attributes_loading_test.go index 1b338b9b..2ac659b5 100644 --- a/integ/wf_state_options_search_attributes_loading_test.go +++ b/integ/wf_state_options_search_attributes_loading_test.go @@ -40,7 +40,7 @@ func doTestWfStateOptionsSearchAttributesLoading( assertions := assert.New(t) wfHandler := wf_state_options_search_attributes_loading.NewHandler() - closeFunc1 := startWorkflowWorkerWithRpc(wfHandler) + closeFunc1 := startWorkflowWorkerWithRpc(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) defer closeFunc2() @@ -72,7 +72,7 @@ func doTestWfStateOptionsSearchAttributesLoading( } _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) time.Sleep(time.Second * 2) diff --git a/integ/wf_state_wait_until_api_fail_and_proceed_test.go b/integ/wf_state_wait_until_api_fail_and_proceed_test.go index 45140c72..d2968a44 100644 --- a/integ/wf_state_wait_until_api_fail_and_proceed_test.go +++ b/integ/wf_state_wait_until_api_fail_and_proceed_test.go @@ -40,7 +40,7 @@ func TestStateApiFailAndProceedCadence(t *testing.T) { func doTestStateApiFailAndProceed(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := wf_state_api_fail_and_proceed.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -83,14 +83,14 @@ func doTestStateApiFailAndProceed(t *testing.T, backendType service.BackendType, WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) history, _ := wfHandler.GetTestResult() assertions := assert.New(t) diff --git a/integ/wf_stop_test.go b/integ/wf_stop_test.go index dd2c8586..45f64a9b 100644 --- a/integ/wf_stop_test.go +++ b/integ/wf_stop_test.go @@ -60,7 +60,7 @@ func TestWorkflowCanceledCadence(t *testing.T) { func doTestWorkflowCanceled(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := signal.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -86,21 +86,21 @@ func doTestWorkflowCanceled(t *testing.T, backendType service.BackendType, confi WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqCancel := apiClient.DefaultApi.ApiV1WorkflowStopPost(context.Background()) httpResp, err = reqCancel.WorkflowStopRequest(iwfidl.WorkflowStopRequest{ WorkflowId: wfId, StopType: iwfidl.CANCEL.Ptr(), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions := assert.New(t) @@ -115,7 +115,7 @@ func doTestWorkflowCanceled(t *testing.T, backendType service.BackendType, confi func doTestWorkflowTerminated(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := signal.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -142,7 +142,7 @@ func doTestWorkflowTerminated(t *testing.T, backendType service.BackendType, con }, } startResp, httpResp, err := req.WorkflowStartRequest(request).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions := assert.New(t) // start it again should return already started error @@ -152,27 +152,27 @@ func doTestWorkflowTerminated(t *testing.T, backendType service.BackendType, con // using terminate if running should go through request.WorkflowStartOptions.WorkflowIDReusePolicy = iwfidl.TERMINATE_IF_RUNNING.Ptr() _, httpResp, err = req.WorkflowStartRequest(request).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // using the compatibility request.WorkflowStartOptions.WorkflowIDReusePolicy = nil request.WorkflowStartOptions.IdReusePolicy = iwfidl.ALLOW_TERMINATE_IF_RUNNING.Ptr() startResp, httpResp, err = req.WorkflowStartRequest(request).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqCancel := apiClient.DefaultApi.ApiV1WorkflowStopPost(context.Background()) httpResp, err = reqCancel.WorkflowStopRequest(iwfidl.WorkflowStopRequest{ WorkflowId: wfId, StopType: iwfidl.TERMINATE.Ptr(), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions.Equalf(&iwfidl.WorkflowGetResponse{ WorkflowRunId: startResp.GetWorkflowRunId(), @@ -185,7 +185,7 @@ func doTestWorkflowTerminated(t *testing.T, backendType service.BackendType, con func doTestWorkflowFail(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := signal.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -211,7 +211,7 @@ func doTestWorkflowFail(t *testing.T, backendType service.BackendType, config *i WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) reqCancel := apiClient.DefaultApi.ApiV1WorkflowStopPost(context.Background()) httpResp, err = reqCancel.WorkflowStopRequest(iwfidl.WorkflowStopRequest{ @@ -219,14 +219,14 @@ func doTestWorkflowFail(t *testing.T, backendType service.BackendType, config *i StopType: iwfidl.FAIL.Ptr(), Reason: iwfidl.PtrString("fail reason"), }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions := assert.New(t) diff --git a/integ/wf_timeout_test.go b/integ/wf_timeout_test.go index 6d2ff28b..b068936d 100644 --- a/integ/wf_timeout_test.go +++ b/integ/wf_timeout_test.go @@ -39,7 +39,7 @@ func TestWorkflowTimeoutadence(t *testing.T) { func doTestWorkflowTimeout(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { // start test workflow server wfHandler := signal.NewHandler() - closeFunc1 := startWorkflowWorker(wfHandler) + closeFunc1 := startWorkflowWorker(wfHandler, t) defer closeFunc1() closeFunc2 := startIwfService(backendType) @@ -65,14 +65,14 @@ func doTestWorkflowTimeout(t *testing.T, backendType service.BackendType, config WorkflowConfigOverride: config, }, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) // wait for the workflow reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) resp, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ WorkflowId: wfId, }).Execute() - panicAtHttpError(err, httpResp) + failTestAtHttpError(err, httpResp, t) assertions := assert.New(t) diff --git a/integ/workflow/any_command_close/routers.go b/integ/workflow/any_command_close/routers.go index 3b00cbd5..c7ca3675 100644 --- a/integ/workflow/any_command_close/routers.go +++ b/integ/workflow/any_command_close/routers.go @@ -8,6 +8,7 @@ import ( "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" + "testing" ) /** @@ -41,7 +42,7 @@ func NewHandler() common.WorkflowHandler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -85,7 +86,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/any_command_combination/routers.go b/integ/workflow/any_command_combination/routers.go index fc497198..dd58ced9 100644 --- a/integ/workflow/any_command_combination/routers.go +++ b/integ/workflow/any_command_combination/routers.go @@ -3,11 +3,13 @@ package anycommandcombination import ( "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "github.com/indeedeng/iwf/service" "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" + "testing" "time" ) @@ -49,7 +51,7 @@ func NewHandler() common.WorkflowHandler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -179,11 +181,10 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { return } } - - panic("invalid workflow type") + helpers.FailTestWithErrorMessage("invalid workflow type", t) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { panic(err) @@ -223,7 +224,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { } } - panic("invalid workflow type") + helpers.FailTestWithErrorMessage("invalid workflow type", t) } func (h *handler) GetTestResult() (map[string]int64, map[string]interface{}) { diff --git a/integ/workflow/any_timer_signal/routers.go b/integ/workflow/any_timer_signal/routers.go index 00249b4b..d42f42aa 100644 --- a/integ/workflow/any_timer_signal/routers.go +++ b/integ/workflow/any_timer_signal/routers.go @@ -8,6 +8,7 @@ import ( "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" + "testing" "time" ) @@ -41,7 +42,7 @@ func NewHandler() common.WorkflowHandler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -95,7 +96,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/basic/routers.go b/integ/workflow/basic/routers.go index 6102ae2b..a1e6b01b 100644 --- a/integ/workflow/basic/routers.go +++ b/integ/workflow/basic/routers.go @@ -3,9 +3,11 @@ package basic import ( "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/service" "log" "net/http" + "testing" ) /** @@ -35,7 +37,7 @@ func NewHandler() *handler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -45,7 +47,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { context := req.GetContext() if context.GetAttempt() <= 0 || context.GetFirstAttemptTimestamp() <= 0 { - panic("attempt and firstAttemptTimestamp should be greater than zero") + helpers.FailTestWithErrorMessage("attempt and firstAttemptTimestamp should be greater than zero", t) } if req.GetWorkflowType() == WorkflowType { @@ -64,7 +66,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -73,7 +75,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { log.Println("received state decide request, ", req) context := req.GetContext() if context.GetAttempt() <= 0 || context.GetFirstAttemptTimestamp() <= 0 { - panic("attempt and firstAttemptTimestamp should be greater than zero") + helpers.FailTestWithErrorMessage("attempt and firstAttemptTimestamp should be greater than zero", t) } if req.GetWorkflowType() == WorkflowType { diff --git a/integ/workflow/common/interfaces.go b/integ/workflow/common/interfaces.go index 78d8c93d..1d34078b 100644 --- a/integ/workflow/common/interfaces.go +++ b/integ/workflow/common/interfaces.go @@ -1,14 +1,17 @@ package common -import "github.com/gin-gonic/gin" +import ( + "github.com/gin-gonic/gin" + "testing" +) type WorkflowHandler interface { - ApiV1WorkflowStateStart(c *gin.Context) - ApiV1WorkflowStateDecide(c *gin.Context) + ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) + ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) GetTestResult() (map[string]int64, map[string]interface{}) } type WorkflowHandlerWithRpc interface { WorkflowHandler - ApiV1WorkflowWorkerRpc(c *gin.Context) + ApiV1WorkflowWorkerRpc(c *gin.Context, t *testing.T) } diff --git a/integ/workflow/conditional_close/routers.go b/integ/workflow/conditional_close/routers.go index 3d4f06d1..6b6e008e 100644 --- a/integ/workflow/conditional_close/routers.go +++ b/integ/workflow/conditional_close/routers.go @@ -3,10 +3,12 @@ package conditional_close import ( "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" + "testing" "time" ) @@ -44,7 +46,7 @@ func NewHandler() common.WorkflowHandlerWithRpc { } } -func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { +func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowWorkerRpcRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -64,7 +66,7 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { } // ApiV1WorkflowStateStart - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -106,10 +108,10 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { } } - panic("error request") + helpers.FailTestWithErrorMessage("error request", t) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -168,7 +170,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { } } - panic("error request") + helpers.FailTestWithErrorMessage("error request", t) } func (h *handler) GetTestResult() (map[string]int64, map[string]interface{}) { diff --git a/integ/workflow/deadend/routers.go b/integ/workflow/deadend/routers.go index 68709ecc..257b01ba 100644 --- a/integ/workflow/deadend/routers.go +++ b/integ/workflow/deadend/routers.go @@ -1,12 +1,15 @@ package deadend import ( + "fmt" "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "github.com/indeedeng/iwf/service" "log" "net/http" + "testing" ) /** @@ -40,7 +43,7 @@ func NewHandler() common.WorkflowHandlerWithRpc { } } -func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { +func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowWorkerRpcRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -50,10 +53,10 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { wfCtx := req.Context if wfCtx.WorkflowId == "" || wfCtx.WorkflowRunId == "" { - panic("invalid context in the request") + helpers.FailTestWithErrorMessage("invalid context in the request", t) } if req.WorkflowType != WorkflowType { - panic("invalid workflow type") + helpers.FailTestWithErrorMessage("invalid workflow type", t) } if req.RpcName == RPCTriggerState { @@ -82,16 +85,16 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { }, }) } else { - panic("invalid rpc name:" + req.RpcName) + helpers.FailTestWithErrorMessage(fmt.Sprintf("invalid rpc name: %s", req.RpcName), t) } } // ApiV1WorkflowStateStart - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { - panic("should not be called") +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { + helpers.FailTestWithErrorMessage("should not be called", t) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/headers/routers.go b/integ/workflow/headers/routers.go index 1a2bab70..f4b5d6c2 100644 --- a/integ/workflow/headers/routers.go +++ b/integ/workflow/headers/routers.go @@ -6,6 +6,7 @@ import ( "github.com/indeedeng/iwf/service" "log" "net/http" + "testing" ) /** @@ -34,7 +35,7 @@ func NewHandler() *handler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { headerValue := c.GetHeader(TestHeaderKey) if headerValue != TestHeaderValue { c.JSON(http.StatusBadRequest, gin.H{"error": "test header not found"}) @@ -64,7 +65,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { headerValue := c.GetHeader(TestHeaderKey) if headerValue != TestHeaderValue { c.JSON(http.StatusBadRequest, gin.H{"error": "test header not found"}) diff --git a/integ/workflow/interstate/routers.go b/integ/workflow/interstate/routers.go index f72b303f..d0476afc 100644 --- a/integ/workflow/interstate/routers.go +++ b/integ/workflow/interstate/routers.go @@ -7,6 +7,7 @@ import ( "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" + "testing" "time" ) @@ -60,7 +61,7 @@ func NewHandler() *handler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -133,7 +134,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/locking/routers.go b/integ/workflow/locking/routers.go index 5ccb6c17..7ab9abdb 100644 --- a/integ/workflow/locking/routers.go +++ b/integ/workflow/locking/routers.go @@ -4,12 +4,14 @@ import ( "fmt" "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "github.com/indeedeng/iwf/service" "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" "strconv" + "testing" "time" ) @@ -99,7 +101,7 @@ func NewHandler() common.WorkflowHandlerWithRpc { } } -func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { +func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowWorkerRpcRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -108,12 +110,12 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { log.Println("received workflow worker rpc request, ", req) if req.WorkflowType != WorkflowType || (req.RpcName != RPCName) { - panic("invalid rpc name:" + req.RpcName) + helpers.FailTestWithErrorMessage(fmt.Sprintf("invalid rpc name: %s", req.RpcName), t) } input := req.Input if input.GetEncoding() != TestValue.GetEncoding() { - panic("input is incorrect") + helpers.FailTestWithErrorMessage("input is incorrect", t) } // Publish to internal channel @@ -132,12 +134,13 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { signalChannelInfo := (*req.SignalChannelInfos)[UnusedSignalChannelName] if signalChannelInfo.GetSize() != NumUnusedSignals { // the 4 messages are sent from the beginning of "locking_test" - panic("incorrect signal channel size") + helpers.FailTestWithErrorMessage("incorrect signal channel size", t) } + if h.rpcInvokes > 0 { internalChannelInfo := (*req.InternalChannelInfos)[UnusedInternalChannelName] if h.rpcInvokes != internalChannelInfo.GetSize() { - panic("incorrect internal channel size") + helpers.FailTestWithErrorMessage("incorrect internal channel size", t) } } h.rpcInvokes++ @@ -175,7 +178,7 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { if data != "" { i, err := strconv.ParseInt(data, 10, 32) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } daInt = int(i) } @@ -225,7 +228,7 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { } // ApiV1WorkflowStateStart - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -300,7 +303,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -354,7 +357,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { if data != "" { i, err := strconv.ParseInt(data, 10, 32) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } daInt = int(i) } diff --git a/integ/workflow/parallel/routers.go b/integ/workflow/parallel/routers.go index 520310cf..adb24162 100644 --- a/integ/workflow/parallel/routers.go +++ b/integ/workflow/parallel/routers.go @@ -7,6 +7,7 @@ import ( "github.com/indeedeng/iwf/service" "log" "net/http" + "testing" "time" ) @@ -61,7 +62,7 @@ func NewHandler() common.WorkflowHandler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -84,7 +85,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/persistence/routers.go b/integ/workflow/persistence/routers.go index 9d58e7dc..01889e75 100644 --- a/integ/workflow/persistence/routers.go +++ b/integ/workflow/persistence/routers.go @@ -3,11 +3,13 @@ package persistence import ( "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "github.com/indeedeng/iwf/service" "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" + "testing" ) /** @@ -74,7 +76,7 @@ func NewHandler() common.WorkflowHandler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -84,12 +86,12 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { initSas := req.GetSearchAttributes() if len(initSas) < 1 { - panic("should have at least one init search attribute") + helpers.FailTestWithErrorMessage("should have at least one init search attribute", t) } for _, sa := range initSas { if sa.GetKey() == "CustomDatetimeField" { if sa.GetValueType() != iwfidl.DATETIME { - panic("key and value type not match") + helpers.FailTestWithErrorMessage("key and value type not match", t) } } } @@ -169,7 +171,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { queryAttFound = true } if queryAtt.GetKey() == TestDataObjectKey2 { - panic("should not load key that is not included in partial loading") + helpers.FailTestWithErrorMessage("should not load key that is not included in partial loading", t) } } h.invokeData["S2_start_queryAttFound"] = queryAttFound @@ -189,7 +191,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { found := false for _, sa := range sas { if sa.GetKey() == TestSearchAttributeKeywordKey { - panic("should not load key that is not included in partial loading") + helpers.FailTestWithErrorMessage("should not load key that is not included in partial loading", t) } if sa.GetKey() == TestSearchAttributeIntKey && sa.GetIntegerValue() == TestSearchAttributeIntValue2 && sa.GetValueType() == iwfidl.INT { @@ -197,7 +199,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { } } if !found { - panic("should see the requested partial loading key") + helpers.FailTestWithErrorMessage("should see the requested partial loading key", t) } queryAttFound := 0 @@ -211,7 +213,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { } } if queryAttFound != 2 { - panic("missing query attribute requested by partial loading keys") + helpers.FailTestWithErrorMessage("missing query attribute requested by partial loading keys", t) } // Go straight to the decide methods without any commands @@ -227,7 +229,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -356,7 +358,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { queryAttFound = true } if queryAtt.GetKey() == TestDataObjectKey2 { - panic("should not load key that is not included in partial loading") + helpers.FailTestWithErrorMessage("should not load key that is not included in partial loading", t) } } @@ -395,7 +397,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { found := false for _, sa := range sas { if sa.GetKey() == TestSearchAttributeKeywordKey { - panic("should not load key that is not included in partial loading") + helpers.FailTestWithErrorMessage("should not load key that is not included in partial loading", t) } if sa.GetKey() == TestSearchAttributeIntKey && sa.GetIntegerValue() == TestSearchAttributeIntValue2 && sa.GetValueType() == iwfidl.INT { @@ -403,7 +405,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { } } if !found { - panic("should see the requested partial loading key") + helpers.FailTestWithErrorMessage("should see the requested partial loading key", t) } queryAttFound := 0 @@ -419,7 +421,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { } } if queryAttFound != 2 { - panic("missing query attribute requested by partial loading keys") + helpers.FailTestWithErrorMessage("missing query attribute requested by partial loading keys", t) } // Move to completion diff --git a/integ/workflow/persistence_loading_policy/routers.go b/integ/workflow/persistence_loading_policy/routers.go index 8db274d6..ee32f7f5 100644 --- a/integ/workflow/persistence_loading_policy/routers.go +++ b/integ/workflow/persistence_loading_policy/routers.go @@ -3,6 +3,7 @@ package persistence_loading_policy import ( "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "github.com/indeedeng/iwf/integ/workflow/persistence" "github.com/indeedeng/iwf/service" @@ -10,6 +11,7 @@ import ( "github.com/stretchr/testify/assert" "log" "net/http" + "testing" ) /** @@ -39,7 +41,7 @@ func NewHandler() common.WorkflowHandlerWithRpc { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -59,7 +61,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { loadingTypeFromInput := req.GetStateInput() loadingType := iwfidl.PersistenceLoadingType(loadingTypeFromInput.GetData()) - verifyLoadedAttributes(req.GetSearchAttributes(), req.GetDataObjects(), loadingType) + verifyLoadedAttributes(t, req.GetSearchAttributes(), req.GetDataObjects(), loadingType) } // Go straight to the decide methods without any commands @@ -70,7 +72,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { }) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -90,7 +92,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { loadingType := iwfidl.PersistenceLoadingType(loadingTypeFromInput.GetData()) if req.GetWorkflowStateId() == State2 { - verifyLoadedAttributes(req.GetSearchAttributes(), req.GetDataObjects(), loadingType) + verifyLoadedAttributes(t, req.GetSearchAttributes(), req.GetDataObjects(), loadingType) } var upsertSearchAttributes []iwfidl.SearchAttribute @@ -144,7 +146,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { }) } -func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { +func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowWorkerRpcRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -163,7 +165,7 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { loadingTypeFromInput := req.GetInput() loadingType := iwfidl.PersistenceLoadingType(loadingTypeFromInput.GetData()) - verifyLoadedAttributes(req.GetSearchAttributes(), req.GetDataAttributes(), loadingType) + verifyLoadedAttributes(t, req.GetSearchAttributes(), req.GetDataAttributes(), loadingType) c.JSON(http.StatusOK, iwfidl.WorkflowWorkerRpcResponse{ StateDecision: getStateDecision(State2, loadingTypeFromInput, loadingType), @@ -176,6 +178,7 @@ func (h *handler) GetTestResult() (map[string]int64, map[string]interface{}) { } func verifyLoadedAttributes( + t *testing.T, searchAttributes []iwfidl.SearchAttribute, dataAttributes []iwfidl.KeyValue, loadingType iwfidl.PersistenceLoadingType) { @@ -237,11 +240,11 @@ func verifyLoadedAttributes( // use ElementsMatch so that the order won't be a problem. // Internally the SAs are stored as a map and as a result, Golang return it without ordering guarantee if !assert.ElementsMatch(common.DummyT{}, expectedSearchAttributes, searchAttributes) { - panic("Search attributes should be the same") + helpers.FailTestWithErrorMessage("Search attributes should be the same", t) } if !assert.ElementsMatch(common.DummyT{}, expectedDataAttributes, dataAttributes) { - panic("Data attributes should be the same") + helpers.FailTestWithErrorMessage("Data attributes should be the same", t) } } diff --git a/integ/workflow/reset/routers.go b/integ/workflow/reset/routers.go index cdd4a642..e785ed99 100644 --- a/integ/workflow/reset/routers.go +++ b/integ/workflow/reset/routers.go @@ -4,10 +4,12 @@ import ( "fmt" "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/service" "log" "net/http" "strconv" + "testing" ) /** @@ -37,11 +39,11 @@ func NewHandler() *handler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { - panic("No start call is expected.") +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { + helpers.FailTestWithErrorMessage("No start call is expected.", t) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { log.Println("start of decide") var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { @@ -51,7 +53,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { log.Println("received state decide request, ", req) context := req.GetContext() if context.GetAttempt() <= 0 || context.GetFirstAttemptTimestamp() <= 0 { - panic("attempt and firstAttemptTimestamp should be greater than zero") + helpers.FailTestWithErrorMessage("attempt and firstAttemptTimestamp should be greater than zero", t) } if req.GetWorkflowType() == WorkflowType { diff --git a/integ/workflow/rpc/routers.go b/integ/workflow/rpc/routers.go index b27a4012..7d3e7784 100644 --- a/integ/workflow/rpc/routers.go +++ b/integ/workflow/rpc/routers.go @@ -1,13 +1,16 @@ package rpc import ( + "fmt" "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "github.com/indeedeng/iwf/service" "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" + "testing" ) /** @@ -86,7 +89,7 @@ var TestInterstateChannelValue = iwfidl.EncodedObject{ Data: iwfidl.PtrString("test-interstatechannel-value"), } -func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { +func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowWorkerRpcRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -96,11 +99,11 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { wfCtx := req.Context if wfCtx.WorkflowId == "" || wfCtx.WorkflowRunId == "" { - panic("invalid context in the request") + helpers.FailTestWithErrorMessage("invalid context in the request", t) } if req.WorkflowType != WorkflowType || (req.RpcName != RPCName && req.RpcName != RPCNameReadOnly && req.RpcName != RPCNameError) { - panic("invalid rpc name:" + req.RpcName) + helpers.FailTestWithErrorMessage(fmt.Sprintf("invalid rpc name: %s", req.RpcName), t) } h.invokeData[req.RpcName+"-input"] = req.Input @@ -165,7 +168,7 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -228,7 +231,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -242,7 +245,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { commandRes := req.GetCommandResults() res := commandRes.GetInterStateChannelResults()[0] if res.GetRequestStatus() != iwfidl.RECEIVED || res.GetChannelName() != TestInterStateChannelName { - panic("the signal should be received") + helpers.FailTestWithErrorMessage("the signal should be received", t) } h.invokeData[TestInterStateChannelName] = res.Value diff --git a/integ/workflow/signal/routers.go b/integ/workflow/signal/routers.go index 1c39c5b7..7ca8d11e 100644 --- a/integ/workflow/signal/routers.go +++ b/integ/workflow/signal/routers.go @@ -5,11 +5,13 @@ import ( "fmt" "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "github.com/indeedeng/iwf/service" "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" + "testing" ) /** @@ -44,7 +46,7 @@ type handler struct { invokeData map[string]interface{} } -func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { +func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowWorkerRpcRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -54,7 +56,7 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { signalInfos := req.SignalChannelInfos data, err := json.Marshal(signalInfos) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } c.JSON(http.StatusOK, iwfidl.WorkflowWorkerRpcResponse{ PublishToInterStateChannel: []iwfidl.InterStateChannelPublishing{ @@ -72,7 +74,7 @@ func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { icInfos := req.InternalChannelInfos data, err := json.Marshal(icInfos) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } c.JSON(http.StatusOK, iwfidl.WorkflowWorkerRpcResponse{ Output: &iwfidl.EncodedObject{ @@ -93,7 +95,7 @@ func NewHandler() common.WorkflowHandlerWithRpc { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -142,7 +144,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/skipstart/routers.go b/integ/workflow/skipstart/routers.go index 3b9b4056..c9e0a910 100644 --- a/integ/workflow/skipstart/routers.go +++ b/integ/workflow/skipstart/routers.go @@ -3,9 +3,11 @@ package skipstart import ( "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/service" "log" "net/http" + "testing" ) /** @@ -35,11 +37,11 @@ func NewHandler() *handler { } // ApiV1WorkflowStateStart - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { - panic("start API should be skipped") +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { + helpers.FailTestWithErrorMessage("start API should be skipped", t) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/timer/routers.go b/integ/workflow/timer/routers.go index d324dadc..4b3c76b6 100644 --- a/integ/workflow/timer/routers.go +++ b/integ/workflow/timer/routers.go @@ -1,10 +1,12 @@ package timer import ( + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" "strconv" + "testing" "time" "github.com/gin-gonic/gin" @@ -42,7 +44,7 @@ func NewHandler() common.WorkflowHandler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -55,7 +57,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { if req.GetWorkflowStateId() == State1 { nowInt, err := strconv.Atoi(req.StateInput.GetData()) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } now := int64(nowInt) h.invokeData["scheduled_at"] = now @@ -97,7 +99,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/wait_for_state_completion/routers.go b/integ/workflow/wait_for_state_completion/routers.go index 41b8c19b..10fb7f5a 100644 --- a/integ/workflow/wait_for_state_completion/routers.go +++ b/integ/workflow/wait_for_state_completion/routers.go @@ -1,10 +1,12 @@ package wait_for_state_completion import ( + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" "strconv" + "testing" "time" "github.com/gin-gonic/gin" @@ -42,7 +44,7 @@ func NewHandler() common.WorkflowHandler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -55,7 +57,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { if req.GetWorkflowStateId() == State1 { nowInt, err := strconv.Atoi(req.StateInput.GetData()) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } now := int64(nowInt) h.invokeData["scheduled_at"] = now @@ -88,7 +90,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/wait_until_search_attributes/routers.go b/integ/workflow/wait_until_search_attributes/routers.go index f4ce6866..1954ea6f 100644 --- a/integ/workflow/wait_until_search_attributes/routers.go +++ b/integ/workflow/wait_until_search_attributes/routers.go @@ -7,6 +7,7 @@ import ( "github.com/indeedeng/iwf/service" "log" "net/http" + "testing" "time" ) @@ -40,7 +41,7 @@ func NewHandler() common.WorkflowHandler { } } -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -73,7 +74,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/wait_until_search_attributes_optimization/routers.go b/integ/workflow/wait_until_search_attributes_optimization/routers.go index 67c32cc6..296123c9 100644 --- a/integ/workflow/wait_until_search_attributes_optimization/routers.go +++ b/integ/workflow/wait_until_search_attributes_optimization/routers.go @@ -8,6 +8,7 @@ import ( "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" + "testing" "time" ) @@ -59,7 +60,7 @@ func NewHandler() common.WorkflowHandler { } } -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -99,7 +100,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/wf_execute_api_fail_and_proceed/routers.go b/integ/workflow/wf_execute_api_fail_and_proceed/routers.go index 6ec3a201..2b7be978 100644 --- a/integ/workflow/wf_execute_api_fail_and_proceed/routers.go +++ b/integ/workflow/wf_execute_api_fail_and_proceed/routers.go @@ -1,9 +1,11 @@ package wf_execute_api_fail_and_proceed import ( + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/service" "log" "net/http" + "testing" "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" @@ -39,11 +41,11 @@ func NewHandler() common.WorkflowHandler { } } -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { - panic("should not get here") +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { + helpers.FailTestWithErrorMessage("should not get here", t) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -59,7 +61,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { if input.GetData() == InputData && input.GetEncoding() == InputDataEncoding { c.JSON(http.StatusBadRequest, map[string]string{"error": "test-error"}) } else { - panic("input is not correct: " + input.GetData() + ", " + input.GetEncoding()) + helpers.FailTestWithErrorMessage("input is not correct: "+input.GetData()+", "+input.GetEncoding(), t) } return @@ -77,12 +79,12 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { }, }) } else { - panic("input is not correct: " + input.GetData() + ", " + input.GetEncoding()) + helpers.FailTestWithErrorMessage("input is not correct: "+input.GetData()+", "+input.GetEncoding(), t) } return } - panic("should not get here") + helpers.FailTestWithErrorMessage("should not get here", t) } func (h *handler) GetTestResult() (map[string]int64, map[string]interface{}) { diff --git a/integ/workflow/wf_force_fail/routers.go b/integ/workflow/wf_force_fail/routers.go index 107cbce7..286354fa 100644 --- a/integ/workflow/wf_force_fail/routers.go +++ b/integ/workflow/wf_force_fail/routers.go @@ -3,10 +3,12 @@ package wf_force_fail import ( "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "github.com/indeedeng/iwf/service" "log" "net/http" + "testing" ) /** @@ -38,7 +40,7 @@ func NewHandler() common.WorkflowHandler { } } -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -58,7 +60,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { panic("should not get here") } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -82,7 +84,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { return } - panic("should not get here") + helpers.FailTestWithErrorMessage("should not get here", t) } func (h *handler) GetTestResult() (map[string]int64, map[string]interface{}) { diff --git a/integ/workflow/wf_ignore_already_started/routers.go b/integ/workflow/wf_ignore_already_started/routers.go index 0183ae6e..3f0b58a9 100644 --- a/integ/workflow/wf_ignore_already_started/routers.go +++ b/integ/workflow/wf_ignore_already_started/routers.go @@ -1,10 +1,12 @@ package wf_ignore_already_started import ( + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/service/common/ptr" "log" "net/http" "strconv" + "testing" "time" "github.com/gin-gonic/gin" @@ -36,7 +38,7 @@ func NewHandler() *handler { } // ApiV1WorkflowStartPost - for a workflow -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -49,7 +51,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { if req.GetWorkflowStateId() == State1 { nowInt, err := strconv.Atoi(req.StateInput.GetData()) if err != nil { - panic(err) + helpers.FailTestWithError(err, t) } now := int64(nowInt) h.invokeData["scheduled_at"] = now @@ -71,7 +73,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { c.JSON(http.StatusBadRequest, struct{}{}) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/integ/workflow/wf_state_api_fail/routers.go b/integ/workflow/wf_state_api_fail/routers.go index 10571fa1..f33f72a5 100644 --- a/integ/workflow/wf_state_api_fail/routers.go +++ b/integ/workflow/wf_state_api_fail/routers.go @@ -3,9 +3,11 @@ package wf_state_api_fail import ( "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "log" "net/http" + "testing" ) /** @@ -31,7 +33,7 @@ func NewHandler() common.WorkflowHandler { } } -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -48,11 +50,11 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { } } - panic("should not get here") + helpers.FailTestWithErrorMessage("should not get here", t) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { - panic("should not get here") +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { + helpers.FailTestWithErrorMessage("should not get here", t) } func (h *handler) GetTestResult() (map[string]int64, map[string]interface{}) { diff --git a/integ/workflow/wf_state_api_fail_and_proceed/routers.go b/integ/workflow/wf_state_api_fail_and_proceed/routers.go index 4109f2d8..e4a63560 100644 --- a/integ/workflow/wf_state_api_fail_and_proceed/routers.go +++ b/integ/workflow/wf_state_api_fail_and_proceed/routers.go @@ -1,9 +1,11 @@ package wf_state_api_fail_and_proceed import ( + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/service" "log" "net/http" + "testing" "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" @@ -33,7 +35,7 @@ func NewHandler() common.WorkflowHandler { } } -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -50,10 +52,10 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { } } - panic("should not get here") + helpers.FailTestWithErrorMessage("should not get here", t) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -62,7 +64,7 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { log.Println("received state decide request, ", req) if req.GetCommandResults().StateStartApiSucceeded == nil || *req.GetCommandResults().StateStartApiSucceeded { - panic("stateStartApiSucceeded should be false") + helpers.FailTestWithErrorMessage("stateStartApiSucceeded should be false", t) } if req.GetWorkflowType() == WorkflowType { diff --git a/integ/workflow/wf_state_api_timeout/routers.go b/integ/workflow/wf_state_api_timeout/routers.go index 09172f8e..0c849c38 100644 --- a/integ/workflow/wf_state_api_timeout/routers.go +++ b/integ/workflow/wf_state_api_timeout/routers.go @@ -1,11 +1,14 @@ package wf_state_api_timeout import ( + "fmt" "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "log" "net/http" + "testing" "time" ) @@ -33,7 +36,7 @@ func NewHandler() common.WorkflowHandler { } } -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -51,12 +54,14 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { return } } - - panic("should not get here") + fmt.Printf( + "WorkflowType: %v", req.GetWorkflowType(), + ) + helpers.FailTestWithErrorMessage("should not get here", t) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { - panic("should not get here") +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { + helpers.FailTestWithErrorMessage("should not get here", t) } func (h *handler) GetTestResult() (map[string]int64, map[string]interface{}) { diff --git a/integ/workflow/wf_state_options_data_attributes_loading/routers.go b/integ/workflow/wf_state_options_data_attributes_loading/routers.go index d765ed0a..b7210e53 100644 --- a/integ/workflow/wf_state_options_data_attributes_loading/routers.go +++ b/integ/workflow/wf_state_options_data_attributes_loading/routers.go @@ -3,11 +3,13 @@ package wf_state_options_data_attributes_loading import ( "github.com/gin-gonic/gin" "github.com/indeedeng/iwf/gen/iwfidl" + "github.com/indeedeng/iwf/integ/helpers" "github.com/indeedeng/iwf/integ/workflow/common" "github.com/indeedeng/iwf/service" "github.com/stretchr/testify/assert" "log" "net/http" + "testing" ) /** @@ -55,7 +57,7 @@ func NewHandler() common.WorkflowHandlerWithRpc { } } -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -76,11 +78,11 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { loadingType := iwfidl.PersistenceLoadingType(loadingTypeFromInput.GetData()) if req.GetWorkflowStateId() == State2 || req.GetWorkflowStateId() == State4 || req.GetWorkflowStateId() == State5 { - verifyLoadedDataAttributes(req.GetWorkflowStateId(), currentMethod, req.GetDataObjects(), loadingType) + verifyLoadedDataAttributes(t, req.GetWorkflowStateId(), currentMethod, req.GetDataObjects(), loadingType) } if req.GetWorkflowStateId() == State3 { - verifyEmptyDataAttributes(req.GetDataObjects()) + verifyEmptyDataAttributes(t, req.GetDataObjects()) } // Go straight to the decide methods without any commands @@ -91,7 +93,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { }) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -116,23 +118,23 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { case State1: response = getState1DecideResponse(req) case State2: - verifyEmptyDataAttributes(req.GetDataObjects()) + verifyEmptyDataAttributes(t, req.GetDataObjects()) response = getState2DecideResponse(req) case State3: - verifyLoadedDataAttributes(req.GetWorkflowStateId(), currentMethod, req.GetDataObjects(), loadingType) + verifyLoadedDataAttributes(t, req.GetWorkflowStateId(), currentMethod, req.GetDataObjects(), loadingType) response = getState3DecideResponse(req) case State4: - verifyLoadedDataAttributes(req.GetWorkflowStateId(), currentMethod, req.GetDataObjects(), loadingType) + verifyLoadedDataAttributes(t, req.GetWorkflowStateId(), currentMethod, req.GetDataObjects(), loadingType) response = getState4DecideResponse(req) case State5: - verifyLoadedDataAttributes(req.GetWorkflowStateId(), currentMethod, req.GetDataObjects(), loadingType) + verifyLoadedDataAttributes(t, req.GetWorkflowStateId(), currentMethod, req.GetDataObjects(), loadingType) response = getState5DecideResponse() } c.JSON(http.StatusOK, response) } -func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { +func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context, t *testing.T) { c.JSON(http.StatusBadRequest, struct{}{}) } @@ -254,17 +256,17 @@ func getState5DecideResponse() iwfidl.WorkflowStateDecideResponse { } } -func verifyEmptyDataAttributes(dataAttributes []iwfidl.KeyValue) { +func verifyEmptyDataAttributes(t *testing.T, dataAttributes []iwfidl.KeyValue) { var expectedDataAttributes []iwfidl.KeyValue if !assert.ElementsMatch(common.DummyT{}, expectedDataAttributes, dataAttributes) { - panic("Data attributes should be empty") + helpers.FailTestWithErrorMessage("Data attributes should be empty", t) } } -func verifyLoadedDataAttributes(stateId string, method string, dataAttributes []iwfidl.KeyValue, loadingType iwfidl.PersistenceLoadingType) { +func verifyLoadedDataAttributes(t *testing.T, stateId string, method string, dataAttributes []iwfidl.KeyValue, loadingType iwfidl.PersistenceLoadingType) { expectedDataAttributes := getExpectedDataAttributes(stateId, method, loadingType) if !assert.ElementsMatch(common.DummyT{}, expectedDataAttributes, dataAttributes) { - panic("Data attributes should be the same") + helpers.FailTestWithErrorMessage("Data attributes should be the same", t) } } diff --git a/integ/workflow/wf_state_options_search_attributes_loading/routers.go b/integ/workflow/wf_state_options_search_attributes_loading/routers.go index e3fe6575..97f8e6b5 100644 --- a/integ/workflow/wf_state_options_search_attributes_loading/routers.go +++ b/integ/workflow/wf_state_options_search_attributes_loading/routers.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "log" "net/http" + "testing" ) /** @@ -56,7 +57,7 @@ func NewHandler() common.WorkflowHandlerWithRpc { } } -func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateStartRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -77,11 +78,11 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { loadingType := iwfidl.PersistenceLoadingType(loadingTypeFromInput.GetData()) if req.GetWorkflowStateId() == State2 || req.GetWorkflowStateId() == State4 || req.GetWorkflowStateId() == State5 { - verifyLoadedSearchAttributes(req.GetWorkflowStateId(), currentMethod, req.GetSearchAttributes(), loadingType) + verifyLoadedSearchAttributes(t, req.GetWorkflowStateId(), currentMethod, req.GetSearchAttributes(), loadingType) } if req.GetWorkflowStateId() == State3 { - verifyEmptySearchAttributes(req.GetSearchAttributes()) + verifyEmptySearchAttributes(t, req.GetSearchAttributes()) } // Go straight to the decide methods without any commands @@ -92,7 +93,7 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { }) } -func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { +func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) { var req iwfidl.WorkflowStateDecideRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -117,23 +118,23 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { case State1: response = getState1DecideResponse(req) case State2: - verifyEmptySearchAttributes(req.GetSearchAttributes()) + verifyEmptySearchAttributes(t, req.GetSearchAttributes()) response = getState2DecideResponse(req) case State3: - verifyLoadedSearchAttributes(req.GetWorkflowStateId(), currentMethod, req.GetSearchAttributes(), loadingType) + verifyLoadedSearchAttributes(t, req.GetWorkflowStateId(), currentMethod, req.GetSearchAttributes(), loadingType) response = getState3DecideResponse(req) case State4: - verifyLoadedSearchAttributes(req.GetWorkflowStateId(), currentMethod, req.GetSearchAttributes(), loadingType) + verifyLoadedSearchAttributes(t, req.GetWorkflowStateId(), currentMethod, req.GetSearchAttributes(), loadingType) response = getState4DecideResponse(req) case State5: - verifyLoadedSearchAttributes(req.GetWorkflowStateId(), currentMethod, req.GetSearchAttributes(), loadingType) + verifyLoadedSearchAttributes(t, req.GetWorkflowStateId(), currentMethod, req.GetSearchAttributes(), loadingType) response = getState5DecideResponse() } c.JSON(http.StatusOK, response) } -func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context) { +func (h *handler) ApiV1WorkflowWorkerRpc(c *gin.Context, t *testing.T) { c.JSON(http.StatusBadRequest, struct{}{}) } @@ -255,14 +256,14 @@ func getState5DecideResponse() iwfidl.WorkflowStateDecideResponse { } } -func verifyEmptySearchAttributes(searchAttributes []iwfidl.SearchAttribute) { +func verifyEmptySearchAttributes(t *testing.T, searchAttributes []iwfidl.SearchAttribute) { var expectedSearchAttributes []iwfidl.SearchAttribute if !assert.ElementsMatch(common.DummyT{}, expectedSearchAttributes, searchAttributes) { panic("Search attributes should be empty") } } -func verifyLoadedSearchAttributes(stateId string, method string, searchAttributes []iwfidl.SearchAttribute, loadingType iwfidl.PersistenceLoadingType) { +func verifyLoadedSearchAttributes(t *testing.T, stateId string, method string, searchAttributes []iwfidl.SearchAttribute, loadingType iwfidl.PersistenceLoadingType) { expectedSearchAttributes := getExpectedSearchAttributes(stateId, method, loadingType) if !assert.ElementsMatch(common.DummyT{}, expectedSearchAttributes, searchAttributes) { panic("Search attributes should be the same")