@@ -114,8 +114,9 @@ def process(conf, event_count)
114114 let ( :queue ) { Queue . new }
115115
116116 let ( :data_type ) { 'list' }
117+ let ( :redis_key ) { 'foo' }
117118 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 } }
119120 let ( :quit_calls ) { [ :quit ] }
120121
121122 subject do
@@ -354,57 +355,58 @@ def process(conf, event_count)
354355
355356 context 'runtime for pattern_list data_type' do
356357 let ( :data_type ) { 'pattern_list' }
357- let ( :key ) { 'foo.*' }
358+ let ( :redis_key ) { 'foo.*' }
359+
358360 before do
359361 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 )
360365 subject . init_threadpool
361366 end
362367
368+ after do
369+ subject . stop
370+ end
371+
363372 context 'close when redis is unset' do
364373 let ( :quit_calls ) { [ :quit , :unsubscribe , :punsubscribe , :connection , :disconnect! ] }
365374
366375 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 )
368377 quit_calls . each do |call |
369- expect ( redis ) . not_to receive ( call )
378+ expect_any_instance_of ( Redis :: Client ) . not_to receive ( call )
370379 end
371380 expect { subject . do_stop } . not_to raise_error
372381 end
373382 end
374383
375384 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'
381387
382388 tt = Thread . new do
383389 end_by = Time . now + 3
384- while accumulator . size < 1 and Time . now <= end_by
385- sleep 0.1
386- end
390+ sleep 0.1 until queue . size > 0 or Time . now > end_by
387391 subject . do_stop
388392 end
389393
390- subject . run ( accumulator )
394+ subject . run ( queue )
391395
392396 tt . join
393397
394- expect ( accumulator . size ) . to be > 0
398+ expect ( queue . size ) . to be > 0
395399 end
396400
397401 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 )
402+ allow_any_instance_of ( Redis ) . to receive ( :keys ) . with ( redis_key ) . and_return ( [ 'foo.bar' ] )
403+ allow_any_instance_of ( Redis ) . to receive ( :lpop ) . with ( 'foo.bar' ) . and_return ( 'l1' )
404+
402405 quit_calls . each do |call |
403- expect ( redis ) . to receive ( call ) . at_most ( :once )
406+ allow_any_instance_of ( Redis ) . to receive ( call ) . at_most ( :once )
404407 end
405408
406409 subject . do_stop
407- connected . push ( false ) #can't use let block here so push to array
408410 expect { subject . do_stop } . not_to raise_error
409411 subject . do_stop
410412 end
0 commit comments