Bug 1521052 - Add DebuggerServer.hasConnection to track if it still has active connections. r=jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D16961

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2019-01-23 14:46:10 +00:00
parent de44cc12fc
commit 34cccbbf19
2 changed files with 11 additions and 1 deletions

View File

@ -95,6 +95,10 @@ var DebuggerServer = {
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

View File

@ -37,6 +37,7 @@ async function test_socket_conn() {
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 = "(╯°□°)╯︵ ┻━┻";
@ -44,13 +45,15 @@ async function test_socket_conn() {
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}) {
@ -71,6 +74,9 @@ async function test_socket_conn() {
};
transport.ready();
});
const type = await onDebuggerConnectionClosed;
Assert.equal(type, "closed");
Assert.ok(!DebuggerServer.hasConnection());
}
async function test_socket_shutdown() {