How do I get a backtrace of hanging Ruby process? - ruby

There is a complex testing suite with Capybara, Selenium, Allure and it's all abused:
it launches and exits Chrome on its own, not leaving this job to Capybara
before and after hooks are put in wrong places, causing such effects as, for example, filling remote DB when you do just rspec --dry-run
Allure reports gem is pretty much abandoned and I believe is integrated here also not without wrong practices
Now when I run tests sometimes they hang, so I press ^C but they don't stop:
RSpec is shutting down and will print the summary report... Interrupt again to force quit.
It does not stop no matter how long I wait and even when I close the browser manually.
When I press ^C again it prints nothing -- no backtrace.
How do I know where it hangs? How do I get a backtrace of it at any moment?

Related

Are there inconsistencies between Cypress tool and running them from the terminal?

i'm evaluating Cypress (Version 3.4.1), and running into inconsistencies between running the same tests from the cypress tool and running them from the terminal, i'm using the same browser in both cases (Electron 61). Anyone experienced this? (failing test from the terminal, but same test runs smoothly from the Cypress tool)
The interactive test runner can be flakey, but I do not see the same issues when I run without the interactive test runner. I wouldn't worry about the test failing in the interactive test runner if it passes when you refresh the page, or passes when run via command line. Use the browser refresh button not the interactive test runner refresh button.
Note: cypress is pretty heavy on your resources. I noticed I have intermittent failures when doing a screen share.
While running Cypress rest from command, I found that the test finishes with All specs passed, but yet it didn't complete the full iterations (last one is to save form in db, didn't happen).
I didn't know why? I tried to change the Cypress code but with no result.
I decided to check the recorded video after test finishes from terminal so I enabled video recording and TARAA!! Test finished correctly. Once I disable video recording It fails.

Capybara/Cucumber/Ruby issue: Control+C close bowser session

After update ruby and some gems version on my project, when I press control+c in a cucumber execution console, browser instance is totally closed....... when until now, console proccess was finished but the webdriver instance in the browser remains open and was interactive manually.....
Where could be the problem?
Some ruby or cucumber environment gem?
Webdriver?
Some hack to fix without roll back to all previous versions?
I´ve already tried to come back to previous ruby version but i still have the problem.
Thanks.
Are you sure your code doesn't call quit or close on the selenium instance? Regardless, it doesn't strike me as particularly surprising that the browser instance would close if it's caller script ended.
I haven't actually done this myself but I've read a bit about methods to keep a selenium-launched browser persistently open.
It basically involves launching a selenium browser from a separate process and then configuring your code to connect to that existing instance. See this SO question on the topic (how-to-use-attach-an-existing-browser-using-selenium).
Another option is to run Selenium server and have your code send a command to start a browser instance. The plus side of this is you have a handy web interface to track all your running selenium instances.

Rescue, exceptions in Ruby's selenium-webdriver, not to terminate program

I tried finding how to rescue selenium from terminating my program session, however I could not.
It would be great if anybody could give one, or maybe several exceptions to include in a selenium program, for a script not to crash.
To give more details, for example, one case can be that when page load takes too long, then in console application running process terminates and profiled browser keeps on running. I would like a process not to terminate, somehow.
I am sure there are other cases other than load time, program terminates / stops to run for other reasons of selenium I guess and that is what I want to handle.
I would like my program not to exit automatically, but whenever it actually should stop.
Thanks.

Rspec process hangs at different places, process cannot be killed. How to diagnose?

In a rails application I'm developing (on OS-X), I'm finding running the test suite via rspec locking up increasingly frequently. It does not happen every time. I've tried adding --format documentation when running the suite to see if it happens at the same place every time, and it does not.
I've tried killing the process with kill -9. It then changes the name to (ruby) with a process status of ?E. This link suggests that the process is blocked waiting for a system call to finish. I have to restart my machine every time this happens in order to kill this process.
I've tried re-installing rvm, ruby, mysql, and imagemagick. This project is using imagemagick (via the mini_magick) gem, and I suspected that it may be one of these commands that is causing rspec to block. I tried adding puts statements around each of the mini_magick commands to ensure they finish executing, and all looks fine.
I'm looking for suggestions on how to diagnose this issue.
It's possible your problem is an order-dependency bug, you can pass the seed along and the order will remain consistent.
RSpec prints out the random number it used to seed the randomizer.
Use this number to run rspec with the same order
--order rand:3455

Matlab onCleanup with Compiled applications (windows)

I have an application made with matlab compiler.
I want to do some shutdown activities whenever it ends. As it seems to be impossible to catch signals in matlab (or I'm not able to), I checked to use onCleanup (Matlab: Is it possible to create signal handlers (.m scripts)). It is working within matlab (native), but not within the compiled application.
I tried to end the application with CTRL-C and with taskkill (which only work with /f). In both cases the onCleanup-method was NOT executed.
For testing purposes here
function sigtest(varargin)
remainder=onCleanup(#()save('exit.mat'));
b=1;
while true
disp(datestr(now));
a=rand(round(5*b));%to be saved
pause(10);
b=a(1);
end
my source code, which I compiled via mcc -m -v sigtest.m.
As onether try, I inserted the lines
myexiter=addlistener(System.AppDomain.CurrentDomain,'ProcessExit',...
#(a,b)save('listexit.mat'));
after line 2, but also this .NET-Event is not working.
If you're registering shutdown activities within M-code, they're only going to work on a graceful shutdown of the process. The taskkill /f command will do a "forceful" shutdown, which I think will terminate the process immediately. The Matlab interpreter won't get a chance to run whatever cleanup code is still pending. I think Ctrl-C on a console application (which the compiled sigtest.m will be running as) will have the same effect. Same applies to the .NET-Event: if you forcefully kill the process, that callback never gets a chance to run.
If you want on-exit code, or any other cleanup stuff, to run, you need to find a way for the program to find out when it should exit and initiate a more graceful shutdown itself. For example, in your sigtest example, you could check stdin at the end of every pass through the loop, see if the user has typed 'quit', and if so call exit(). Then your onCleanup stuff should run.
In a GUI compiled Matlab application, this is more straightforward; you have GUI controls to exit the application. I don't know what the canonical way is to make a console compiled Matlab application responsive to user exit requests, or if there even is a good one. You might want to make this a GUI app if you think the user might want to request a graceful abort of its operation.

Resources