Bug 1646456 - Add xpcshell test to check pool destruction when connection closes r=nchevobbe
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 23 Jun 2020 10:13:59 +0000
changeset 600947 8704e81643c67e889a76479065d3ba7900a2f672
parent 600946 7ca3d4bada7371ff782a50f74a29126ad050a38a
child 600948 fdabfde164e98448cd76dc229e204b1749f0a00c
push id13310
push userffxbld-merge
push dateMon, 29 Jun 2020 14:50:06 +0000
treeherdermozilla-beta@15a59a0afa5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1646456
milestone79.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 1646456 - Add xpcshell test to check pool destruction when connection closes r=nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D80059
devtools/server/tests/xpcshell/test_connection_closes_all_pools.js
devtools/server/tests/xpcshell/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/devtools/server/tests/xpcshell/test_connection_closes_all_pools.js
@@ -0,0 +1,100 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const { Pool } = require("devtools/shared/protocol/Pool");
+const {
+  DevToolsServerConnection,
+} = require("devtools/server/devtools-server-connection");
+const {
+  LocalDebuggerTransport,
+} = require("devtools/shared/transport/local-transport");
+
+// Helper class to assert how many times a Pool was destroyed
+class FakeActor extends Pool {
+  constructor(...args) {
+    super(...args);
+    this.destroyedCount = 0;
+  }
+
+  destroy() {
+    this.destroyedCount++;
+    super.destroy();
+  }
+}
+
+add_task(async function() {
+  const transport = new LocalDebuggerTransport();
+  const conn = new DevToolsServerConnection("prefix", transport);
+
+  // Setup a flat pool hierarchy with multiple pools:
+  //
+  // - pool1
+  //   |
+  //   \- actor1
+  //
+  // - pool2
+  //   |
+  //   |- actor2a
+  //   |
+  //   \- actor2b
+  //
+  // From the point of view of the DevToolsServerConnection, the only pools
+  // registered in _extraPools should be pool1 and pool2. Even though actor1,
+  // actor2a and actor2b extend Pool, they don't manage other pools.
+  const actor1 = new FakeActor(conn);
+  const pool1 = new Pool(conn, "pool-1");
+  pool1.manage(actor1);
+
+  const actor2a = new FakeActor(conn);
+  const actor2b = new FakeActor(conn);
+  const pool2 = new Pool(conn, "pool-2");
+  pool2.manage(actor2a);
+  pool2.manage(actor2b);
+
+  ok(!!actor1.actorID, "actor1 has a valid actorID");
+  ok(!!actor2a.actorID, "actor2a has a valid actorID");
+  ok(!!actor2b.actorID, "actor2b has a valid actorID");
+
+  conn.close();
+
+  equal(actor1.destroyedCount, 1, "actor1 was successfully destroyed");
+  equal(actor2a.destroyedCount, 1, "actor2 was successfully destroyed");
+  equal(actor2b.destroyedCount, 1, "actor2 was successfully destroyed");
+});
+
+add_task(async function() {
+  const transport = new LocalDebuggerTransport();
+  const conn = new DevToolsServerConnection("prefix", transport);
+
+  // Setup a nested pool hierarchy:
+  //
+  // - pool
+  //   |
+  //   \- parentActor
+  //      |
+  //      \- childActor
+  //
+  // Since parentActor is also an ActorPool from the point of view of the
+  // DevToolsServerConnection, it will attempt to destroy it when looping on
+  // this._extraPools. But since `parentActor` is also a direct child of `pool`,
+  // it has already been destroyed by the Pool destroy() mechanism.
+  //
+  // Here we check that we don't call destroy() too many times on a single Pool.
+  // Even though Pool::destroy() is stable when called multiple times, we can't
+  // guarantee the same for classes inheriting Pool.
+  const childActor = new FakeActor(conn);
+  const parentActor = new FakeActor(conn);
+  const pool = new Pool(conn, "pool");
+  pool.manage(parentActor);
+  parentActor.manage(childActor);
+
+  ok(!!parentActor.actorID, "customActor has a valid actorID");
+  ok(!!childActor.actorID, "childActor has a valid actorID");
+
+  conn.close();
+
+  equal(parentActor.destroyedCount, 1, "parentActor was destroyed once");
+  equal(parentActor.destroyedCount, 1, "customActor was destroyed once");
+});
--- a/devtools/server/tests/xpcshell/xpcshell.ini
+++ b/devtools/server/tests/xpcshell/xpcshell.ini
@@ -234,8 +234,9 @@ support-files = xpcshell_debugging_scrip
 skip-if = true # breakpoint sliding is not supported bug 1525685
 [test_setBreakpoint-on-line-with-no-offsets-in-gcd-script.js]
 skip-if = true # breakpoint sliding is not supported bug 1525685
 [test_safe-getter.js]
 [test_shapes_highlighter_helpers.js]
 [test_symbolactor.js]
 [test_webext_apis.js]
 [test_restartFrame-01.js]
+[test_connection_closes_all_pools.js]