Bug 1521052 - Add DebuggerServer.hasConnection to track if it still has active connections. r=jdescottes
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 23 Jan 2019 14:46:10 +0000
changeset 515104 b4cd1ef4baf051d5f9e933581bb3187059c02289
parent 515103 21cb7caef246d374a8f73a14806d9fd328adbf8a
child 515105 c68ab257f8c8f0023ad3dbb436de6fb49bd54317
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1521052
milestone66.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 1521052 - Add DebuggerServer.hasConnection to track if it still has active connections. r=jdescottes Differential Revision: https://phabricator.services.mozilla.com/D16961
devtools/server/main.js
devtools/shared/transport/tests/unit/test_dbgsocket.js
--- a/devtools/server/main.js
+++ b/devtools/server/main.js
@@ -90,16 +90,20 @@ var DebuggerServer = {
   get protocol() {
     return require("devtools/shared/protocol");
   },
 
   get initialized() {
     return this._initialized;
   },
 
+  hasConnection() {
+    return Object.keys(this._connections).length > 0;
+  },
+
   /**
    * Performs cleanup tasks before shutting down the debugger server. Such tasks
    * include clearing any actor constructors added at runtime. This method
    * should be called whenever a debugger server is no longer useful, to avoid
    * memory leaks. After this method returns, the debugger server must be
    * initialized again before use.
    */
   destroy() {
--- a/devtools/shared/transport/tests/unit/test_dbgsocket.js
+++ b/devtools/shared/transport/tests/unit/test_dbgsocket.js
@@ -32,30 +32,33 @@ async function test_socket_conn() {
   listener.open();
   Assert.equal(DebuggerServer.listeningSockets, 1);
   gPort = DebuggerServer._listeners[0].port;
   info("Debugger server port is " + gPort);
   // Open a second, separate listener
   gExtraListener = new SocketListener(DebuggerServer, socketOptions);
   gExtraListener.open();
   Assert.equal(DebuggerServer.listeningSockets, 2);
+  Assert.ok(!DebuggerServer.hasConnection());
 
   info("Starting long and unicode tests at " + new Date().toTimeString());
   const unicodeString = "(╯°□°)╯︵ ┻━┻";
   const transport = await DebuggerClient.socketConnect({
     host: "127.0.0.1",
     port: gPort,
   });
+  Assert.ok(DebuggerServer.hasConnection());
 
   // Assert that connection settings are available on transport object
   const settings = transport.connectionSettings;
   Assert.equal(settings.host, "127.0.0.1");
   Assert.equal(settings.port, gPort);
 
-  return new Promise((resolve) => {
+  const onDebuggerConnectionClosed = DebuggerServer.once("connectionchange");
+  await new Promise((resolve) => {
     transport.hooks = {
       onPacket: function(packet) {
         this.onPacket = function({unicode}) {
           Assert.equal(unicode, unicodeString);
           transport.close();
         };
         // Verify that things work correctly when bigger than the output
         // transport buffers and when transporting unicode...
@@ -66,16 +69,19 @@ async function test_socket_conn() {
         Assert.equal(packet.from, "root");
       },
       onClosed: function(status) {
         resolve();
       },
     };
     transport.ready();
   });
+  const type = await onDebuggerConnectionClosed;
+  Assert.equal(type, "closed");
+  Assert.ok(!DebuggerServer.hasConnection());
 }
 
 async function test_socket_shutdown() {
   Assert.equal(DebuggerServer.listeningSockets, 2);
   gExtraListener.close();
   Assert.equal(DebuggerServer.listeningSockets, 1);
   Assert.ok(DebuggerServer.closeAllSocketListeners());
   Assert.equal(DebuggerServer.listeningSockets, 0);