-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
rspec hangs in the middle of testing #1353
Comments
So try a couple of things, first off run try to run your specs with Secondly do |
@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 puts "rspec pid: #{Process.pid}"
trap 'USR1' do
threads = Thread.list
puts
puts "=" * 80
puts "Received USR1 signal; printing all #{threads.count} thread backtraces."
threads.each do |thr|
description = thr == Thread.main ? "Main thread" : thr.inspect
puts
puts "#{description} backtrace: "
puts thr.backtrace.join("\n")
end
puts "=" * 80
end 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 The nice thing about this compared to |
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 or kill 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! |
Hmm thats a bit odd, are the zombie processes belonging to RSpec or rails? |
I can't really tell as this was the only the second project where I used RSpec (is there a way I could dig deeper to find out) because when I ran "rails s", the browser was working just fine. The code worked. It just broke when I ran rspec. |
thanks, @myronmarston ! i don't have zombies but do have hanging tests so your comment is really helpful. |
@myronmarston -- your suggestion above was a life-saver, thank you! |
I have one hanging test. Using the recommendation from @myronmarston I got following output: Received USR1 signal; printing all 1 thread backtraces. Main thread backtrace:
How may I identify the source of my problem? |
@cicio look at the backtrace. The first 4 lines are from After that comes |
Thanks @myronmarston for the help: I got alternating results by sending consecutive signals (kill -USR1 : Based on your recommended troubleshooting steps I was able to identified the line of code that caused it. The problem was a condition written with the operator ? : , instead of if else. It is solved. Once the error was removed all test resumed and passed. Thank you |
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 |
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. |
@pmichaeljones It's an interesting case. I believe the error message should bubble up. Do you care to open a ticket provided a reproduction example repo? |
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). |
+1 to documenting this. I'm upgrading a Rails app and Rspec tests were hanging. Thanks to @myronmarston I was able to connect this issue to this post https://thoughtbot.com/blog/multi-thread-backtrace-for-silently-hanging-tests Restarting postgres service did the trick for me. My specs were getting stuck specifically in "connection_pool.rb sleep". |
Add info about simplecov hanging CI node: rspec/rspec-rails#1353 (comment)
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:
The text was updated successfully, but these errors were encountered: