@@ -54,14 +54,14 @@ var defaultIsolationGroups = []string{
5454func TestDispatchSingleTaskFromBuffer (t * testing.T ) {
5555 testCases := []struct {
5656 name string
57- allowances func (t * testing.T , reader * taskReader )
57+ allowances func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource )
5858 ttl int
5959 breakDispatch bool
6060 breakRetries bool
6161 }{
6262 {
6363 name : "success - no isolation" ,
64- allowances : func (t * testing.T , reader * taskReader ) {
64+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
6565 reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
6666 return "" , - 1
6767 }
@@ -77,7 +77,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
7777 },
7878 {
7979 name : "success - isolation" ,
80- allowances : func (t * testing.T , reader * taskReader ) {
80+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
8181 reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
8282 return defaultIsolationGroup , - 1
8383 }
@@ -93,7 +93,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
9393 },
9494 {
9595 name : "success - unknown isolation group" ,
96- allowances : func (t * testing.T , reader * taskReader ) {
96+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
9797 reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
9898 return "mystery group" , - 1
9999 }
@@ -108,9 +108,24 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
108108 breakDispatch : false ,
109109 breakRetries : true ,
110110 },
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+ },
111126 {
112127 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 ) {
114129 reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
115130 return defaultIsolationGroup , - 1
116131 }
@@ -124,7 +139,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
124139 },
125140 {
126141 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 ) {
128143 reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
129144 return defaultIsolationGroup , - 1
130145 }
@@ -138,7 +153,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
138153 },
139154 {
140155 name : "Error - throttled, should retry" ,
141- allowances : func (t * testing.T , reader * taskReader ) {
156+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
142157 reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
143158 return defaultIsolationGroup , - 1
144159 }
@@ -151,7 +166,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
151166 },
152167 {
153168 name : "Error - unknown, should retry" ,
154- allowances : func (t * testing.T , reader * taskReader ) {
169+ allowances : func (t * testing.T , reader * taskReader , mockTime clock. MockedTimeSource ) {
155170 reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
156171 return defaultIsolationGroup , - 1
157172 }
@@ -164,7 +179,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
164179 },
165180 {
166181 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 ) {
168183 reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
169184 return defaultIsolationGroup , - 1
170185 }
@@ -177,22 +192,23 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
177192 breakRetries : false ,
178193 },
179194 {
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 ) {
182197 reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
183198 return defaultIsolationGroup , - 1
184199 }
185200 reader .dispatchTask = func (ctx context.Context , task * InternalTask ) error {
201+ mockTime .Advance (time .Hour )
186202 return errTaskNotStarted
187203 }
188204 },
189- ttl : - 2 ,
205+ ttl : 1 ,
190206 breakDispatch : false ,
191- breakRetries : true ,
207+ breakRetries : false ,
192208 },
193209 {
194210 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 ) {
196212 reader .getIsolationGroupForTask = func (ctx context.Context , info * persistence.TaskInfo ) (string , time.Duration ) {
197213 return defaultIsolationGroup , - 1
198214 }
@@ -211,7 +227,7 @@ func TestDispatchSingleTaskFromBuffer(t *testing.T) {
211227 c := defaultConfig ()
212228 tlm := createTestTaskListManagerWithConfig (t , testlogger .New (t ), controller , c , timeSource )
213229 reader := tlm .taskReader
214- tc .allowances (t , reader )
230+ tc .allowances (t , reader , timeSource )
215231 taskInfo := newTask (timeSource )
216232 taskInfo .Expiry = timeSource .Now ().Add (time .Duration (tc .ttl ) * time .Second )
217233
0 commit comments