@@ -52,6 +52,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
52
52
testCases := []struct {
53
53
name string
54
54
allowances func (t * testing.T , reader * taskReader )
55
+ ttl int
55
56
breakDispatch bool
56
57
breakRetries bool
57
58
}{
@@ -174,6 +175,47 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
174
175
breakDispatch : false ,
175
176
breakRetries : false ,
176
177
},
178
+ {
179
+ name : "Error - task not started and not expired, should retry" ,
180
+ allowances : func (t * testing.T , reader * taskReader ) {
181
+ reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration , error ) {
182
+ return defaultIsolationGroup , - 1 , nil
183
+ }
184
+ reader .dispatchTask = func (ctx context.Context , task * InternalTask ) error {
185
+ return errTaskNotStarted
186
+ }
187
+ },
188
+ ttl : 100 ,
189
+ breakDispatch : false ,
190
+ breakRetries : false ,
191
+ },
192
+ {
193
+ name : "Error - task not started and expired, should not retry" ,
194
+ allowances : func (t * testing.T , reader * taskReader ) {
195
+ reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration , error ) {
196
+ return defaultIsolationGroup , - 1 , nil
197
+ }
198
+ reader .dispatchTask = func (ctx context.Context , task * InternalTask ) error {
199
+ return errTaskNotStarted
200
+ }
201
+ },
202
+ ttl : - 2 ,
203
+ breakDispatch : false ,
204
+ breakRetries : true ,
205
+ },
206
+ {
207
+ name : "Error - time not reached to complete task without workflow execution, should retry" ,
208
+ allowances : func (t * testing.T , reader * taskReader ) {
209
+ reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration , error ) {
210
+ return defaultIsolationGroup , - 1 , nil
211
+ }
212
+ reader .dispatchTask = func (ctx context.Context , task * InternalTask ) error {
213
+ return errWaitTimeNotReachedForEntityNotExists
214
+ }
215
+ },
216
+ breakDispatch : false ,
217
+ breakRetries : false ,
218
+ },
177
219
}
178
220
for _ , tc := range testCases {
179
221
t .Run (tc .name , func (t * testing.T ) {
@@ -184,6 +226,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
184
226
reader := tlm .taskReader
185
227
tc .allowances (t , reader )
186
228
taskInfo := newTask (timeSource )
229
+ taskInfo .Expiry = timeSource .Now ().Add (time .Duration (tc .ttl ) * time .Second )
187
230
188
231
breakDispatch , breakRetries := reader .dispatchSingleTaskFromBuffer (taskInfo )
189
232
assert .Equal (t , tc .breakDispatch , breakDispatch )
0 commit comments