Skip to content

Support multiple files in Result.from_hash - #687

Closed
sheki wants to merge 2 commits into
simplecov-ruby:mainfrom
sheki:master
Closed

sheki wants to merge 2 commits into
simplecov-ruby:mainfrom
sheki:master

Conversation

@sheki

@sheki sheki commented Aug 7, 2018 •

Copy link
Copy Markdown

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 consumes the first result, and dropping the rest.

In this PR I fix it by returning arrays through out.

sheki added 2 commits August 6, 2018 22:01
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 PragTob left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi there @sheki ! 👋

Sorry, I always seem to have missed this PR ☹️ Thank you so much for putting in the work! 🎉 💚

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)

WhatsApp Image 2019-03-28 at 17 08 08

Comment thread lib/simplecov/result.rb
result
results = []
hash.each do |command_name, data|
command_name, data = hash.first

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Comment thread lib/simplecov/result.rb
result = SimpleCov::Result.new(data["coverage"])
result.command_name = command_name
result.created_at = Time.at(data["timestamp"])
results << result

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if we just add results shouldn't this rather be a map operation then?

@deivid-rodriguez deivid-rodriguez mentioned this pull request Jan 19, 2020
4 tasks done
@PragTob
PragTob changed the base branch from master to main July 5, 2020 09:46
@PragTob

PragTob commented Aug 16, 2020

Copy link
Copy Markdown
Collaborator

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:

def results
results = []
resultset.each do |command_name, data|
result = SimpleCov::Result.from_hash(command_name => data)
# Only add result if the timeout is above the configured threshold
results << result if (Time.now - result.created_at) < SimpleCov.merge_timeout
end
results
end

Now you could make an argument that all of this should happen in .from_hash and be called from those places instead.

It's also meant as an inverse operation to to_hash:

# Returns a hash representation of this Result that can be used for marshalling it into JSON
def to_hash
{
command_name => {
"coverage" => coverage,
"timestamp" => created_at.to_i
}
}
end
# Loads a SimpleCov::Result#to_hash dump
def self.from_hash(hash)

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 💚

@PragTob PragTob closed this Aug 16, 2020
PragTob added a commit that referenced this pull request Aug 16, 2020
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 :)
PragTob added a commit that referenced this pull request Aug 16, 2020
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 :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants