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

Adding debug info to test isolation validation #373

Merged
merged 2 commits into from
Oct 29, 2018

Conversation

scalvert
Copy link
Contributor

@scalvert scalvert commented Oct 20, 2018

This PR builds on the existing work to detect when tests are not isolated.

Debug info is extracted from backburner using the new getDebugInfo method, which allows us to provide information, including stack trace information, to end users. We output that debug info to the console to allow 'click to open' functionality from within the stack traces, and additionally provide a summary of the debug info to test output.

TODO:

  • Add tests to ensure that, when backburner.DEBUG = true we gather and output debug info
  • Figure out correct version of ember-source

@@ -36,13 +68,23 @@ export function reportIfTestNotIsolated() {
let leakyTests = TESTS_NOT_ISOLATED.slice();
TESTS_NOT_ISOLATED.length = 0;

throw new Error(getMessage(leakyTests.length, leakyTests.join('\n')));
throw new Error(getMessage(leakyTests.length, leakyTests.join('\n'), _debugInfoSummary));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to console.error the various stacks that are still pending here, that will ensure the source maps are applied and makes things much more actionable IMHO

Copy link
Contributor Author

@scalvert scalvert Oct 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the summary will not contain the stacks. We'll format the stacks separately to output to the console. This is a summary view, which is basically

TESTS ARE NOT ISOLATED
The following (13) tests have one or more of pending timers, pending AJAX requests, pending test waiters, or are still in a runloop:
<list of tests>


We found the following information that may help you identify code that violated test isolation:
Pending timers: 3
Pending scheduled items: 0

More information has been printed to the console. Please use that information to help in debugging.

this._testDebugInfos.push(testDebugInfo);

this.fullTestNames.push(summary.fullTestName);
this.hasPendingRequests |= summary.hasPendingRequests;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZOMG my bits are all flipped! (🤡 bits...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seriously though, can we use booleans? My brain can't handle the bitwise operations...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are booleans. We're aggregating all the booleans from all the TestDebugInfo instances to determine, overall, if we have any pending requests from any of our tests. Remember, this is a summarized view.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I’m saying / asking is to avoid using bitwise operations (which |= is).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's a better way to aggregate all the booleans?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

let testDebugInfo = new TestDebugInfo(module, name, getSettledState());

if (typeof backburner.getDebugInfo === 'function') {
testDebugInfo.debugInfo = backburner.getDebugInfo();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I'd prefer to do this above the testDebugInfo creation so that we can pass it into the constructor, what do you think?

yarn.lock Outdated
@@ -5,14 +5,12 @@
"@babel/code-frame@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0.tgz#06e2ab19bdb535385559aabb5ba59729482800f8"
integrity sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update your global yarn version to 1.10.1 so we can avoid removing the integrity field data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly I have no integrity...

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good, thanks for all the hard work here! I left a couple of small comments inline for tweaking...

TESTS_NOT_ISOLATED.length = 0;
if (nonIsolatedTests.hasDebugInfo) {
nonIsolatedTests.printToConsole();
nonIsolatedTests.reset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat curious, wouldn't it be easier to do:

nonIsolatedTests = new TestInfoSummary();

If we do that, then AFAICT we don't need reset?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could that. :)

@scalvert
Copy link
Contributor Author

@rwjblue I think we're good here. Anything else you think I should add?

@scalvert
Copy link
Contributor Author

What about awaiting the isSettled?

@rwjblue
Copy link
Member

rwjblue commented Oct 27, 2018

IMHO, that should be separate

@rwjblue rwjblue changed the title [WIP] Adding debug info to test isolation validation Adding debug info to test isolation validation Oct 29, 2018
@rwjblue rwjblue merged commit 420bec2 into emberjs:master Oct 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants