Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make AMP tests less flaky #14360

Closed
rsimha opened this issue Apr 2, 2018 · 11 comments · Fixed by #17213
Closed

Make AMP tests less flaky #14360

rsimha opened this issue Apr 2, 2018 · 11 comments · Fixed by #17213

Comments

@rsimha
Copy link
Contributor

rsimha commented Apr 2, 2018

The number of test failures / flakes during PR and push builds on Travis due to dirty global state appears to have increased over the recent weeks. It's time to explore ideas that will reduce flakiness by isolating tests from one another and eliminating dirty global state.

Some ideas:

(More ideas welcome via comments below)

@rsimha rsimha added this to the Sprint H1 April 2018 milestone Apr 2, 2018
@rsimha rsimha self-assigned this Apr 2, 2018
@rsimha rsimha added the P2: Soon label Apr 2, 2018
@alanorozco
Copy link
Member

alanorozco commented Apr 2, 2018

1. Stub experiment toggles by default

Some sort of test-time replacement of isExperimentOn and toggleExperiment so that they use stubs instead of affecting the window state. Tests that need to validate the behavior of these functions can be whitelisted.

2. Forbid experiment toggles in test

Disadvantage: tests need to be rewritten to stub a static method that checks for the experiment.

3. Force all services to be stubbed in tests

Services are likely to affect global state since they're singletons. Implement some mechanism (similar to above) to either:

  1. automatically mock services or
  2. forbid the direct use of services without mocks

This would also reduce the running time of a lot of tests.

@dreamofabear
Copy link

AKA return of the prodigal son: go/amp-test-excellence

/cc @lannka 😂

@rsimha
Copy link
Contributor Author

rsimha commented Jun 4, 2018

It turns out that several AMP tests do asynchronous stuff (like throwing errors), but don't correctly use the done() callback to indicate that the asynchronous tasks have completed.

This is being tracked by #15658

@dreamofabear
Copy link

dreamofabear commented Jul 6, 2018

FR: Run all tests in the scope of a child iframe such that window, document and other globals don't reference the test runner's window.

Motivation: #16586

@rsimha
Copy link
Contributor Author

rsimha commented Jul 31, 2018

Reopening, since we still haven't solved the global window / document issue.

@rsimha rsimha reopened this Jul 31, 2018
@lannka
Copy link
Contributor

lannka commented Jul 31, 2018

Did we explore Karma option, how possible it is to open separate browser tab for each test file (not each test case).

Another hacky idea regarding to the async code leakage (I don't quite like, but shared anyway):

@rsimha we've talked a bit that if we can wait a full tick at end of each test to make sure async executions not leaked to next test (those execution could potentially throw and unpredictably fail unrelated test).

We couldn't have it done in afterEach because for some reason thrown in beforeEach or afterEach would sometimes be swallowed by Mocha silently and stop all the remaining tests.

I'm wondering if we can hack/wrap the it method to do the job.

@ampprojectbot
Copy link
Member

This issue hasn't been updated in awhile. @rsimha Do you have any updates?

1 similar comment
@ampprojectbot
Copy link
Member

This issue hasn't been updated in awhile. @rsimha Do you have any updates?

@rsimha
Copy link
Contributor Author

rsimha commented Apr 30, 2020

Since this was filed, several things have been done to improve test flakiness (see PRs linked above). However, more remains to be done in the areas of improving transitions during tests (#9164), fixing incorrect use of test assertions (#28128), and preventing external network requests (#26756). Keeping this uber-issue around until they are done.

@rsimha
Copy link
Contributor Author

rsimha commented Apr 22, 2021

[Infra triage] Assigning this uber-issue to @rileyajones for visibility. It may no longer be useful to keep this issue around since most ideas have already been split off into separate efforts. Feel free to close if this is the case.

@rsimha
Copy link
Contributor Author

rsimha commented May 12, 2021

Closing this now that all AMP unit and integration tests are sandboxed by describes. Issues related global state will be tracked by #23837.

@rsimha rsimha closed this as completed May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants