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 rails console --sandbox test for Mac OS #9761

Closed
wants to merge 1 commit into from

Conversation

MacksMind
Copy link
Contributor

Using Process#kill was triggering ReportCrash on Mac OS Moutain Lion and
the test would not complete. This happened whether run from rake test
or as ruby -w -Itest ...

/cc @jonleighton @carlosantoniodasilva

@carlosantoniodasilva
Copy link
Member

Hm yeah, I was having problems but couldn't look yet. Will try your patch later, thanks @MacksMind!

@@ -120,15 +120,19 @@ def assert_output(expected, timeout = 1)
end

def write_prompt(command, expected_output = nil)
expected_output ||= "> "

Choose a reason for hiding this comment

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

Can you move this default to the arguments definition instead?

@carlosantoniodasilva
Copy link
Member

Confirme, tests pass for me with this change.

@jonleighton thoughts?

Using Process#kill was triggering ReportCrash on Mac OS Moutain Lion and
the test would not complete. This happened whether run from `rake test`
or as ruby -w -Itest ...
@rrmartins
Copy link
Contributor

@carlosantoniodasilva not passed the tests...

@carlosantoniodasilva
Copy link
Member

@rrmartins sorry, what? It seems to be passing here.

@rrmartins
Copy link
Contributor

@carlosantoniodasilva here in my machine had a failure, below is the log:

1) Failure:
FullStackConsoleTest#test_sandbox [test/application/console_test.rb:125]:
"Post.count" expected, but got:

quit

@carlosantoniodasilva
Copy link
Member

@rrmartins crap.. which version is your OS?

@rrmartins
Copy link
Contributor

@carlosantoniodasilva here is my version 10.8.3

@MacksMind
Copy link
Contributor Author

@rrmartins Pulling that down now.

@carlosantoniodasilva
Copy link
Member

Weird, I'm already on OSX 10.8.3, and it worked.

@MacksMind
Copy link
Contributor Author

Works for me on 10.8.3 too. @rrmartins, call you try increasing the timeout at line 109 and see if anything changes. Grasping at straws, but it seems like that quit should have already been consumed.

@jonleighton
Copy link
Member

Sorry for my slow reply folks, I've been moving house :( :( :( I'll look at this today.

@jonleighton
Copy link
Member

Hi guys, I hope that the above commit resolves this? Please let me know if not.

@MacksMind
Copy link
Contributor Author

No, it doesn't.

$ bundle exec ruby -wItest test/application/console_test.rb
Run options: --seed 41388

# Running tests:

.....Terminated: 15

@MacksMind
Copy link
Contributor Author

Based on the Process#kill rdoc, what you did looks good. But I played with it for a while on my Mac and I couldn't figure out how to make it do what I wanted. My patch isn't ideal, but it's the best I could think of. Do we need to bring this up at http://bugs.ruby-lang.org/ ?

@jonleighton
Copy link
Member

Hmm, weird. Maybe some native extension is objecting to the signal. Anyway, how about this?

diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb
index d586822..80700a1 100644
--- a/railties/test/application/console_test.rb
+++ b/railties/test/application/console_test.rb
@@ -126,12 +126,6 @@ class FullStackConsoleTest < ActiveSupport::TestCase
     assert_output "> "
   end

-  def kill(pid)
-    Process.kill('TERM', pid)
-    Process.wait(pid)
-  rescue Errno::ESRCH
-  end
-
   def spawn_console
     pid = Process.spawn(
       "#{app_path}/bin/rails console --sandbox",
@@ -148,15 +142,13 @@ class FullStackConsoleTest < ActiveSupport::TestCase
     write_prompt "Post.count", "=> 0"
     write_prompt "Post.create"
     write_prompt "Post.count", "=> 1"
-
-    kill pid
+    @master.puts "quit"

     pid = spawn_console

     write_prompt "Post.count", "=> 0"
     write_prompt "Post.transaction { Post.create; raise }"
     write_prompt "Post.count", "=> 0"
-  ensure
-    kill pid if pid
+    @master.puts "quit"
   end
 end

I basically want to avoid having special cases for different OSes.

@MacksMind
Copy link
Contributor Author

Yes!

jonleighton added a commit that referenced this pull request Mar 22, 2013
Use the "quit" command instead. This seems to prevents some weirdness on
OS X. See #9761.
@jonleighton
Copy link
Member

Ok, I've committed that then

@jonleighton jonleighton reopened this Mar 22, 2013
@MacksMind
Copy link
Contributor Author

@jonleighton Thanks

DanOlson pushed a commit to DanOlson/rails that referenced this pull request Mar 24, 2013
SIGTERM is the correct signal for a graceful exit.

This will hopefully resolve rails#9761.
DanOlson pushed a commit to DanOlson/rails that referenced this pull request Mar 24, 2013
Use the "quit" command instead. This seems to prevents some weirdness on
OS X. See rails#9761.
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.

None yet

4 participants