Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential out of bounds index in test #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions spec/inputs/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +27 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Juuso, indeed it's me to blame.
While your code fixes the issue it requires extra 🤔 could we just hard-code 999:

Suggested change
[0, 100, 1000].each do |idx|
idx = [idx, event_count - 1].min
expect(events[idx].get('sequence')).to eq idx
end
[0, 100, 999].each do |idx|
expect(events[idx].get('sequence')).to eq idx
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I don't mind. I just figured it would make sense to have a bit more generic approach because this way the function requires to input to be >=1000.

end

# integration tests ---------------------
Expand Down