Skip to content

Commit

Permalink
IWF-472: Trying to remove all panics and convert them into t.Fatal in…
Browse files Browse the repository at this point in the history
…stead
  • Loading branch information
samuel27m committed Jan 24, 2025
1 parent 3affee3 commit 3c5437b
Show file tree
Hide file tree
Showing 67 changed files with 244 additions and 206 deletions.
2 changes: 1 addition & 1 deletion 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 Down
6 changes: 3 additions & 3 deletions integ/any_command_combination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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 Down Expand Up @@ -189,7 +189,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
"\"stateStartApiSucceeded\":true}"
err = json.Unmarshal([]byte(s1ResultJsonStr), &s1CommandResults)
if err != nil {
panic(err)
t.Fatal(err)
}
s2ResultsJsonStr := "{\"signalResults\":[" +
"{\"commandId\":\"test-signal-name1\",\"signalChannelName\":\"test-signal-name1\",\"signalRequestStatus\":\"RECEIVED\",\"signalValue\":{\"data\":\"test-data-1\",\"encoding\":\"json\"}}, " +
Expand All @@ -201,7 +201,7 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
"\"stateStartApiSucceeded\":true}"
err = json.Unmarshal([]byte(s2ResultsJsonStr), &s2CommandResults)
if err != nil {
panic(err)
t.Fatal(err)
}
expectedData := map[string]interface{}{
"s1_commandResults": s1CommandResults,
Expand Down
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion 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
4 changes: 2 additions & 2 deletions integ/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 Down Expand Up @@ -88,7 +88,7 @@ func doTestCreateWithoutStartingState(t *testing.T, backendType service.BackendT
var dump service.DebugDumpResponse
err = uclient.QueryWorkflow(context.Background(), &dump, wfId, "", service.DebugDumpQueryType)
if err != nil {
panic(err)
t.Fatal(err)
}
assertions.Equal(service.StateExecutionCounterInfo{
StateIdStartedCount: make(map[string]int),
Expand Down
2 changes: 1 addition & 1 deletion 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 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 @@ -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 Down
2 changes: 1 addition & 1 deletion integ/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion integ/internalchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion integ/large_data_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion integ/locking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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{
Expand Down
2 changes: 1 addition & 1 deletion integ/parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions integ/persistence_loading_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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()
Expand Down Expand Up @@ -100,7 +100,7 @@ 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")
t.Fatal("err should not be nil when Memo is not supported with Cadence")
}
return
}
Expand Down Expand Up @@ -140,7 +140,7 @@ 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")
t.Fatal("err should not be nil when Locking is not supported with Cadence")
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion integ/persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion integ/reset_by_state_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion integ/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion integ/set_data_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion integ/set_search_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions integ/signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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)
Expand Down Expand Up @@ -93,7 +93,7 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config
var debugDump service.DebugDumpResponse
err = uclient.QueryWorkflow(context.Background(), &debugDump, wfId, "", service.DebugDumpQueryType)
if err != nil {
panic(err)
t.Fatal(err)
}
expectedConfig := *config2.DefaultWorkflowConfig
if config != nil {
Expand All @@ -116,7 +116,7 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config
}
err = uclient.QueryWorkflow(context.Background(), &debugDump, wfId, "", service.DebugDumpQueryType)
if err != nil {
panic(err)
t.Fatal(err)
}
expectedConfig.DisableSystemSearchAttribute = iwfidl.PtrBool(true)
assertions.Equal(expectedConfig, debugDump.Config)
Expand All @@ -133,7 +133,7 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config

err = uclient.QueryWorkflow(context.Background(), &debugDump, wfId, "", service.DebugDumpQueryType)
if err != nil {
panic(err)
t.Fatal(err)
}
expectedConfig.ContinueAsNewPageSizeInBytes = iwfidl.PtrInt32(3000000)
assertions.Equal(expectedConfig, debugDump.Config)
Expand Down Expand Up @@ -225,7 +225,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)
t.Fatal(err)
}
assertions.Equal(unhandledSignalVals, dump.Snapshot.SignalsReceived[signal.UnhandledSignalName])
assertions.True(len(unhandledSignalVals) > 0)
Expand Down
2 changes: 1 addition & 1 deletion integ/skip_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion integ/start_delay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion integ/start_with_no_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion integ/timer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 24 additions & 18 deletions integ/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
temporalapi "github.com/indeedeng/iwf/service/client/temporal"
"log"
"net/http"
"testing"
"time"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -36,19 +37,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,
Expand Down Expand Up @@ -178,33 +185,32 @@ func doStartIwfServiceWithClient(config IwfServiceTestConfig) (uclient uclient.U
}
}

func panicAtError(err error) {
func panicAtError(err error, t *testing.T) {
if err != nil {
panic(err)
t.Fatal(err)
}
}

func panicAtHttpError(err error, httpResp *http.Response) {
func panicAtHttpError(err error, httpResp *http.Response, t *testing.T) {
if err != nil {
panic(err)
t.Fatal(err)
}
if httpResp.StatusCode != http.StatusOK {
panic("Status not success" + httpResp.Status)
t.Fatal("Status not success" + httpResp.Status)
}
}

func panicAtHttpErrorOrWorkflowUncompleted(err error, httpResp *http.Response, resp *iwfidl.WorkflowGetResponse) {
func panicAtHttpErrorOrWorkflowUncompleted(err error, httpResp *http.Response, resp *iwfidl.WorkflowGetResponse, t *testing.T) {
if err != nil {
panic(err)
t.Fatal(err)
}
if httpResp.StatusCode != http.StatusOK {
panic("Status not success" + httpResp.Status)
t.Fatalf("Status not success: %v", httpResp.Status)
}
if resp.WorkflowStatus != iwfidl.COMPLETED {
panic("Workflow uncompleted:" + resp.WorkflowStatus)
t.Fatalf("Workflow uncompleted: %v", resp.WorkflowStatus)
}
}

func smallWaitForFastTest() {
du := time.Millisecond * time.Duration(*repeatInterval)
if *repeatIntegTest == 0 {
Expand Down
2 changes: 1 addition & 1 deletion integ/wait_for_state_completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 3c5437b

Please sign in to comment.