mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
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:
1 parent
b8b8c44083
commit
c35b6de70e
13 files changed
+278
-31
No files matched your search
@@ -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({});
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
Reference in new issue
Block a user