Skip to content

Commit 325e7ca

Browse files
authored
IWF-475: Cleanup unnecessary waiting in integ tests and add wait comments (#549)
1 parent e103716 commit 325e7ca

32 files changed

+76
-53
lines changed

integ/any_command_close_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func doTestAnyCommandCloseWorkflow(t *testing.T, backendType service.BackendType
9696
}).Execute()
9797
failTestAtHttpError(err, httpResp, t)
9898

99-
// wait for the workflow
99+
// Wait for the workflow to complete
100100
reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
101101
_, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
102102
WorkflowId: wfId,

integ/any_command_combination_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
108108
}).Execute()
109109
failTestAtHttpError(err, httpResp, t)
110110

111-
// skip the timer for S1
112-
time.Sleep(time.Second * 5) // wait for a few seconds so that timer is ready to be skipped
111+
// Skip the timer for S1
112+
time.Sleep(time.Second * 5) // Wait for a few seconds so that timer is ready to be skipped
113113
req3 := apiClient.DefaultApi.ApiV1WorkflowTimerSkipPost(context.Background())
114114
httpResp, err = req3.WorkflowSkipTimerRequest(iwfidl.WorkflowSkipTimerRequest{
115115
WorkflowId: wfId,
@@ -118,6 +118,9 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
118118
}).Execute()
119119
failTestAtHttpError(err, httpResp, t)
120120

121+
// Add delay to wait for timer to be skipped
122+
time.Sleep(time.Second)
123+
121124
// now it should be running at S2
122125
// Future: we can check it is already done S1
123126

@@ -129,8 +132,6 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
129132
}).Execute()
130133
failTestAtHttpError(err, httpResp, t)
131134

132-
// wait and check the workflow, it should be still running
133-
time.Sleep(time.Second)
134135
reqDesc := apiClient.DefaultApi.ApiV1WorkflowGetPost(context.Background())
135136
descResp, httpResp, err := reqDesc.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
136137
WorkflowId: wfId,
@@ -153,8 +154,9 @@ func doTestAnyCommandCombinationWorkflow(t *testing.T, backendType service.Backe
153154
}).Execute()
154155
failTestAtHttpError(err, httpResp, t)
155156

156-
// workflow should be completed now
157+
// Workflow should be completed now
157158
if config == nil {
159+
// Wait for workflow to move to execution
158160
time.Sleep(time.Second)
159161
descResp, httpResp, err = reqDesc.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
160162
WorkflowId: wfId,

integ/any_timer_signal_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func doTestAnyTimerSignalWorkflow(t *testing.T, backendType service.BackendType,
125125
}).Execute()
126126
failTestAtHttpError(err, httpResp, t)
127127

128-
// wait for 3 secs and send the signal
128+
// Delay for 3 secs and then send the signal
129129
time.Sleep(time.Second * 3)
130130
signalValue := iwfidl.EncodedObject{
131131
Encoding: iwfidl.PtrString("json"),
@@ -139,7 +139,7 @@ func doTestAnyTimerSignalWorkflow(t *testing.T, backendType service.BackendType,
139139
}).Execute()
140140
failTestAtHttpError(err, httpResp, t)
141141

142-
// wait for the workflow
142+
// Wait for the workflow to complete
143143
reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
144144
_, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
145145
WorkflowId: wfId,

integ/conditional_close_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func doTestConditionalForceCompleteOnChannelEmptyWorkflow(
107107
_, httpResp, err := req.WorkflowStartRequest(startReq).Execute()
108108
failTestAtHttpError(err, httpResp, t)
109109

110-
// wait for a second so that query handler is ready for executing PRC
110+
// Wait for a second so that query handler is ready for executing PRC
111111
time.Sleep(time.Second)
112112
// invoke RPC to send 1 messages to the internal channel to unblock the waitUntil
113113
// then send another two messages
@@ -128,12 +128,12 @@ func doTestConditionalForceCompleteOnChannelEmptyWorkflow(
128128

129129
failTestAtHttpError(err, httpResp, t)
130130
if i == 0 {
131-
// wait for a second so that the workflow is in execute state
131+
// Wait for a second so that the workflow is in execute state
132132
time.Sleep(time.Second)
133133
}
134134
}
135135

136-
// wait for the workflow
136+
// Wait for the workflow to complete
137137
req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
138138
resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
139139
WorkflowId: wfId,

integ/create_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func doTestCreateWithoutStartingState(t *testing.T, backendType service.BackendT
113113
}).Execute()
114114
failTestAtHttpError(err, httpResp, t)
115115

116-
// wait for the workflow
116+
// Wait for the workflow to complete
117117
reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
118118
respWait, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
119119
WorkflowId: wfId,

integ/deadend_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config
8888

8989
// invoke RPC to trigger write to verify continue as new is happening with no states
9090
for i := 0; i < 3; i++ {
91+
// Delay between rpc requests
9192
time.Sleep(time.Second * 2)
9293
_, httpResp, err = reqRpc.WorkflowRpcRequest(iwfidl.WorkflowRpcRequest{
9394
WorkflowId: wfId,
@@ -107,6 +108,7 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config
107108

108109
// invoke an RPC to trigger the state execution
109110
for i := 0; i < 3; i++ {
111+
// Delay between rpc requests
110112
time.Sleep(time.Second * 2)
111113
_, httpResp, err = reqRpc.WorkflowRpcRequest(iwfidl.WorkflowRpcRequest{
112114
WorkflowId: wfId,
@@ -115,8 +117,9 @@ func doTestDeadEndWorkflow(t *testing.T, backendType service.BackendType, config
115117
failTestAtHttpError(err, httpResp, t)
116118
}
117119

120+
// Wait for workflow to move to execution
118121
time.Sleep(time.Second * 2)
119-
// wait for the workflow
122+
120123
reqCancel := apiClient.DefaultApi.ApiV1WorkflowStopPost(context.Background())
121124
httpResp, err = reqCancel.WorkflowStopRequest(iwfidl.WorkflowStopRequest{
122125
WorkflowId: wfId,

integ/get_with_wait_timeout_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func doTestWorkflowWithWaitTimeout(t *testing.T, backendType service.BackendType
6767
}).Execute()
6868
failTestAtHttpError(err, httpResp, t)
6969

70-
// wait for the workflow
70+
// Wait for the workflow to complete
7171
reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
7272
startTimeUnix := time.Now().Unix()
7373
_, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{

integ/greedy_timer_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func doTestGreedyTimerWorkflowCustomConfig(t *testing.T, backendType service.Bac
103103
}).Execute()
104104
failTestAtHttpError(err, httpResp, t)
105105

106+
// Short wait for ApiV1WorkflowStateStart to complete so the timers have been started
106107
time.Sleep(time.Second * 1)
107108

108109
// assertions
@@ -125,6 +126,7 @@ func doTestGreedyTimerWorkflowCustomConfig(t *testing.T, backendType service.Bac
125126
}).Execute()
126127
failTestAtHttpError(err, httpResp, t)
127128

129+
// Short wait for signal to be received and timer to be skipped
128130
time.Sleep(time.Second * 1)
129131

130132
err = uClient.QueryWorkflow(context.Background(), &debug, wfId, "", service.DebugDumpQueryType)
@@ -138,7 +140,7 @@ func doTestGreedyTimerWorkflowCustomConfig(t *testing.T, backendType service.Bac
138140
assertions.LessOrEqual(singleTimerScheduled, debug.FiringTimersUnixTimestamps[0])
139141
scheduleTimerAndAssertExpectedScheduled(t, apiClient, uClient, wfId, 5, 2)
140142

141-
// wait for the workflow
143+
// Wait for the workflow to complete
142144
req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
143145
_, httpResp, err = req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
144146
WorkflowId: wfId,
@@ -176,6 +178,7 @@ func scheduleTimerAndAssertExpectedScheduled(
176178
}).Execute()
177179
failTestAtHttpError(err, httpResp, t)
178180

181+
// Short wait for RPC request to complete
179182
time.Sleep(time.Second * 1)
180183

181184
debug := service.DebugDumpResponse{}

integ/large_data_attributes_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func doTestLargeQueryAttributes(t *testing.T, backendType service.BackendType, c
110110
failTestAtHttpError(err, httpResp2, t)
111111
}
112112

113-
// wait for the workflow
113+
// Wait for the workflow to complete
114114
reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
115115
_, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
116116
WorkflowId: wfId,

integ/locking_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config
132132
ValueType: iwfidl.INT.Ptr(),
133133
},
134134
}
135+
// Adding delay between rpc requests
135136
time.Sleep(time.Second * 2)
136137
reqRpc := apiClient.DefaultApi.ApiV1WorkflowRpcPost(context.Background())
137138
rpcResp, httpResp, err := reqRpc.WorkflowRpcRequest(iwfidl.WorkflowRpcRequest{
@@ -186,6 +187,7 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config
186187
fmt.Println("rpc results, success, failure:", rpcIncrease, rpcLockingFailure)
187188
}
188189

190+
// Wait for state to store the attributes
189191
time.Sleep(time.Second * 1)
190192
reqRpc := apiClient.DefaultApi.ApiV1WorkflowRpcPost(context.Background())
191193
_, httpResp, err = reqRpc.WorkflowRpcRequest(iwfidl.WorkflowRpcRequest{
@@ -195,6 +197,8 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config
195197
}).Execute()
196198
failTestAtHttpError(err, httpResp, t)
197199

200+
// State 2 of the workflow has a 1s sleep in both the start and execute phase. 10 instances of State 2 are called so we
201+
// will match the 10*(1+1) = 20s sleep here.
198202
time.Sleep(time.Second * 20)
199203
req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
200204
resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
@@ -271,6 +275,8 @@ func doTestLockingWorkflow(t *testing.T, backendType service.BackendType, config
271275
}).Execute()
272276
failTestAtHttpError(err, httpResp, t)
273277

278+
// State 2 of the workflow has a 1s sleep in both the start and execute phase. 10 instances of State 2 are called so we
279+
// will match the 10*(1+1) = 20s sleep here.
274280
time.Sleep(time.Second * 20)
275281
req2Reset := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
276282
resp2Reset, httpResp, err := req2Reset.WorkflowGetRequest(iwfidl.WorkflowGetRequest{

integ/parallel_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func doTestParallelWorkflow(t *testing.T, backendType service.BackendType, confi
6767
}).Execute()
6868
failTestAtHttpError(err, httpResp, t)
6969

70-
// wait for the workflow
70+
// Wait for the workflow to complete
7171
req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
7272
resp2, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
7373
WorkflowId: wfId,

integ/persistence_loading_policy_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func doTestPersistenceLoadingPolicy(
107107
}
108108
failTestAtHttpError(err, httpResp, t)
109109

110+
// Wait for workflow
110111
time.Sleep(time.Second * 2)
111112

112113
reqRpc := apiClient.DefaultApi.ApiV1WorkflowRpcPost(context.Background())
@@ -147,7 +148,11 @@ func doTestPersistenceLoadingPolicy(
147148
}
148149
failTestAtHttpError(err, httpResp, t)
149150

150-
time.Sleep(time.Second * 2)
151+
reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
152+
_, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
153+
WorkflowId: wfId,
154+
}).Execute()
155+
failTestAtHttpError(err, httpResp, t)
151156

152157
history, _ := wfHandler.GetTestResult()
153158

integ/persistence_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func doTestPersistenceWorkflow(
178178
break
179179
}
180180
// Loading data to a continuedAsNew workflow might take a few seconds thus retry mechanism is needed
181-
time.Sleep(time.Millisecond * 1000)
181+
time.Sleep(time.Second)
182182
retryCount += 1
183183
queryResult, httpResp, err = getDataAttributes(initReqQry, wfId, expectedDataAttribute, useMemo)
184184
}
@@ -381,7 +381,7 @@ func doTestPersistenceWorkflow(
381381
}).Execute()
382382
failTestAtHttpErrorOrWorkflowUncompleted(err, httpResp, resp, t)
383383

384-
// wait for the search attribute index to be ready in ElasticSearch
384+
// Wait for the search attribute index to be ready in ElasticSearch
385385
time.Sleep(time.Duration(*searchWaitTimeIntegTest) * time.Millisecond)
386386

387387
if config != nil {

integ/rpc_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ func doTestRpcWorkflow(
148148
ValueType: iwfidl.BOOL.Ptr(),
149149
},
150150
}
151+
152+
// Wait for state to store the attributes
151153
time.Sleep(time.Second * 1)
154+
152155
reqRpc := apiClient.DefaultApi.ApiV1WorkflowRpcPost(context.Background())
153156
rpcRespReadOnly, httpResp, err := reqRpc.WorkflowRpcRequest(iwfidl.WorkflowRpcRequest{
154157
WorkflowId: wfId,
@@ -212,7 +215,7 @@ func doTestRpcWorkflow(
212215
}).Execute()
213216
failTestAtHttpError(err, httpResp, t)
214217

215-
// wait for the workflow
218+
// Wait for the workflow to complete
216219
reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
217220
respWait, httpResp, err := reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
218221
WorkflowId: wfId,

integ/set_data_attributes_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestSetDataAttributesTemporal(t *testing.T) {
6969

7070
failTestAtHttpError(err, httpResp2, t)
7171

72+
// Wait for state to store the data attributes
7273
time.Sleep(time.Second)
7374

7475
getReq := apiClient.DefaultApi.ApiV1WorkflowDataobjectsGetPost(context.Background())

integ/set_search_attributes_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func TestSetSearchAttributes(t *testing.T) {
7575

7676
failTestAtHttpError(err, httpResp2, t)
7777

78+
// Wait for state to store the search attributes
7879
time.Sleep(time.Second)
7980

8081
getReq := apiClient.DefaultApi.ApiV1WorkflowSearchattributesGetPost(context.Background())

integ/signal_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config
112112
}).Execute()
113113
failTestAtHttpError(err, httpResp, t)
114114

115+
// Short wait for workflow update
115116
if config != nil {
116117
time.Sleep(2 * time.Second)
117118
}
@@ -200,7 +201,7 @@ func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config
200201
failTestAtHttpError(err, httpResp2, t)
201202
}
202203

203-
// wait for the workflow
204+
// Wait for the workflow to complete
204205
reqWait := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
205206
_, httpResp, err = reqWait.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
206207
WorkflowId: wfId,

integ/start_delay_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func doTestStartDelay(t *testing.T, backendType service.BackendType, config *iwf
9191
_, httpResp, err := req.WorkflowStartRequest(startReq).Execute()
9292
failTestAtHttpError(err, httpResp, t)
9393

94+
// The WorkflowStartDelaySeconds is delayed 10s so we need to wait before trying to execute due to timeouts
9495
time.Sleep(5 * time.Second)
9596
req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
9697
_, httpResp, err = req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{

integ/timer_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config *
131131
}).Execute()
132132
failTestAtHttpError(err, httpResp, t)
133133

134+
// Short wait for timers to get initialized in state
134135
time.Sleep(time.Second * 1)
135136
timerInfos := service.GetCurrentTimerInfosQueryResponse{}
136137
err = uclient.QueryWorkflow(context.Background(), &timerInfos, wfId, "", service.GetCurrentTimerInfosQueryType)
@@ -171,6 +172,7 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config *
171172
}).Execute()
172173
failTestAtHttpError(err, httpResp, t)
173174

175+
// Short wait for signal to be received and timer to be skipped
174176
time.Sleep(time.Second * 1)
175177
timerInfos = service.GetCurrentTimerInfosQueryResponse{}
176178
err = uclient.QueryWorkflow(context.Background(), &timerInfos, wfId, "", service.GetCurrentTimerInfosQueryType)
@@ -180,14 +182,14 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config *
180182
timer2.Status = service.TimerSkipped
181183
assertTimerQueryResponseEqual(assertions, expectedTimerInfos, timerInfos)
182184

183-
time.Sleep(time.Second * 1)
184185
httpResp, err = req3.WorkflowSkipTimerRequest(iwfidl.WorkflowSkipTimerRequest{
185186
WorkflowId: wfId,
186187
WorkflowStateExecutionId: "S1-1",
187188
TimerCommandIndex: iwfidl.PtrInt32(2),
188189
}).Execute()
189190
failTestAtHttpError(err, httpResp, t)
190191

192+
// Short wait for signal to be received and timer to be skipped
191193
time.Sleep(time.Second * 1)
192194
timerInfos = service.GetCurrentTimerInfosQueryResponse{}
193195
err = uclient.QueryWorkflow(context.Background(), &timerInfos, wfId, "", service.GetCurrentTimerInfosQueryType)
@@ -197,7 +199,7 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config *
197199
timer3.Status = service.TimerSkipped
198200
assertTimerQueryResponseEqual(assertions, expectedTimerInfos, timerInfos)
199201

200-
// wait for the workflow
202+
// Wait for the workflow to complete
201203
req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
202204
_, httpResp, err = req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
203205
WorkflowId: wfId,
@@ -215,7 +217,7 @@ func doTestTimerWorkflow(t *testing.T, backendType service.BackendType, config *
215217
assertions.Equal("timer-cmd-id", data["timer_id"])
216218
assertions.True(duration >= 9 && duration <= 11, duration)
217219

218-
// reset with all signals reserved (default behavior)
220+
// Reset with all signals reserved (default behavior)
219221
// Therefore, the skip timer would be reapplied
220222
req4 := apiClient.DefaultApi.ApiV1WorkflowResetPost(context.Background())
221223
_, httpResp, err = req4.WorkflowResetRequest(iwfidl.WorkflowResetRequest{

integ/wait_for_state_completion_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func doTestWaitForStateCompletion(
126126
}
127127
}
128128

129-
// wait for the workflow
129+
// Wait for the workflow to complete
130130
req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background())
131131
_, httpResp, err := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{
132132
WorkflowId: wfId,

integ/wait_until_search_attributes_optimization_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func doTestWaitUntilHistoryCompleted(
8181
_, httpResp, err := reqStart.WorkflowStartRequest(wfReq).Execute()
8282
failTestAtHttpError(err, httpResp, t)
8383

84+
// Wait before sending the signal that would allow State 4 to proceed.
8485
time.Sleep(time.Second * 5)
8586

8687
signalValue := iwfidl.EncodedObject{

integ/wait_until_search_attributes_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func doTestWaitUntilSearchAttributes(
7575
_, httpResp, err := reqStart.WorkflowStartRequest(wfReq).Execute()
7676
failTestAtHttpError(err, httpResp, t)
7777

78-
// wait for the search attribute index to be ready in ElasticSearch
78+
// Wait for the search attribute index to be ready in ElasticSearch
7979
time.Sleep(time.Duration(*searchWaitTimeIntegTest) * time.Millisecond)
8080

8181
switch mode := config.GetExecutingStateIdMode(); mode {

0 commit comments

Comments
 (0)