Notify on connection events

Implement notification to plugins for disconnect request, connect, drop,
and close.  This allows plugins to properly handle slaves and the master
server shutting down without sending messages that will get lost.
This commit is contained in:
Hornwitser committed 2020-05-08 23:49:28 +02:00
1 parent b8b8c44083
commit c35b6de70e
13 files changed
+278 -31

No files matched your search

+4
View File
@@ -21,6 +21,8 @@ describe("lib/plugin", function() {
await instancePlugin.onStop();
instancePlugin.onExit();
await instancePlugin.onOutput({});
instancePlugin.onMasterConnectionEvent("connect");
instancePlugin.onPrepareMasterDisconnect();
})
});
@@ -33,6 +35,8 @@ describe("lib/plugin", function() {
it("should define defaults for hooks", async function() {
await masterPlugin.onMetrics();
await masterPlugin.onShutdown();
masterPlugin.onSlaveConnectionEvent({}, "connect");
masterPlugin.onPrepareSlaveDisconnect({});
})
});
+10
View File
@@ -34,6 +34,9 @@ class MockConnector extends events.EventEmitter {
this.sentMessages = [];
this.events = new Map();
this.handshake = { address: "socket.test" };
this.connected = true;
this.closing = false;
}
send(type, data) {
@@ -70,9 +73,16 @@ class MockInstance extends link.Link {
}
}
class MockSlave extends link.Link {
constructor() {
super('slave', 'master', new MockConnector());
}
}
module.exports = {
MockSocket,
MockConnector,
MockInstance,
MockSlave,
};