I recently added some code that uses Capybara::Poltergeist to fetch information from pages that work with JavaScript. (I'll be happy to replace it with a something else if there is an option)
The I load the page , input some data into it , click a button , wait for return value.
In order to try and have as little memory leaks , zombie processes etc. I use the following:
Capybara.default_driver = :poltergeist
Capybara.default_max_wait_time = 60
Capybara.javascript_driver = :poltergeist
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {js_errors: false} )
end
capybara_session = Capybara::Session.new(:poltergeist , timeout: 60 )
I do some actions .....
capybara_session.try(:reset_session!)
capybara_session.try(:driver).try(:quit)
Capybara.try(:drivers).try(:clear)
But I'm still getting "can't create Thread: Resource temporarily unavailable" after a few hours of operation.
Any idea how to solve or replace this?
The main issue here is the incorrect use of Session.new. The second parameter to Session.new is supposed to be the app being tested, and if passed in triggers the creation of a server thread for that app. Since you're not actually testing an app that parameter should be nil (which it defaults to) so
capybara_session = Session.new(:poltergeist)
The timeout: 60
option gets passed to the driver when creating it.
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, js_errors: false, timeout: 60 )
end