Bug 1508287 - Refactor server xpcshell tests that do not pass in worker context. r=yulia
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 22 Nov 2018 15:23:26 +0000
changeset 504189 14c07af09b66f52379a25519edcebf2d8e6e0178
parent 504188 fc126a74993d098fb394a1204877833c458c2570
child 504190 3e6a10079e5c6b60a885cfb2bdeb6fef1c730acf
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1508287
milestone65.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 1508287 - Refactor server xpcshell tests that do not pass in worker context. r=yulia MozReview-Commit-ID: 4qGo1ZF7ITC Depends on D12311 Differential Revision: https://phabricator.services.mozilla.com/D12312
devtools/server/tests/unit/head_dbg.js
devtools/server/tests/unit/test_ignore_caught_exceptions.js
devtools/server/tests/unit/test_ignore_no_interface_exceptions.js
devtools/server/tests/unit/test_listsources-04.js
devtools/server/tests/unit/test_pause_exceptions-03.js
--- a/devtools/server/tests/unit/head_dbg.js
+++ b/devtools/server/tests/unit/head_dbg.js
@@ -844,19 +844,21 @@ async function setupTestFromUrl(url) {
  *        - ThreadClient threadClient
  *          A reference to a ThreadClient instance that is attached to the debuggee.
  *        - DebuggerClient client
  *          A reference to the DebuggerClient used to communicated with the RDP server.
  * @param Object options
  *        Optional arguments to tweak test environment
  *        - JSPrincipal principal
  *          Principal to use for the debuggee.
+ *        - boolean doNotRunWorker
+ *          If true, do not run this tests in worker debugger context.
  */
 function threadClientTest(test, options = {}) {
-  let { principal } = options;
+  let { principal, doNotRunWorker } = options;
   if (!principal) {
     principal = systemPrincipal;
   }
 
   async function runThreadClientTestWithServer(server, test) {
     // Setup a server and connect a client to it.
     initTestDebuggerServer(server);
 
@@ -886,12 +888,15 @@ function threadClientTest(test, options 
     // Also cleanup the created server
     server.destroy();
   }
 
   return async () => {
     dump(">>> Run thread client test against a regular DebuggerServer\n");
     await runThreadClientTestWithServer(DebuggerServer, test);
 
-    dump(">>> Run thread client test against a worker DebuggerServer\n");
-    await runThreadClientTestWithServer(WorkerDebuggerServer, test);
+    // Skip tests that fail in the worker context
+    if (!doNotRunWorker) {
+      dump(">>> Run thread client test against a worker DebuggerServer\n");
+      await runThreadClientTestWithServer(WorkerDebuggerServer, test);
+    }
   };
 }
--- a/devtools/server/tests/unit/test_ignore_caught_exceptions.js
+++ b/devtools/server/tests/unit/test_ignore_caught_exceptions.js
@@ -4,59 +4,41 @@
 
 "use strict";
 
 /**
  * Test that setting ignoreCaughtExceptions will cause the debugger to ignore
  * caught exceptions, but not uncaught ones.
  */
 
-var gDebuggee;
-var gClient;
-
-function run_test() {
-  do_test_pending();
-  run_test_with_server(DebuggerServer, function() {
-    run_test_with_server(WorkerDebuggerServer, do_test_finished);
-  });
-}
-
-function run_test_with_server(server, callback) {
-  initTestDebuggerServer(server);
-  gDebuggee = addTestGlobal("test-pausing", server);
-  gClient = new DebuggerClient(server.connectPipe());
-  gClient.connect(test_pause_frame);
-}
-
-async function test_pause_frame() {
-  const [,, threadClient] = await attachTestTabAndResume(gClient, "test-pausing");
-  await executeOnNextTickAndWaitForPause(evaluateTestCode, gClient);
-
-  evaluateTestCode();
+add_task(threadClientTest(async ({ threadClient, client, debuggee }) => {
+  await executeOnNextTickAndWaitForPause(() => evaluateTestCode(debuggee), client);
 
   threadClient.pauseOnExceptions(true, true);
   await resume(threadClient);
-  const paused = await waitForPause(gClient);
+  const paused = await waitForPause(client);
   Assert.equal(paused.why.type, "exception");
   equal(paused.frame.where.line, 6, "paused at throw");
 
   await resume(threadClient);
-  finishClient(gClient);
-}
+}, {
+  // Bug 1508289, exception tests fails in worker scope
+  doNotRunWorker: true,
+}));
 
-function evaluateTestCode() {
+function evaluateTestCode(debuggee) {
   /* eslint-disable */
   try {
   Cu.evalInSandbox(`                    // 1
    debugger;                            // 2
    try {                                // 3           
      throw "foo";                       // 4
    } catch (e) {}                       // 5
    throw "bar";                         // 6  
   `,                                    // 7
-    gDebuggee,
+    debuggee,
     "1.8",
     "test_pause_exceptions-03.js",
     1
   );
   } catch (e) {}
   /* eslint-disable */
 }
--- a/devtools/server/tests/unit/test_ignore_no_interface_exceptions.js
+++ b/devtools/server/tests/unit/test_ignore_no_interface_exceptions.js
@@ -3,62 +3,45 @@
 
 "use strict";
 
 /**
  * Test that the debugger automatically ignores NS_ERROR_NO_INTERFACE
  * exceptions, but not normal ones.
  */
 
-var gDebuggee;
-var gClient;
-
-function run_test() {
-  do_test_pending();
-  run_test_with_server(DebuggerServer, function() {
-    run_test_with_server(WorkerDebuggerServer, do_test_finished);
-  });
-}
-
-function run_test_with_server(server, callback) {
-  initTestDebuggerServer(server);
-  gDebuggee = addTestGlobal("test-pausing", server);
-  gClient = new DebuggerClient(server.connectPipe());
-  gClient.connect(test_pause_frame);
-}
-
-async function test_pause_frame() {
-  const [,, threadClient] = await attachTestTabAndResume(gClient, "test-pausing");
-
+add_task(threadClientTest(async ({ threadClient, debuggee, client }) => {
   await threadClient.pauseOnExceptions(true, false);
-  await executeOnNextTickAndWaitForPause(evaluateTestCode, gClient);
+  await executeOnNextTickAndWaitForPause(() => evaluateTestCode(debuggee), client);
 
   await resume(threadClient);
-  const paused = await waitForPause(gClient);
+  const paused = await waitForPause(client);
   Assert.equal(paused.why.type, "exception");
   equal(paused.frame.where.line, 12, "paused at throw");
 
   await resume(threadClient);
-  finishClient(gClient);
-}
+}, {
+  // Bug 1508289, exception tests fails in worker scope
+  doNotRunWorker: true,
+}));
 
-function evaluateTestCode() {
+function evaluateTestCode(debuggee) {
   /* eslint-disable */
   Cu.evalInSandbox(`                    // 1
     function QueryInterface() {         // 2
       throw Cr.NS_ERROR_NO_INTERFACE;   // 3
     }                                   // 4
     function stopMe() {                 // 5
       throw 42;                         // 6
     }                                   // 7
     try {                               // 8
       QueryInterface();                 // 9
     } catch (e) {}                      // 10
     try {                               // 11
       stopMe();                         // 12
     } catch (e) {}`,                    // 13
-    gDebuggee,
+    debuggee,
     "1.8",
     "test_ignore_no_interface_exceptions.js",
     1
   );
   /* eslint-disable */
 }
--- a/devtools/server/tests/unit/test_listsources-04.js
+++ b/devtools/server/tests/unit/test_listsources-04.js
@@ -5,49 +5,32 @@
 "use strict";
 
 /**
  * Check getSources functionality with sourcemaps.
  */
 
 const {SourceNode} = require("source-map");
 
-function run_test() {
-  run_test_with_server(DebuggerServer, function() {
-    // Bug 1304144 - This test does not run in a worker because the
-    // `rpc` method which talks to the main thread does not work.
-    // run_test_with_server(WorkerDebuggerServer, do_test_finished);
-    do_test_finished();
-  });
-  do_test_pending();
-}
+add_task(threadClientTest(async ({ threadClient, debuggee }) => {
+  await threadClient.reconfigure({ useSourceMaps: true });
+  addSources(debuggee);
+
+  const res = await threadClient.getSources();
+  Assert.equal(res.sources.length, 3, "3 sources exist");
 
-function run_test_with_server(server, cb) {
-  (async function() {
-    initTestDebuggerServer(server);
-    const debuggee = addTestGlobal("test-sources", server);
-    const client = new DebuggerClient(server.connectPipe());
-    await client.connect();
-    const [,, threadClient] = await attachTestTabAndResume(client, "test-sources");
-
-    await threadClient.reconfigure({ useSourceMaps: true });
-    addSources(debuggee);
+  await threadClient.reconfigure({ useSourceMaps: false });
 
-    threadClient.getSources(async function(res) {
-      Assert.equal(res.sources.length, 3, "3 sources exist");
-
-      await threadClient.reconfigure({ useSourceMaps: false });
-
-      threadClient.getSources(function(res) {
-        Assert.equal(res.sources.length, 1, "1 source exist");
-        client.close().then(cb);
-      });
-    });
-  })();
-}
+  const res2 = await threadClient.getSources();
+  Assert.equal(res2.sources.length, 1, "1 source exist");
+}, {
+  // Bug 1304144 - This test does not run in a worker because the
+  // `rpc` method which talks to the main thread does not work.
+  doNotRunWorker: true,
+}));
 
 function addSources(debuggee) {
   let { code, map } = (new SourceNode(null, null, null, [
     new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"),
     new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"),
     new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"),
   ])).toStringWithSourceMap({
     file: "abc.js",
--- a/devtools/server/tests/unit/test_pause_exceptions-03.js
+++ b/devtools/server/tests/unit/test_pause_exceptions-03.js
@@ -4,57 +4,41 @@
 
 "use strict";
 
 /**
  * Test that setting pauseOnExceptions to true will cause the debuggee to pause
  * when an exception is thrown.
  */
 
-var gDebuggee;
-var gClient;
-
-function run_test() {
-  do_test_pending();
-  run_test_with_server(DebuggerServer, function() {
-    run_test_with_server(WorkerDebuggerServer, do_test_finished);
-  });
-}
-
-function run_test_with_server(server, callback) {
-  initTestDebuggerServer(server);
-  gDebuggee = addTestGlobal("test-pausing", server);
-  gClient = new DebuggerClient(server.connectPipe());
-  gClient.connect(test_pause_frame);
-}
-
-async function test_pause_frame() {
-  const [,, threadClient] = await attachTestTabAndResume(gClient, "test-pausing");
-  await executeOnNextTickAndWaitForPause(evaluateTestCode, gClient);
+add_task(threadClientTest(async ({ threadClient, client, debuggee }) => {
+  await executeOnNextTickAndWaitForPause(() => evaluateTestCode(debuggee), client);
 
   threadClient.pauseOnExceptions(true);
   await resume(threadClient);
-  const paused = await waitForPause(gClient);
+  const paused = await waitForPause(client);
   Assert.equal(paused.why.type, "exception");
   equal(paused.frame.where.line, 4, "paused at throw");
 
   await resume(threadClient);
-  finishClient(gClient);
-}
+}, {
+  // Bug 1508289, exception tests fails in worker scope
+  doNotRunWorker: true,
+}));
 
-function evaluateTestCode() {
+function evaluateTestCode(debuggee) {
   /* eslint-disable */
   Cu.evalInSandbox(
     `                                   // 1
     function stopMe() {                 // 2
       debugger;                         // 3
       throw 42;                         // 4
     }                                   // 5
     try {                               // 6
       stopMe();                         // 7
     } catch (e) {}`,                    // 8
-    gDebuggee,
+    debuggee,
     "1.8",
     "test_pause_exceptions-03.js",
     1
   );
   /* eslint-disable */
-}
\ No newline at end of file
+}