mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Add automatic export of metrics from slaves to the master server. And rewrite the statistics export plugin to use this new system.
86 lines
1.4 KiB
JavaScript
86 lines
1.4 KiB
JavaScript
const events = require("events");
|
|
|
|
const link = require("lib/link");
|
|
|
|
|
|
class MockSocket {
|
|
constructor() {
|
|
this.sentMessages = [];
|
|
this.events = new Map();
|
|
this.handshake = { address: "socket.test" };
|
|
}
|
|
|
|
send(message) {
|
|
this.sentMessages.push(message);
|
|
}
|
|
|
|
on(event, fn) {
|
|
this.events.set(event, fn);
|
|
}
|
|
|
|
disconnect() {
|
|
this.disconnectCalled = true;
|
|
}
|
|
|
|
close() {
|
|
this.closeCalled = true;
|
|
}
|
|
}
|
|
|
|
class MockConnector extends events.EventEmitter {
|
|
constructor() {
|
|
super();
|
|
|
|
this._seq = 1;
|
|
this.sentMessages = [];
|
|
this.events = new Map();
|
|
this.handshake = { address: "socket.test" };
|
|
}
|
|
|
|
send(type, data) {
|
|
let message = { seq: this._seq, type, data };
|
|
this.sentMessages.push(message);
|
|
setImmediate(() => this.emit('send', message));
|
|
return this._seq++;
|
|
}
|
|
|
|
close(reason) {
|
|
this.send('close', { reason });
|
|
this.disconnect();
|
|
}
|
|
|
|
disconnect() {
|
|
this.disconnectCalled = true;
|
|
}
|
|
}
|
|
|
|
class MockServer {
|
|
constructor() {
|
|
this.rconCommands = [];
|
|
this.rconCommandResults = new Map();
|
|
}
|
|
|
|
async sendRcon(command) {
|
|
this.rconCommands.push(command);
|
|
return this.rconCommandResults.get(command) || '';
|
|
}
|
|
}
|
|
|
|
class MockInstance extends link.Link {
|
|
constructor() {
|
|
super('instance', 'slave', new MockConnector());
|
|
this.server = new MockServer();
|
|
this.name = "test";
|
|
this.config = {
|
|
id: 7357,
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
MockSocket,
|
|
MockConnector,
|
|
MockInstance,
|
|
};
|