Skip to content

Commit

Permalink
IWF-472: Trying to see errors in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel27m committed Jan 27, 2025
1 parent 9640c0c commit 8d3a11b
Show file tree
Hide file tree
Showing 59 changed files with 265 additions and 225 deletions.
11 changes: 11 additions & 0 deletions helpers/errors.go
Original file line number Diff line number Diff line change
@@ -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)
}
6 changes: 3 additions & 3 deletions integ/any_command_close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func doTestAnyCommandCloseWorkflow(t *testing.T, backendType service.BackendType
WorkflowConfigOverride: config,
},
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

signalValue := iwfidl.EncodedObject{
Encoding: iwfidl.PtrString("json"),
Expand All @@ -94,14 +94,14 @@ func doTestAnyCommandCloseWorkflow(t *testing.T, backendType service.BackendType
SignalChannelName: anycommandclose.SignalName2,
SignalValue: &signalValue,
}).Execute()
panicAtHttpError(err, httpResp, t)
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, t)
failTestAtHttpError(err, httpResp, t)

history, data := wfHandler.GetTestResult()
assertions := assert.New(t)
Expand Down
25 changes: 13 additions & 12 deletions integ/any_command_combination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package integ
import (
"context"
"encoding/json"
"github.com/indeedeng/iwf/helpers"
"github.com/indeedeng/iwf/service/common/ptr"
"strconv"
"testing"
Expand Down Expand Up @@ -85,7 +86,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
WorkflowConfigOverride: config,
},
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

signalValue := iwfidl.EncodedObject{
Encoding: iwfidl.PtrString("json"),
Expand All @@ -99,13 +100,13 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
SignalChannelName: anycommandconbination.SignalNameAndId1,
SignalValue: &signalValue,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)
httpResp, err = req2.WorkflowSignalRequest(iwfidl.WorkflowSignalRequest{
WorkflowId: wfId,
SignalChannelName: anycommandconbination.SignalNameAndId1,
SignalValue: &signalValue,
}).Execute()
panicAtHttpError(err, httpResp, t)
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
Expand All @@ -115,7 +116,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
WorkflowStateExecutionId: "S1-1",
TimerCommandId: iwfidl.PtrString(anycommandconbination.TimerId1),
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

// now it should be running at S2
// Future: we can check it is already done S1
Expand All @@ -126,46 +127,46 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
SignalChannelName: anycommandconbination.SignalNameAndId1,
SignalValue: &signalValue,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

// wait and check the workflow, it should be still running
time.Sleep(time.Second)
reqDesc := apiClient.DefaultApi.ApiV1WorkflowGetPost(context.Background())
descResp, httpResp, err := reqDesc.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
WorkflowId: wfId,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)
assertions.Equal(iwfidl.RUNNING, descResp.GetWorkflowStatus())

httpResp, err = req2.WorkflowSignalRequest(iwfidl.WorkflowSignalRequest{
WorkflowId: wfId,
SignalChannelName: anycommandconbination.SignalNameAndId3,
SignalValue: &signalValue,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

// send 2nd signal for s2
httpResp, err = req2.WorkflowSignalRequest(iwfidl.WorkflowSignalRequest{
WorkflowId: wfId,
SignalChannelName: anycommandconbination.SignalNameAndId2,
SignalValue: &signalValue,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

// workflow should be completed now
if config == nil {
time.Sleep(time.Second)
descResp, httpResp, err = reqDesc.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
WorkflowId: wfId,
}).Execute()
panicAtHttpError(err, httpResp, t)
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, t)
failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, respWait, t)
}

history, data := wfHandler.GetTestResult()
Expand All @@ -189,7 +190,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
"\"stateStartApiSucceeded\":true}"
err = json.Unmarshal([]byte(s1ResultJsonStr), &s1CommandResults)
if err != nil {
t.Fatal(err)
helpers.FailTestWithError(err, t)
}
s2ResultsJsonStr := "{\"signalResults\":[" +
"{\"commandId\":\"test-signal-name1\",\"signalChannelName\":\"test-signal-name1\",\"signalRequestStatus\":\"RECEIVED\",\"signalValue\":{\"data\":\"test-data-1\",\"encoding\":\"json\"}}, " +
Expand All @@ -201,7 +202,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
"\"stateStartApiSucceeded\":true}"
err = json.Unmarshal([]byte(s2ResultsJsonStr), &s2CommandResults)
if err != nil {
t.Fatal(err)
helpers.FailTestWithError(err, t)
}
expectedData := map[string]interface{}{
"s1_commandResults": s1CommandResults,
Expand Down
6 changes: 3 additions & 3 deletions integ/any_timer_signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func doTestAnyTimerSignalWorkflow(t *testing.T, backendType service.BackendType,
WorkflowConfigOverride: config,
},
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

// wait for 3 secs and send the signal
time.Sleep(time.Second * 3)
Expand All @@ -97,14 +97,14 @@ func doTestAnyTimerSignalWorkflow(t *testing.T, backendType service.BackendType,
SignalChannelName: anytimersignal.SignalName,
SignalValue: &signalValue,
}).Execute()
panicAtHttpError(err, httpResp, t)
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, t)
failTestAtHttpError(err, httpResp, t)

history, data := wfHandler.GetTestResult()
assertions := assert.New(t)
Expand Down
4 changes: 2 additions & 2 deletions integ/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func doTestBasicWorkflow(t *testing.T, backendType service.BackendType, config *
},
}
_, httpResp, err := req.WorkflowStartRequest(startReq).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

// start it again should return already started error
_, _, err = req.WorkflowStartRequest(startReq).Execute()
Expand All @@ -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, t)
failTestAtHttpError(err, httpResp, t)

// use a wrong workflowId to test the error case
_, _, err = req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
Expand Down
6 changes: 3 additions & 3 deletions integ/conditional_close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func doTestConditionalForceCompleteOnChannelEmptyWorkflow(
}

_, httpResp, err := req.WorkflowStartRequest(startReq).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

// wait for a second so that query handler is ready for executing PRC
time.Sleep(time.Second)
Expand All @@ -126,7 +126,7 @@ func doTestConditionalForceCompleteOnChannelEmptyWorkflow(
}).Execute()
}

panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)
if i == 0 {
// wait for a second so that the workflow is in execute state
time.Sleep(time.Second)
Expand All @@ -138,7 +138,7 @@ func doTestConditionalForceCompleteOnChannelEmptyWorkflow(
resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
WorkflowId: wfId,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

history, _ := wfHandler.GetTestResult()

Expand Down
9 changes: 5 additions & 4 deletions integ/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package integ
import (
"context"
"github.com/indeedeng/iwf/gen/iwfidl"
"github.com/indeedeng/iwf/helpers"
"github.com/indeedeng/iwf/integ/workflow/rpc"
"github.com/indeedeng/iwf/service"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -82,13 +83,13 @@ func doTestCreateWithoutStartingState(t *testing.T, backendType service.BackendT
WorkflowConfigOverride: config,
},
}).Execute()
panicAtHttpError(err, httpResp, t)
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 {
t.Fatal(err)
helpers.FailTestWithError(err, t)
}
assertions.Equal(service.StateExecutionCounterInfo{
StateIdStartedCount: make(map[string]int),
Expand All @@ -110,14 +111,14 @@ func doTestCreateWithoutStartingState(t *testing.T, backendType service.BackendT
},
TimeoutSeconds: iwfidl.PtrInt32(2),
}).Execute()
panicAtHttpError(err, httpResp, t)
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, t)
failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, respWait, t)

history, _ := wfHandler.GetTestResult()
assertions.Equalf(map[string]int64{
Expand Down
10 changes: 5 additions & 5 deletions integ/deadend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config
WorkflowConfigOverride: config,
},
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

reqRpc := apiClient.DefaultApi.ApiV1WorkflowRpcPost(context.Background())

Expand All @@ -93,15 +93,15 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config
WorkflowId: wfId,
RpcName: deadend.RPCWriteData,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)
}

if config != nil {
reqDesc := apiClient.DefaultApi.ApiV1WorkflowGetPost(context.Background())
descResp, httpResp, err := reqDesc.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
WorkflowId: wfId,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)
assertions.True(startResp.GetWorkflowRunId() != descResp.GetWorkflowRunId())
}

Expand All @@ -112,7 +112,7 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config
WorkflowId: wfId,
RpcName: deadend.RPCTriggerState,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)
}

time.Sleep(time.Second * 2)
Expand All @@ -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, t)
failTestAtHttpError(err, httpResp, t)

history, _ := wfHandler.GetTestResult()
assertions.Equalf(map[string]int64{
Expand Down
2 changes: 1 addition & 1 deletion integ/get_with_wait_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func doTestWorkflowWithWaitTimeout(t *testing.T, backendType service.BackendType
WorkflowConfigOverride: config,
},
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

// wait for the workflow
reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
Expand Down
4 changes: 2 additions & 2 deletions integ/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func doTestWorkflowWithHeaders(t *testing.T, backendType service.BackendType, co
},
}
_, httpResp, err := req.WorkflowStartRequest(startReq).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
_, httpResp2, err2 := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
WorkflowId: wfId,
}).Execute()
panicAtHttpError(err2, httpResp2, t)
failTestAtHttpError(err2, httpResp2, t)

assertions := assert.New(t)

Expand Down
4 changes: 2 additions & 2 deletions integ/internalchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ func doTestInterStateWorkflow(t *testing.T, backendType service.BackendType, con
WorkflowConfigOverride: config,
},
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
WorkflowId: wfId,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

history, data := wfHandler.GetTestResult()
assertions := assert.New(t)
Expand Down
8 changes: 4 additions & 4 deletions integ/large_data_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func doTestLargeQueryAttributes(t *testing.T, backendType service.BackendType, c
WorkflowConfigOverride: config,
},
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)

assertions.Equal(httpResp.StatusCode, http.StatusOK)

Expand All @@ -90,7 +90,7 @@ func doTestLargeQueryAttributes(t *testing.T, backendType service.BackendType, c
},
}).Execute()

panicAtHttpError(err, httpResp2, t)
failTestAtHttpError(err, httpResp2, t)
}

// signal the workflow to complete
Expand All @@ -107,13 +107,13 @@ func doTestLargeQueryAttributes(t *testing.T, backendType service.BackendType, c
SignalValue: &signalVal,
}).Execute()

panicAtHttpError(err, httpResp2, t)
failTestAtHttpError(err, httpResp2, t)
}

// wait for the workflow
reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
_, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
WorkflowId: wfId,
}).Execute()
panicAtHttpError(err, httpResp, t)
failTestAtHttpError(err, httpResp, t)
}
Loading

0 comments on commit 8d3a11b

Please sign in to comment.