From 3ad7b241e54d7fbd103f76af4e2de96067eb2d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juuso=20M=C3=A4yr=C3=A4nen?= Date: Fri, 7 May 2021 15:22:51 +0300 Subject: [PATCH] Fix potential out of bounds index in test --- spec/inputs/redis_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/inputs/redis_spec.rb b/spec/inputs/redis_spec.rb index d070f13..5bc212b 100755 --- a/spec/inputs/redis_spec.rb +++ b/spec/inputs/redis_spec.rb @@ -17,15 +17,17 @@ def populate(key, event_count) end def process(conf, event_count) + expect(event_count).to be > 0 events = input(conf) do |_, queue| sleep 0.1 until queue.size >= event_count queue.size.times.map { queue.pop } end # due multiple workers we get events out-of-order in the output events.sort! { |a, b| a.get('sequence') <=> b.get('sequence') } - expect(events[0].get('sequence')).to eq(0) - expect(events[100].get('sequence')).to eq(100) - expect(events[1000].get('sequence')).to eq(1000) + [0, 100, 1000].each do |idx| + idx = [idx, event_count - 1].min + expect(events[idx].get('sequence')).to eq idx + end end # integration tests ---------------------