rspec-rails: rspec hangs in the middle of testing
Whether I type “rspec” or “rake spec” in the terminal, it just hangs and never finishes the testing suite. I’ve commented out tests, ran test files individually, but it still just stops. Closest I got to having it finish was uninstalling and reinstalling rspec-rails. First time I run it, I get it to finish.
Second time, I get this:
$ rake spec
/Users/edmac/.rvm/rubies/ruby-2.1.3/bin/ruby -I/Users/edmac/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.2.3/lib:/Users/edmac/.rvm/gems/ruby-2.1.3/gems/rspec-support-3.2.2/lib /Users/edmac/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.2.3/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
I, [2015-04-14T11:28:18.114799 #4618] INFO -- : Not reporting to Code Climate because ENV['CODECLIMATE_REPO_TOKEN'] is not set.
.........*.........*....*.......*..*..*..*.*......^C
RSpec is shutting down and will print the summary report... Interrupt again to force quit.
rake aborted!
Interrupt:
/Users/edmac/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.2.3/lib/rspec/core/rake_task.rb:69:in `system'
/Users/edmac/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.2.3/lib/rspec/core/rake_task.rb:69:in `run_task'
/Users/edmac/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.2.3/lib/rspec/core/rake_task.rb:89:in `block (2 levels) in define'
/Users/edmac/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.2.3/lib/rspec/core/rake_task.rb:87:in `block in define'
/Users/edmac/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `eval'
/Users/edmac/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => spec
(See full trace by running task with --trace)
I had to shut it down because it was hanging for ten minutes. The next time I run the suite, I get:
$ rspec
I, [2015-04-14T11:35:50.690190 #4777] INFO -- : Not reporting to Code Climate because ENV['CODECLIMATE_REPO_TOKEN'] is not set.
About this issue
- Original URL
- State: closed
- Created 12 years ago
- Comments: 15 (5 by maintainers)
Commits related to this issue
- https://github.com/rspec/rspec-rails/issues/1353#issuecomment-93173691 — committed to DataDog/dd-trace-rb by TonyCTHsu 4 years ago
- Update troubleshooting.mdx Add info about simplecov hanging CI node: https://github.com/rspec/rspec-rails/issues/1353#issuecomment-1120477035 — committed to KnapsackPro/docs.knapsackpro.com by ArturT 2 years ago
@JonRowe’s suggestion is a good one, but here’s a slightly more robust way to get the stack trace, so we can see what it’s stuck at. Add this code to any file that is loaded as part of your suite (such as
spec/spec_helper.rb):That’ll print off the pid of the RSpec process, and then you can run this from another terminal session:
…and it’ll print off the stacktraces of all threads. (Note that it’ll print to RSpec’s stdout, not to the terminal where you ran
killfrom).The nice thing about this compared to
ctrl-cis that you get the stacktraces for all threads and it doesn’t halt the process – so you can run it repeatedly to see if it’s staying stuck at one spot, or if it’s making progress but just going really slow or whatever.Wanted to also point out that if you binding.pry a test in another window, then try to run RSpec, your test will wait for the other test to finish and therefore never run (unless you were to exit that debugging session).
Restarting your computer could solve this problem if you’re just really unsure where the process is but otherwise
ps aux | grep rubycould probably show you then you could kill -9 the PID.Thanks so much guys, and sorry for the delay in getting back. Not an rspec problem it turned out. I had a bunch of “zombie” processes hitting the server (only seemed to happen with RSpec though, because Minitest had no problems that I could see). I just had to type out
ps -ax | grep
in the terminal and yes,
killall <the name of the process>
or
kill <pid>
It took a while to figure out and go through all the different server processes (and the ones on my team mates laptops) but all good now. Cheers!
So try a couple of things, first off run try to run your specs with
rspec /specrather thanrake specthat way if you have toCTRL-Cyou’ll get a trace of where your specs are stuck rather than just aborting the rake task.Secondly do
spring stopbefore running the specs to remove that as a possibility.I just wanted to add something here for future internet explorers that find this post.
My test suite started hanging and I could not figure it out. No stack trace, no nothing. Restarted my computer and everything, thinking the testing server needed to reboot.
Turns out, I went to test the app manually and BOOM, I had a simple syntax error, unexpected end-of-input, expecting end in the controller that was causing the test suite to hang and there was no stack trace in the test suite to notify me about the syntax error.
Simple mistake on my part, and nothing to do with Rspec, but just something for others to look into.
@cicio look at the backtrace. The first 4 lines are from
spec_helper.rband are probably from thetrapblock you pasted into yourspec_helper.rb.After that comes
lib/hangperson_game.rb:37which is probably the source of your problem. You can also try sending the signal, waiting a bit (30 seconds or so), sending the signal again, etc. By sending it multiple times like this you can see if its always stuck at the exact same line or whether it is at different lines. If it’s at different lines, it suggests your code is running some slow algorithm, but is in fact making progress. If it’s the same line, maybe there’s some sort of blocking I/O there that just gets stuck.Wowza, so also adding my experience to future explorers as well. And special h/t to @myronmarston for the trap backtrace code that uncovered the lead.
For us, our test suite was hanging at the very end. After implementing Myron’s code, we got the stack trace (abbreviated):
So, I explored the Railtie application finisher.rb code and saw it was doing something with mutex locking, probably the GIL. But what? So, after chasing this down wrongly, I ended up searching the right keywords: “rspec rails application finisher mutex hanging”, which then took me to right question/answer on StackOverflow: https://stackoverflow.com/questions/21313628/rspec-hangs-after-it-finishes-running-through-my-tests
In the end, it was SimpleCov that was the culprit. As reported:
NOTE: this has apparently been fixed in newer versions of SimpleCov (we were running an old version).