Bug 1493837 - Fix intermittent on browser_jsterm_await.js; r=Honza.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Fri, 19 Oct 2018 07:06:12 +0000
changeset 500536 1ef10ec64cb7993648efa0b5a0dab01ea2be53e7
parent 500535 3e62b3523fb5f8af9996e88ff5e15d5edd4742fd
child 500537 d0a571485527107249ea5dcb59413452291f040d
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1493837
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
devtools/client/webconsole/test/mochitest/browser.ini
devtools/client/webconsole/test/mochitest/browser_jsterm_await.js
devtools/client/webconsole/test/mochitest/browser_jsterm_await_concurrent.js
--- a/devtools/client/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -200,16 +200,17 @@ skip-if = verify
 [browser_jsterm_autocomplete_inside_text.js]
 [browser_jsterm_autocomplete_native_getters.js]
 [browser_jsterm_autocomplete_nav_and_tab_key.js]
 [browser_jsterm_autocomplete_paste_undo.js]
 [browser_jsterm_autocomplete_return_key_no_selection.js]
 [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]
 [browser_jsterm_await.js]
 [browser_jsterm_completion_bracket_cached_results.js]
 [browser_jsterm_completion_bracket.js]
 [browser_jsterm_completion_case_sensitivity.js]
 [browser_jsterm_completion.js]
--- a/devtools/client/webconsole/test/mochitest/browser_jsterm_await.js
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_await.js
@@ -1,12 +1,12 @@
 /* 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";
 
 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);
@@ -16,31 +16,30 @@ add_task(async function() {
   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;
 
   const executeAndWaitForResultMessage = (input, expectedOutput) =>
     executeAndWaitForMessage(hud, input, expectedOutput, ".result");
 
   info("Evaluate a top-level await expression");
   const simpleAwait = `await new Promise(r => setTimeout(() => r(["await1"]), 500))`;
   await executeAndWaitForResultMessage(
     simpleAwait,
     `Array [ "await1" ]`,
   );
 
   // 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");
 
   // Check that the timestamp of the result is accurate
   const {
     visibleMessages,
     messagesById
   } = hud.ui.consoleOutput.getStore().getState().messages;
@@ -57,40 +56,15 @@ async function performTests() {
   );
 
   let message = await executeAndWaitForResultMessage(
     `"-" + x + "-"`,
     `"-await2-"`,
   );
   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))`,
     `Promise {`,
   );
   ok(message, "Promise are displayed as expected");
 }
copy from devtools/client/webconsole/test/mochitest/browser_jsterm_await.js
copy to devtools/client/webconsole/test/mochitest/browser_jsterm_await_concurrent.js
--- a/devtools/client/webconsole/test/mochitest/browser_jsterm_await.js
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_await_concurrent.js
@@ -1,12 +1,12 @@
 /* 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 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);
@@ -18,79 +18,32 @@ add_task(async function() {
   await pushPref("devtools.webconsole.jsterm.codeMirror", true);
   await performTests();
 });
 
 async function performTests() {
   const hud = await openNewTabAndConsole(TEST_URI);
   const {jsterm} = hud;
 
-  const executeAndWaitForResultMessage = (input, expectedOutput) =>
-    executeAndWaitForMessage(hud, input, expectedOutput, ".result");
-
-  info("Evaluate a top-level await expression");
-  const simpleAwait = `await new Promise(r => setTimeout(() => r(["await1"]), 500))`;
-  await executeAndWaitForResultMessage(
-    simpleAwait,
-    `Array [ "await1" ]`,
-  );
-
-  // 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(" - ");
-  is(messagesText, `${simpleAwait} - Array [ "await1" ]`,
-    "The output contains the the expected messages");
-
-  // Check that the timestamp of the result is accurate
-  const {
-    visibleMessages,
-    messagesById
-  } = hud.ui.consoleOutput.getStore().getState().messages;
-  const [commandId, resultId] = visibleMessages;
-  const delta = messagesById.get(resultId).timeStamp -
-    messagesById.get(commandId).timeStamp;
-  ok(delta >= 500,
-    `The result has a timestamp at least 500ms (${delta}ms) older than the command`);
-
-  info("Check that assigning the result of a top-level await expression works");
-  await executeAndWaitForResultMessage(
-    `x = await new Promise(r => setTimeout(() => r("await2"), 500))`,
-    `await2`,
-  );
-
-  let message = await executeAndWaitForResultMessage(
-    `"-" + x + "-"`,
-    `"-await2-"`,
-  );
-  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 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-2000", ".message.result");
+  const onMessage = waitForMessage(hud, "await-concurrent-9000", ".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 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-1000"`,
-    `"await-concurrent-1500"`,
-    `"await-concurrent-2000"`,
+    `"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");
-
-  info("Check that a logged promise is still displayed as a promise");
-  message = await executeAndWaitForResultMessage(
-    `new Promise(r => setTimeout(() => r(1), 1000))`,
-    `Promise {`,
-  );
-  ok(message, "Promise are displayed as expected");
 }