-
Notifications
You must be signed in to change notification settings - Fork 415
Let Process.spawn handle STDOUT redirection on MRI #855
Conversation
I couldn't come up with a great spec for this, but the one in the PR does demonstrate the bug. Running the spec without the bugfix causes it to (typically) fail with an error like:
|
The failing builds don't appear to be related to this change. (It looks like bundler is picking up a new version of ttfunk, released today, that depends on ruby ~> 2.1) |
lib/capybara/poltergeist/client.rb
Outdated
STDOUT.reopen(prev) | ||
$stdout = STDOUT | ||
prev.close | ||
if Capybara::Poltergeist.jruby? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does rubinius support the :out option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I believe JRuby 9000 should support the :out option (could be wrong on that but I think so)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. If not, we could make this test more strict.
Separately, the thread safety issue still exists for JRuby (and Rubinius, if it doesn't support the :out
option). I think it's outside the scope of this PR, but it may be worth looking into an alternate solution there, e.g. fork
, then redirect STDOUT, then exec
(assuming those VMs support fork
and exec
) rather than Process.spawn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no fork for JVM
I fixed the ttfunk issue - please rebase so the tests can be fully run |
This code was exactly written to be working across different ruby implementations. I wouldn't change it without strong reason and if I do I'd do it carefully. |
@route the current implementation definitely doesn't work correctly in multithreaded applications on MRI, so at a minimum, this should be fixed to use On platforms that don't support |
@afn how does your test fail without this patch? |
@route our production app intermittently dies with
|
spec/integration/driver_spec.rb
Outdated
@@ -56,6 +56,29 @@ def session_url(path) | |||
end | |||
end | |||
|
|||
unless Capybara::Poltergeist.jruby? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of of not running the test when jruby, please set the test to pending when jruby is true so that we can see the results in the logs as an accepted failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, looks like it doesn't actually fail in jruby. I'd be surprised if the thread-safety issue didn't exist there, though. Let me see if I can come up with a better test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test that doesn't actually add 100k lines to the log would be good too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😁
Updated the spec, so that it's deterministic; it's pending on jruby. I guess the only outstanding question is whether we can use |
Looks like BTW, the build wasn't running at all on Rubinius, but the build failure was ignored. I've updated |
spec/integration/driver_spec.rb
Outdated
|
||
it 'is threadsafe in how it captures console.log' do | ||
stdout = capture_stdout do | ||
pending if Capybara::Poltergeist.jruby? || Capybara::Poltergeist.rubinius? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a descriptive text here - pending "blah blah not supported" if ...
also this should be the first line in the test
lib/capybara/poltergeist/client.rb
Outdated
@@ -64,6 +64,7 @@ def start | |||
|
|||
process_options = {} | |||
process_options[:pgroup] = true unless Capybara::Poltergeist.windows? | |||
process_options[:out] = @write_io unless Capybara::Poltergeist.jruby? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this check rubinius? too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed
spec/integration/driver_spec.rb
Outdated
@@ -56,6 +56,54 @@ def session_url(path) | |||
end | |||
end | |||
|
|||
def capture_stdout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be replaced with RSpec's output matcher - https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/output-matcher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I didn't know about that.
JRuby 9.1.7.0 appears to pass the correctly if the |
Is there a way to test whether the current JRuby version is new enough to
support `:out`?
…On Mon, Feb 20, 2017 at 4:01 PM Thomas Walpole ***@***.***> wrote:
JRuby 9.1.7.0 appears to pass the correctly if the :out option is passed
- so either it supports :out or the test isn't valid
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#855 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACppHlzGg_wCspIEu_X-HR2DamUJbky6ks5ref82gaJpZM4L_wSW>
.
|
There's the global constant |
Well how about we merge this PR, which is a conservative fix (in that it fixes the issue on MRI, but not on JRuby or Rubinius; but it also doesn't introduce regressions on those platforms), and then open a separate issue to address the thread-unsafe behavior on JRuby and Rubinius. Then as part of triaging that issue, we can look into whether the bug is OS-specific, whether Rubinius is still of interest, which version of JRuby added support for |
My concern here would also be whether it has platform specific issues on MRI - @route? |
@twalpole I can't recall MRI's issues, but I definitely remember how it failed on jruby or rubinius either. Moreover I tried to fix it different ways including out option and when it worked on jruby then rubinius failed and vice versa haha) But time has passed since then and maybe languages has changed decently. Here's the related PR #405 |
@afn Could you please change this to check for MRI to opt in to the new behavior (since that's the only place we know for sure it works) rather than checking JRuby and rubinius to opt out of it and squash the commits, then I'll merge |
@twalpole Done - LMK how that looks. Thanks! |
Thanks! |
Fixes #854