Bug 1497457 - Clear clients stored in remote client manager after tests;r=daisuke,ladybenko
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 27 Nov 2018 10:22:40 +0000
changeset 504661 5cda18843d7b6fe9bfbc20b9bfb0a5b3e0bfa84b
parent 504660 f0c4ce1b0cf99f1d14093327810c9b9ae6ff1191
child 504662 99da1452e409ddf36bcdc827aa13c6241092cbc0
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)
reviewersdaisuke, ladybenko
bugs1497457
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 1497457 - Clear clients stored in remote client manager after tests;r=daisuke,ladybenko Depends on D12040. If we don't cleanup the clients after the test, some tests may leak. Differential Revision: https://phabricator.services.mozilla.com/D12095
devtools/client/aboutdebugging-new/test/browser/head.js
devtools/client/shared/remote-debugging/remote-client-manager.js
--- a/devtools/client/aboutdebugging-new/test/browser/head.js
+++ b/devtools/client/aboutdebugging-new/test/browser/head.js
@@ -27,16 +27,20 @@ registerCleanupFunction(async function()
   try {
     const { adbAddon } = require("devtools/shared/adb/adb-addon");
     await adbAddon.uninstall();
   } catch (e) {
     // Will throw if the addon is already uninstalled, ignore exceptions here.
   }
   const { ADB } = require("devtools/shared/adb/adb");
   await ADB.kill();
+
+  const { remoteClientManager } =
+    require("devtools/client/shared/remote-debugging/remote-client-manager");
+  await remoteClientManager.removeAllClients();
 });
 
 /**
  * Enable the new about:debugging panel.
  */
 async function enableNewAboutDebugging() {
   await pushPref("devtools.aboutdebugging.new-enabled", true);
   await pushPref("devtools.aboutdebugging.network", true);
--- a/devtools/client/shared/remote-debugging/remote-client-manager.js
+++ b/devtools/client/shared/remote-debugging/remote-client-manager.js
@@ -24,17 +24,16 @@ class RemoteClientManager {
    * @param {Object}
    *        - client: {DebuggerClient}
    *        - transportDetails: {Object} typically a host object ({hostname, port}) that
    *          allows consumers to easily find the connection information for this client.
    */
   setClient(id, type, { client, transportDetails }) {
     const key = this._getKey(id, type);
     this._clients.set(key, { client, transportDetails });
-
     client.addOneTimeListener("closed", this._onClientClosed);
   }
 
   // See JSDoc for id, type from setClient.
   hasClient(id, type) {
     return this._clients.has(this._getKey(id, type));
   }
 
@@ -44,32 +43,47 @@ class RemoteClientManager {
   }
 
   // See JSDoc for id, type from setClient.
   removeClient(id, type) {
     const key = this._getKey(id, type);
     this._removeClientByKey(key);
   }
 
+  removeAllClients() {
+    const keys = [...this._clients.keys()];
+    for (const key of keys) {
+      this._removeClientByKey(key);
+    }
+  }
+
+  /**
+   * Retrieve a unique, url-safe key based on a runtime id and type.
+   */
   getRemoteId(id, type) {
     return encodeURIComponent(this._getKey(id, type));
   }
 
+  /**
+   * Retrieve a managed client for a remote id. The remote id should have been generated
+   * using getRemoteId.
+   */
   getClientByRemoteId(remoteId) {
     const key = decodeURIComponent(remoteId);
     return this._clients.get(key);
   }
 
   _getKey(id, type) {
     return id + "-" + type;
   }
 
   _removeClientByKey(key) {
-    if (this.hasClient(key)) {
-      this.getClient(key).client.removeListener("closed", this._onClientClosed);
+    const client = this._clients.get(key).client;
+    if (client) {
+      client.removeListener("closed", this._onClientClosed);
       this._clients.delete(key);
     }
   }
 
   /**
    * Cleanup all closed clients when a "closed" notification is received from a client.
    */
   _onClientClosed() {