Integration tests and unfinished requests

Hi everyone, first timer here,

We have been experiencing an intermittent issue and I would like to see if someone in here has insight to how we can tackle it.

We are doing our integration tests with Minitest + Capybara and Chrome headless driver.

The issue is when a test is finished, the database gets ROLLBACK’d. There can still be some unfinished requests running, and crashes may occur if they try to access deleted database information.

This most commonly happens because of AJAX requests, and for this, we are using a wait_for_ajax helper (that we developed ourselves) to wait until the Browser has finished with his requests.

The less common problem happens with IMG HTML tags, if their are using an endpoint that redirects to another image URL.

Here is an example that for us would cause the issue 100% of the time:

upload_some_images # Uploads images visit ‘/list_of_images’ # Some page with list of images, you click on the image and it opens full-screen in a popup

find(‘.image-popup-open-button’).click # Open image in a popup window assert_selector ‘.some-class-must-be-present’

``

This is a simple test, yet, it will always crash in our case with a ActiveRecord::RecordNotFound blob id=xxx error.

  • What happens is that when opening the popup window, an IMG tag with url /files/123 is added to the DOM. The Browser then queries that and gets redirected to the ActiveRecord representation URL.

  • The integration test is quite simple and validates if some class is present, then the test is finished and the database is ROLLBACK’d.

  • The browser continues doing his thing and accesses ActiveRecord representation URL, which then tries to load a blob that does not exist anymore, and result in a crash.

Does anyone ever had such a problem, if so, how did you manage to avoid it?

I hope I am posting this in the right place, sorry if not… Thank you

TheBean