@@ -114,8 +114,9 @@ def process(conf, event_count)
114
114
let ( :queue ) { Queue . new }
115
115
116
116
let ( :data_type ) { 'list' }
117
+ let ( :redis_key ) { 'foo' }
117
118
let ( :batch_count ) { 1 }
118
- let ( :config ) { { 'key' => 'foo' , 'data_type' => data_type , 'batch_count' => batch_count } }
119
+ let ( :config ) { { 'key' => redis_key , 'data_type' => data_type , 'batch_count' => batch_count } }
119
120
let ( :quit_calls ) { [ :quit ] }
120
121
121
122
subject do
@@ -354,57 +355,60 @@ def process(conf, event_count)
354
355
355
356
context 'runtime for pattern_list data_type' do
356
357
let ( :data_type ) { 'pattern_list' }
357
- let ( :key ) { 'foo.*' }
358
+ let ( :redis_key ) { 'foo.*' }
359
+
358
360
before do
359
361
subject . register
362
+ allow_any_instance_of ( Redis ::Client ) . to receive ( :connected? ) . and_return true
363
+ allow_any_instance_of ( Redis ::Client ) . to receive ( :disconnect )
364
+ allow_any_instance_of ( Redis ) . to receive ( :quit )
360
365
subject . init_threadpool
361
366
end
362
367
368
+ after do
369
+ subject . stop
370
+ end
371
+
363
372
context 'close when redis is unset' do
364
373
let ( :quit_calls ) { [ :quit , :unsubscribe , :punsubscribe , :connection , :disconnect! ] }
365
374
366
375
it 'does not attempt to quit' do
367
- allow ( redis ) . to receive ( :nil? ) . and_return ( true )
376
+ allow_any_instance_of ( Redis :: Client ) . to receive ( :nil? ) . and_return ( true )
368
377
quit_calls . each do |call |
369
- expect ( redis ) . not_to receive ( call )
378
+ expect_any_instance_of ( Redis :: Client ) . not_to receive ( call )
370
379
end
371
380
expect { subject . do_stop } . not_to raise_error
372
381
end
373
382
end
374
383
375
384
it 'calling the run method, adds events to the queue' do
376
- expect ( redis ) . to receive ( :keys ) . at_least ( :once ) . and_return ( [ 'foo.bar' ] )
377
- expect ( redis ) . to receive ( :lpop ) . at_least ( :once ) . and_return ( 'l1' )
378
-
379
- allow ( redis ) . to receive ( :connected? ) . and_return ( connected . last )
380
- allow ( redis ) . to receive ( :quit )
385
+ expect_any_instance_of ( Redis ) . to receive ( :keys ) . at_least ( :once ) . with ( redis_key ) . and_return [ 'foo.bar' ]
386
+ expect_any_instance_of ( Redis ) . to receive ( :lpop ) . at_least ( :once ) . with ( 'foo.bar' ) . and_return 'l1'
381
387
382
388
tt = Thread . new do
383
389
end_by = Time . now + 3
384
- while accumulator . size < 1 and Time . now <= end_by
390
+ while queue . size < 1 and Time . now <= end_by
385
391
sleep 0.1
386
392
end
387
393
subject . do_stop
388
394
end
389
395
390
- subject . run ( accumulator )
396
+ subject . run ( queue )
391
397
392
398
tt . join
393
399
394
- expect ( accumulator . size ) . to be > 0
400
+ expect ( queue . size ) . to be > 0
395
401
end
396
402
397
403
it 'multiple close calls, calls to redis once' do
398
- subject . use_redis ( redis )
399
- allow ( redis ) . to receive ( :keys ) . at_least ( :once ) . and_return ( [ 'foo.bar' ] )
400
- allow ( redis ) . to receive ( :lpop ) . and_return ( 'l1' )
401
- expect ( redis ) . to receive ( :connected? ) . and_return ( connected . last )
404
+ allow_any_instance_of ( Redis ) . to receive ( :keys ) . with ( redis_key ) . and_return ( [ 'foo.bar' ] )
405
+ allow_any_instance_of ( Redis ) . to receive ( :lpop ) . with ( 'foo.bar' ) . and_return ( 'l1' )
406
+
402
407
quit_calls . each do |call |
403
- expect ( redis ) . to receive ( call ) . at_most ( :once )
408
+ allow_any_instance_of ( Redis ) . to receive ( call ) . at_most ( :once )
404
409
end
405
410
406
411
subject . do_stop
407
- connected . push ( false ) #can't use let block here so push to array
408
412
expect { subject . do_stop } . not_to raise_error
409
413
subject . do_stop
410
414
end
0 commit comments