fix(tests): Prevent router_test.exs from running async #2288
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Most tests rely on the
HOST
environment variable to be set tonil
, so that it defaults tolocalhost
. IfHOST
is set towww.mbta.com
, that causes a redirect.router_test.exs
has a test that validates that redirect, by settingHOST
towww.mbta.com
, validating the redirect, and then setting it back tonil
.This is what that normally looks like in context:
(Note the existence of
OtherTest
, which also retrievesHOST
, and relies onHOST
beingnil
.)BUT, when
router_test.exs
's execution is interleaved with other tests, then sometimes another test will try to retrieveHOST
(well, another test will invoke aconn
, which then invokesHOST
through the CanonicalHostname plug) beforerouter_test.exs
has setHOST
back tonil
.The
conn
invoked byOtherTest
gets thewww.mbta.com
HOST
and does a redirect, which the other test wasn't expecting, and fails.This creates a very challenging debugging environment, because, in this context,
OtherTest
could refer to literally any other test that makes an HTTP request or does anything with aconn
. This bug was causing very rare non-deterministic failures in every other HTTP-related test.The solution here is to remove the
async: true
flag fromrouter_test.exs
, preventing it from interleaving itself with other tests.Hat-tip to @thecristen for helping me figure out that this CanonicalHostname plug was the culprit.