Skip to content

Process spawn should not raise NoMethodError when true argument is given to :pgroup#1895

Merged
dbussink merged 2 commits intorubinius:masterfrom
LTe:process_spawn
Sep 22, 2012
Merged

Process spawn should not raise NoMethodError when true argument is given to :pgroup#1895
dbussink merged 2 commits intorubinius:masterfrom
LTe:process_spawn

Conversation

@LTe
Copy link
Copy Markdown
Contributor

@LTe LTe commented Sep 11, 2012

No description provided.

Comment thread spec/ruby/shared/process/spawn.rb Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should try to spec behavior here as how it should work, not that it shouldn't raise an exception. So that means we should specify here that it creates a new pgroup.

In general, any spec that says "should not raise an exception" is almost always a wrong spec.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I update pull request. And spec about "should not raise and exception" can be good: https://github.com/LTe/rubinius/commit/a16eeac790527589e862b03d0aab95ae927137b3#L0R272 :)

@LTe
Copy link
Copy Markdown
Contributor Author

LTe commented Sep 11, 2012

Process.spawn("ls", :pgroup => :true) should raise TypeError.
I updated specs with pgroup. Specs checks now that process executed in new group and also executed (print pid to STDOUT).

@LTe
Copy link
Copy Markdown
Contributor Author

LTe commented Sep 11, 2012

Pass on travis but rake raise

/home/travis/builds/rubinius/rubinius/Rakefile:131:in `exit': no implicit conversion from nil to integer (TypeError)
2483    from /home/travis/builds/rubinius/rubinius/Rakefile:131:in `block in set_at_exit_handler'`

On my localhost:
3891 files, 21911 examples, 142349 expectations, 0 failures, 0 errors

Comment thread spec/ruby/shared/process/spawn.rb Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like this description is wrong. It raises an exception and the description says otherwise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point!

@LTe
Copy link
Copy Markdown
Contributor Author

LTe commented Sep 11, 2012

It feels to me as what MRI does here is a standard Ruby coercion protocol to Integer. Looks like we need to do that too here, instead of just having a special case for Symbol.

We need to consider several options

  • pgroup is true
  • pgroup is positive Integer
  • pgroup is negative Integer
  • pgroup is nil
  • pgroup is false

I moved a little bit of logic from this place to this place

Now when pgroup is true we set pgroup value to 0. Method coerce_to create once again 0 and set value. When pgroup is false or nil this value will set and default behavior will execute because of that. If pgroup will be Integer negative Rubinius will raise argument error because of that. If pgroup will be positive Integer everything will be normal.

@dbussink what do you think?

Comment thread kernel/common/process19.rb Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like we have multiple if value checks here. What is the behavior when value is nil? We should try to only have to this check once probably.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When pgroup is nil or false process group will not create.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dbussink we can do something like that:

value = 0 if value == true
if value
  value = Rubinius::Type.coerce_to value, Integer, :to_int 
  raise ArgumentError, "negative process group ID : #{value}" if value < 0
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about something like this?

if value == true
  value = 0
elsif value
  value = Rubinius::Type.coerce_to value, Integer, :to_int 
  raise ArgumentError, "negative process group ID : #{value}" if value < 0
end

LTe added 2 commits September 22, 2012 13:27
When user execute method with :pgroup => true Rubinius tried to use '<'
method on TrueClass object. It will throw an exception NoMethotError.

Process.spawn executed with :pgroup => Symbol should raise TypeError
Cases:
1. pgroup value is 'true' => 0
2. pgroup value is kind of true => Rubinius will try coerce_to Integer
3. pgroup value if kind of true and pass coerce then Rubinius will check
check whether the value is < 0. If yes then an ArgumentError exception is thrown
4. pgroup if kind of false (false, nil) - default behavior (like without
pgroup)

Fixes #1894
dbussink added a commit that referenced this pull request Sep 22, 2012
Process spawn should not raise NoMethodError when true argument is given to :pgroup
@dbussink dbussink merged commit 5aea289 into rubinius:master Sep 22, 2012
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