@@ -54,14 +54,14 @@ var defaultIsolationGroups = []string{
54
54
func TestDispatchSingleTaskFromBuffer (t * testing.T ) {
55
55
testCases := []struct {
56
56
name string
57
- allowances func (t * testing.T , reader * taskReader )
57
+ allowances func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource )
58
58
ttl int
59
59
breakDispatch bool
60
60
breakRetries bool
61
61
}{
62
62
{
63
63
name : "success - no isolation" ,
64
- allowances : func (t * testing.T , reader * taskReader ) {
64
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
65
65
reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
66
66
return "" , - 1
67
67
}
@@ -77,7 +77,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
77
77
},
78
78
{
79
79
name : "success - isolation" ,
80
- allowances : func (t * testing.T , reader * taskReader ) {
80
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
81
81
reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
82
82
return defaultIsolationGroup , - 1
83
83
}
@@ -93,7 +93,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
93
93
},
94
94
{
95
95
name : "success - unknown isolation group" ,
96
- allowances : func (t * testing.T , reader * taskReader ) {
96
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
97
97
reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
98
98
return "mystery group" , - 1
99
99
}
@@ -108,9 +108,24 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
108
108
breakDispatch : false ,
109
109
breakRetries : true ,
110
110
},
111
+ {
112
+ name : "success - skip expired tasks" ,
113
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock.MockedTimeSource ) {
114
+ reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
115
+ return defaultIsolationGroup , - 1
116
+ }
117
+ reader .dispatchTask = func (ctx context.Context , task * InternalTask ) error {
118
+ t .Fatal ("task must not be dispatched" )
119
+ return nil
120
+ }
121
+ },
122
+ ttl : - 2 ,
123
+ breakDispatch : false ,
124
+ breakRetries : true ,
125
+ },
111
126
{
112
127
name : "Error - context cancelled, should stop" ,
113
- allowances : func (t * testing.T , reader * taskReader ) {
128
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
114
129
reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
115
130
return defaultIsolationGroup , - 1
116
131
}
@@ -124,7 +139,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
124
139
},
125
140
{
126
141
name : "Error - Deadline Exceeded, should retry" ,
127
- allowances : func (t * testing.T , reader * taskReader ) {
142
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
128
143
reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
129
144
return defaultIsolationGroup , - 1
130
145
}
@@ -138,7 +153,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
138
153
},
139
154
{
140
155
name : "Error - throttled, should retry" ,
141
- allowances : func (t * testing.T , reader * taskReader ) {
156
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
142
157
reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
143
158
return defaultIsolationGroup , - 1
144
159
}
@@ -151,7 +166,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
151
166
},
152
167
{
153
168
name : "Error - unknown, should retry" ,
154
- allowances : func (t * testing.T , reader * taskReader ) {
169
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
155
170
reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
156
171
return defaultIsolationGroup , - 1
157
172
}
@@ -164,7 +179,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
164
179
},
165
180
{
166
181
name : "Error - task not started and not expired, should retry" ,
167
- allowances : func (t * testing.T , reader * taskReader ) {
182
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
168
183
reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
169
184
return defaultIsolationGroup , - 1
170
185
}
@@ -177,22 +192,23 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
177
192
breakRetries : false ,
178
193
},
179
194
{
180
- name : "Error - task not started and expired, should not retry" ,
181
- allowances : func (t * testing.T , reader * taskReader ) {
195
+ name : "Error - task not started and expired, should retry" ,
196
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
182
197
reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
183
198
return defaultIsolationGroup , - 1
184
199
}
185
200
reader .dispatchTask = func (ctx context.Context , task * InternalTask ) error {
201
+ mockTime .Advance (time .Hour )
186
202
return errTaskNotStarted
187
203
}
188
204
},
189
- ttl : - 2 ,
205
+ ttl : 1 ,
190
206
breakDispatch : false ,
191
- breakRetries : true ,
207
+ breakRetries : false ,
192
208
},
193
209
{
194
210
name : "Error - time not reached to complete task without workflow execution, should retry" ,
195
- allowances : func (t * testing.T , reader * taskReader ) {
211
+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
196
212
reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
197
213
return defaultIsolationGroup , - 1
198
214
}
@@ -211,7 +227,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
211
227
c := defaultConfig ()
212
228
tlm := createTestTaskListManagerWithConfig (t , testlogger .New (t ), controller , c , timeSource )
213
229
reader := tlm .taskReader
214
- tc .allowances (t , reader )
230
+ tc .allowances (t , reader , timeSource )
215
231
taskInfo := newTask (timeSource )
216
232
taskInfo .Expiry = timeSource .Now ().Add (time .Duration (tc .ttl ) * time .Second )
217
233
0 commit comments