When writing a new Rails system test I ran into an issue where the
browser would hang and not close, eventually failing the test due to
pending requests. There were no clear pending requests and the requests
mentioned were AJAX calls that should have been made several pages ago.
I believe the cause is an AJAX call being cancelled almost immediately
after it was initiated, but I'm not 100% positive.
Code wise, it looks like the value of `env['REQUEST_URI']` that
increments the counter is different from the `env['REQUEST_URI']` that's
decremented in the `ensure` block.
This resolves the issue by storing the `env['REQUEST_URI']` value in a
variable so it will be consistent between counter calls.
* Backfill tests on pending requests behavior
* Implement parameterized wait time for wait_for_oending_requests
At some point, this might be worth being a top-level configuration.
* Re-implement counter mutex with a list of pending request envs
Set up for exposing more information to developers about pending requests.
* Expose pending requests in error message
This provides a bit more information to other developers about the state of their tests. Whether we include further information would require more feedback from other developers and how the community use the error message for debugging.
* Add safe fallback value to avoid passing `nil`
* Use a memory barrier on read operations for array
* Only store REQUEST_URI instead of env
* Revert back to fixed wait_time (60)
Keeping initial PR tidy and focused.
* Remove redundant attr reader
We already defined a getter for the value to ensure proper concurrent accessing.
* Ruby linter: single-line body for modifier if usage
* Ruby linter: single quotes