Postgres connection timeout in Wallaby acceptance tests

293 Views Asked by At

I’m having a couple issues with Postgres timeouts in my Wallaby tests. The error I’m getting is:

[error] Postgrex.Protocol (#PID<0.349.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.566.0> timed out because it owned the connection for longer than 15000ms

It happens locally when I try to chain a click(button("Submit")) event (I think all the ones I’ve had issues with do a form submission, <a> links seems to work fine) with a CSS assertion like assert_has(link("Sign Out"). If I pass the session from the context instead of piping the two together it seems to be okay. However, it still fails on the CI server (Travis).

It kind of sounds like the issue described above (“often times in our test suites the error that an action is performed and one goes on to another page without waiting that the action completed, creating a race condition”), but it fails or succeeds consistently rather than being flaky so I’m wondering if there’s not something I’m missing.

Here’s the PR that’s failing, if you wanna see the actual code: https://github.com/solid-af/cheese_log/pull/18

I should also mention that (while testing locally) it looks like the assertion that’s failing after the timeout should have been successful. If I remove the explicit return of session in RegistrationPage.register_with, the line that’s failing is RegistrationPage.assert_registered(). I have screenshot_on_failure turned on. The screenshot from that shows the form filled out, but not submitted, while the manual take_screenshot() line above shows the home page with the “successfully registered” text. Super weird!

|> RegistrationPage.register_with(@valid_attrs)
|> take_screenshot()
|> RegistrationPage.assert_registered()

edit: though the issues I’m having locally seem to be unrelated to the issue I’m having on CI. As pointed out below, that is likely something do to with the connection staying logged in somehow.

2

There are 2 best solutions below

6
On

I have the same problem in test env. Add this in your config/test.exs file under data base config

ownership_timeout: 60_000

This should do the trick. The error you are getting is because by default the time set is 15000. So if any process takes longer than that Db throws an error.

1
On

The issue is not where you expect it to be. Assertion RegistrationPage.assert_registered() succeeds. You have issues signing out and the subsequent call to Page.click_sign_in() fails. Basically, your test stays logged in forever.

I have modified the code in sign_in_test.exs to visit a homepage and then take a screenshot:

  test "user can sign in", %{session: session} do
    session
    |> Page.visit_home_page()
    |> Page.click_sign_in()
    |> SignInPage.click_register_link()
    |> RegistrationPage.register_with(@valid_attrs)
    |> RegistrationPage.assert_registered()
    |> Page.click_sign_out()
    |> Page.visit_home_page()

    |> take_screenshot() # HERE

    |> Page.click_sign_in()
    |> SignInPage.sign_in_with(@valid_attrs)
    |> SignInPage.assert_signed_in()
  end

And the screenshot shows there is still “Sign Out” visible:

Screenshot after click_sign_out