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

Conversation

juusom
Copy link

@juusom juusom commented May 7, 2021

While working on merging master to #81 I noticed that the process function in the integration tests assumes that indices 100 and 1000 exist. Currently, the event_count that gets passed into the method is 1000 + rand(50). rand(50) may return 0, yielding a count of 1000 and a maximum index of 999.

This should make the function a bit safer.

Comment on lines +27 to +30
[0, 100, 1000].each do |idx|
idx = [idx, event_count - 1].min
expect(events[idx].get('sequence')).to eq idx
end
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants