@@ -210,6 +210,97 @@ describe('Queue', function() {
210210 assert ( queue . fn . calledWith ( 'b' ) ) ;
211211 } ) ;
212212
213+ describe ( 'while using in memory engine' , function ( ) {
214+ beforeEach ( function ( ) {
215+ queue . _store . _swapEngine ( ) ;
216+ } ) ;
217+
218+ it ( 'should take over a queued task if a queue is abandoned' , function ( ) {
219+ // a wild queue of interest appears
220+ var foundQueue = new Store ( 'test' , 'fake-id' , queue . keys ) ;
221+ foundQueue . set ( foundQueue . keys . ACK , 0 ) ; // fake timers starts at time 0
222+ foundQueue . set ( foundQueue . keys . QUEUE , [ {
223+ item : 'a' ,
224+ time : 0 ,
225+ attemptNumber : 0
226+ } ] ) ;
227+
228+ // wait for the queue to expire
229+ clock . tick ( queue . timeouts . RECLAIM_TIMEOUT ) ;
230+
231+ queue . start ( ) ;
232+
233+ // wait long enough for the other queue to expire and be reclaimed
234+ clock . tick (
235+ queue . timeouts . RECLAIM_TIMER
236+ + queue . timeouts . RECLAIM_WAIT * 2
237+ ) ;
238+
239+ assert ( queue . fn . calledOnce ) ;
240+ assert ( queue . fn . calledWith ( 'a' ) ) ;
241+ } ) ;
242+
243+ it ( 'should take over an in-progress task if a queue is abandoned' , function ( ) {
244+ // set up a fake queue
245+ var foundQueue = new Store ( 'test' , 'fake-id' , queue . keys ) ;
246+ foundQueue . set ( foundQueue . keys . ACK , - 15000 ) ;
247+ foundQueue . set ( foundQueue . keys . IN_PROGRESS , {
248+ 'task-id' : {
249+ item : 'a' ,
250+ time : 0 ,
251+ attemptNumber : 0
252+ }
253+ } ) ;
254+
255+ // wait for the queue to expire
256+ clock . tick ( queue . timeouts . RECLAIM_TIMEOUT ) ;
257+
258+ queue . start ( ) ;
259+
260+ // wait long enough for the other queue to expire and be reclaimed
261+ clock . tick (
262+ queue . timeouts . RECLAIM_TIMER
263+ + queue . timeouts . RECLAIM_WAIT * 2
264+ ) ;
265+
266+ assert ( queue . fn . calledOnce ) ;
267+ assert ( queue . fn . calledWith ( 'a' ) ) ;
268+ } ) ;
269+
270+ it ( 'should take over multiple tasks if a queue is abandoned' , function ( ) {
271+ // set up a fake queue
272+ var foundQueue = new Store ( 'test' , 'fake-id' , queue . keys ) ;
273+ foundQueue . set ( foundQueue . keys . ACK , - 15000 ) ;
274+ foundQueue . set ( foundQueue . keys . QUEUE , [ {
275+ item : 'a' ,
276+ time : 0 ,
277+ attemptNumber : 0
278+ } ] ) ;
279+ foundQueue . set ( foundQueue . keys . IN_PROGRESS , {
280+ 'task-id' : {
281+ item : 'b' ,
282+ time : 1 ,
283+ attemptNumber : 0
284+ }
285+ } ) ;
286+
287+ // wait for the queue to expire
288+ clock . tick ( queue . timeouts . RECLAIM_TIMEOUT ) ;
289+
290+ queue . start ( ) ;
291+
292+ // wait long enough for the other queue to expire and be reclaimed
293+ clock . tick (
294+ queue . timeouts . RECLAIM_TIMER
295+ + queue . timeouts . RECLAIM_WAIT * 2
296+ ) ;
297+
298+ assert ( queue . fn . calledTwice ) ;
299+ assert ( queue . fn . calledWith ( 'a' ) ) ;
300+ assert ( queue . fn . calledWith ( 'b' ) ) ;
301+ } ) ;
302+ } ) ;
303+
213304 it ( 'should respect maxAttempts when rejected' , function ( ) {
214305 var calls = new Array ( 100 ) ;
215306
0 commit comments