Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Race condition with capybara-webkit and DatabaseCleaner #602

Closed
miks opened this issue Dec 14, 2013 · 8 comments
Closed

Race condition with capybara-webkit and DatabaseCleaner #602

miks opened this issue Dec 14, 2013 · 8 comments

Comments

@miks
Copy link
Contributor

miks commented Dec 14, 2013

We have js functionality that calls load json on page load.
It's making problem when DatabaseCleaner is cleaning database in rspec "after" hook while capybara-webkit is still somehow active and doing request to controller.

We have hook like this, but it not working correctly all the times as sometimes json loading happpen even after this hook.

config.after(:each) do
    if Capybara.current_driver != :rack_test
      safety = 10
      while (page.evaluate_script('jQuery.active').to_i > 0) && (safety > 0)
        safety -= 1
        sleep 0.5
      end
    end
end

Question: is there some way to tell capybara-webkit to stop all request or even close tab/window after test is finished?

@jferris
Copy link
Member

jferris commented Dec 16, 2013

Active requests are generally terminated when calling reset on capybara. Is it possible that you're trying to clean the database before reset is called? Can you paste some of your capybara or database_cleaner setup?

On Saturday, December 14, 2013 at 5:36 AM, Miks Miķelsons wrote:

We have js functionality that calls load json on page load.
It's making problem when DatabaseCleaner is cleaning database in rspec "after" hook while capybara-webkit is still somehow active and doing request to controller.
We have hook like this, but it not working correctly all the times as sometimes json loading happpen even after this hook.
config.after(:each) do if Capybara.current_driver != :rack_test safety = 10 while (page.evaluate_script('jQuery.active').to_i > 0) && (safety > 0) safety -= 1 sleep 0.5 end end end
Question: is there some way to tell capybara-webkit to stop all request or even close tab/window after test is finished?


Reply to this email directly or view it on GitHub (#602).

@miks
Copy link
Contributor Author

miks commented Dec 16, 2013

Here it is https://gist.github.com/miks/7990167

@jferris
Copy link
Member

jferris commented Dec 16, 2013

It's possible that something else is running asynchronously. The two that jump out at me from your spec_helper are Sidekiq and and ParallelTests. I haven't tried either of those recently and I'm not sure if there would be any issues.

On Monday, December 16, 2013 at 11:48 AM, Miks Miķelsons wrote:

Here it is https://gist.github.com/miks/7990167


Reply to this email directly or view it on GitHub (#602 (comment)).

@tf
Copy link

tf commented Dec 20, 2013

I am experiencing the same problem. Placing a sleep 1 before my DatabaseCleaner.clean resolves the issue, but is obviously not the solution.

@miks
Copy link
Contributor Author

miks commented Dec 21, 2013

@jferris: problem already existed before Sidekiq was added to project. @tf do you happen to have ParalleTest in your project?

@tf
Copy link

tf commented Dec 23, 2013

@miks No. Simply, rspec (2.14.1), capybara (2.1.0), capybara-webkit (1.0.0).

@miks
Copy link
Contributor Author

miks commented Mar 6, 2014

Actually it's very simply to recreate this error. Just add continuous ajax content loading (for example: call function itself to load data one more time on successful ajax request).
So, I guess it's more related to rspec after hook.

@miks
Copy link
Contributor Author

miks commented Mar 6, 2014

Ok, it's due to fact that capybara "after" hook (defined within gem) is called after all other after hooks described within project (spec_helper.rb).

Just add "Capybara.reset_sessions!" before database cleanup:

Capybara.reset_sessions!
DatabaseCleaner.clean

@miks miks closed this as completed Mar 6, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants