Bug 1493837 - Fix intermittent on browser_jsterm_await.js; r=Honza.

The test is failing because the result of the last
evaluation is received before we expect it. Since we
had a 500ms delay between each promise resolution, it
might happen than the time it takes to execute the
command execedes this delay, making our expected message
order wrong.
Increasing the delay between each Promise resolution seems
to resolve the issue, although it makes the test a lot longer too.
This is why a new test was created to only cover the concurrent
await case.

Differential Revision: https://phabricator.services.mozilla.com/D8698

--HG--
rename : devtools/client/webconsole/test/mochitest/browser_jsterm_await.js => devtools/client/webconsole/test/mochitest/browser_jsterm_await_concurrent.js
extra : moz-landing-system : lando
This commit is contained in:
Nicolas Chevobbe 2018-10-19 07:06:12 +00:00
parent e60786d47f
commit 961f0c1eca
3 changed files with 53 additions and 29 deletions

View File

@ -205,6 +205,7 @@ skip-if = verify
[browser_jsterm_autocomplete_return_key.js]
[browser_jsterm_autocomplete_width.js]
[browser_jsterm_autocomplete-properties-with-non-alphanumeric-names.js]
[browser_jsterm_await_concurrent.js]
[browser_jsterm_await_error.js]
[browser_jsterm_await_helper_dollar_underscore.js]
[browser_jsterm_await_paused.js]

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that top-level await expression work as expected.
// Test that top-level await expressions work as expected.
"use strict";
@ -21,7 +21,6 @@ add_task(async function() {
async function performTests() {
const hud = await openNewTabAndConsole(TEST_URI);
const {jsterm} = hud;
const executeAndWaitForResultMessage = (input, expectedOutput) =>
executeAndWaitForMessage(hud, input, expectedOutput, ".result");
@ -34,8 +33,8 @@ async function performTests() {
);
// Check that the resulting promise of the async iife is not displayed.
let messages = hud.ui.outputNode.querySelectorAll(".message .message-body");
let messagesText = Array.from(messages).map(n => n.textContent).join(" - ");
const messages = hud.ui.outputNode.querySelectorAll(".message .message-body");
const messagesText = Array.from(messages).map(n => n.textContent).join(" - ");
is(messagesText, `${simpleAwait} - Array [ "await1" ]`,
"The output contains the the expected messages");
@ -62,31 +61,6 @@ async function performTests() {
);
ok(message.node, "`x` was assigned as expected");
info("Check that concurrent await expression work fine");
hud.ui.clearOutput();
const delays = [1000, 500, 2000, 1500];
const inputs = delays.map(delay => `await new Promise(
r => setTimeout(() => r("await-concurrent-" + ${delay}), ${delay}))`);
// Let's wait for the message that sould be displayed last.
const onMessage = waitForMessage(hud, "await-concurrent-2000", ".message.result");
for (const input of inputs) {
jsterm.execute(input);
}
await onMessage;
messages = hud.ui.outputNode.querySelectorAll(".message .message-body");
messagesText = Array.from(messages).map(n => n.textContent);
const expectedMessages = [
...inputs,
`"await-concurrent-500"`,
`"await-concurrent-1000"`,
`"await-concurrent-1500"`,
`"await-concurrent-2000"`,
];
is(JSON.stringify(messagesText, null, 2), JSON.stringify(expectedMessages, null, 2),
"The output contains the the expected messages, in the expected order");
info("Check that a logged promise is still displayed as a promise");
message = await executeAndWaitForResultMessage(
`new Promise(r => setTimeout(() => r(1), 1000))`,

View File

@ -0,0 +1,49 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that multiple concurrent top-level await expressions work as expected.
"use strict";
const TEST_URI = "data:text/html;charset=utf-8,Web Console test top-level await";
add_task(async function() {
// Enable await mapping.
await pushPref("devtools.debugger.features.map-await-expression", true);
// Run test with legacy JsTerm
await pushPref("devtools.webconsole.jsterm.codeMirror", false);
await performTests();
// And then run it with the CodeMirror-powered one.
await pushPref("devtools.webconsole.jsterm.codeMirror", true);
await performTests();
});
async function performTests() {
const hud = await openNewTabAndConsole(TEST_URI);
const {jsterm} = hud;
hud.ui.clearOutput();
const delays = [3000, 500, 9000, 6000];
const inputs = delays.map(delay => `await new Promise(
r => setTimeout(() => r("await-concurrent-" + ${delay}), ${delay}))`);
// Let's wait for the message that sould be displayed last.
const onMessage = waitForMessage(hud, "await-concurrent-9000", ".message.result");
for (const input of inputs) {
jsterm.execute(input);
}
await onMessage;
const messages = hud.ui.outputNode.querySelectorAll(".message .message-body");
const messagesText = Array.from(messages).map(n => n.textContent);
const expectedMessages = [
...inputs,
`"await-concurrent-500"`,
`"await-concurrent-3000"`,
`"await-concurrent-6000"`,
`"await-concurrent-9000"`,
];
is(JSON.stringify(messagesText, null, 2), JSON.stringify(expectedMessages, null, 2),
"The output contains the the expected messages, in the expected order");
}