Skip to content

Commit

Permalink
IWF-472: Fix all the panic and enable test coverage (#535)
Browse files Browse the repository at this point in the history
Co-authored-by: lwolczynski <[email protected]>
  • Loading branch information
samuel27m and lwolczynski authored Jan 29, 2025
1 parent aab8522 commit 2a439d5
Show file tree
Hide file tree
Showing 70 changed files with 474 additions and 380 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci-all-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ jobs:
if: always()
uses: jwalton/gh-docker-logs@v2
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions integ/any_command_close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"),
Expand All @@ -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)
Expand Down
27 changes: 14 additions & 13 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/integ/helpers"
"github.com/indeedeng/iwf/service/common/ptr"
"strconv"
"testing"
Expand Down Expand Up @@ -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)
Expand All @@ -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"),
Expand All @@ -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
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)
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)
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)
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)
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)
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)
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()
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 {
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\"}}, " +
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 {
panic(err)
helpers.FailTestWithError(err, t)
}
expectedData := map[string]interface{}{
"s1_commandResults": s1CommandResults,
Expand Down
8 changes: 4 additions & 4 deletions integ/any_timer_signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions integ/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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()
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)
failTestAtHttpError(err, httpResp, t)

// use a wrong workflowId to test the error case
_, _, err = req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
Expand Down
8 changes: 4 additions & 4 deletions integ/conditional_close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()

Expand Down
11 changes: 6 additions & 5 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/integ/helpers"
"github.com/indeedeng/iwf/integ/workflow/rpc"
"github.com/indeedeng/iwf/service"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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)
Expand All @@ -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),
Expand All @@ -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{
Expand Down
12 changes: 6 additions & 6 deletions integ/deadend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())

Expand All @@ -93,15 +93,15 @@ 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 {
reqDesc := apiClient.DefaultApi.ApiV1WorkflowGetPost(context.Background())
descResp, httpResp, err := reqDesc.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
WorkflowId: wfId,
}).Execute()
panicAtHttpError(err, httpResp)
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)
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)
failTestAtHttpError(err, httpResp, t)

history, _ := wfHandler.GetTestResult()
assertions.Equalf(map[string]int64{
Expand Down
4 changes: 2 additions & 2 deletions integ/get_with_wait_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand Down
Loading

0 comments on commit 2a439d5

Please sign in to comment.