Repository navigation
Conversation
Result.from_hash is used to merge resultsets when the tests are run in parallel across machines using things like `parallel_tests`. In the above scenario each machine can have multiple results sets as one would want to run as many parallel spec process as the machine has cores. The merge result code only consume the first result, and dropping the rest. In this PR I fix it by returning arrays through out.
PragTob
left a comment
There was a problem hiding this comment.
Hi there @sheki ! 👋
Sorry, I always seem to have missed this PR
I think I know what problem you want to solve here although I've never exercised the concrete scenario. Some tests to show of the handling of this might also help show how it's supposed to work and make sure that it really works (see my comment, I think a little bug might have snug in right now)
| result | ||
| results = [] | ||
| hash.each do |command_name, data| | ||
| command_name, data = hash.first |
There was a problem hiding this comment.
this seems odd to me, we iterate over it getting command_name and data and then we just discard them and use hash.first again - shouldn't this be prone to the same problem(s) again?
| result = SimpleCov::Result.new(data["coverage"]) | ||
| result.command_name = command_name | ||
| result.created_at = Time.at(data["timestamp"]) | ||
| results << result |
There was a problem hiding this comment.
if we just add results shouldn't this rather be a map operation then?
|
So, I finally resumed this and the reasoning why this works (it'd have been hard core borken otherwise) is because the iteration happens at another level. Namely over here: simplecov/lib/simplecov/result_merger.rb Lines 55 to 63 in 67ced4a Now you could make an argument that all of this should happen in It's also meant as an inverse operation to simplecov/lib/simplecov/result.rb Lines 63 to 74 in 67ced4a I'll meditate on this a bit and see how I like it. Maybe sketch out the solution for moving it up or alternatively probably put some sort of "raise assertion" in there. Closing here as it'll probably not look like in here/not implemented at all. Thanks a lot for the pointer though 💚 |
Inspired by #687 This feels cleaner as we have one centralized instead of 2 things making up their own loop leaking knowledge about the data structure. That knowledge is now more contained in the Result class which is great. Using select also feels much better. If anyone was using Result.from_hash we might break their code as it's an Array now. I hope not/nobody should :)
Inspired by #687 This feels cleaner as we have one centralized instead of 2 things making up their own loop leaking knowledge about the data structure. That knowledge is now more contained in the Result class which is great. Using select also feels much better. If anyone was using Result.from_hash we might break their code as it's an Array now. I hope not/nobody should :)

Result.from_hash is used to merge resultsets when the tests are run in
parallel across machines using things like
parallel_tests. In theabove scenario each machine can have multiple results sets as one would
want to run as many parallel spec process as the machine has cores. The
merge result code only consumes the first result, and dropping the rest.
In this PR I fix it by returning arrays through out.