Skip to content

Commit 944c713

Browse files
author
Juuso Mäyränen
committed
Update pattern list tests according to recent refactorings
1 parent 226bb97 commit 944c713

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

spec/inputs/redis_spec.rb

+22-18
Original file line numberDiff line numberDiff line change
@@ -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,60 @@ 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
390+
while queue.size < 1 and Time.now <= end_by
385391
sleep 0.1
386392
end
387393
subject.do_stop
388394
end
389395

390-
subject.run(accumulator)
396+
subject.run(queue)
391397

392398
tt.join
393399

394-
expect(accumulator.size).to be > 0
400+
expect(queue.size).to be > 0
395401
end
396402

397403
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+
402407
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)
404409
end
405410

406411
subject.do_stop
407-
connected.push(false) #can't use let block here so push to array
408412
expect {subject.do_stop}.not_to raise_error
409413
subject.do_stop
410414
end

0 commit comments

Comments
 (0)