mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-26 00:33:12 +09:00
Merge branch 'master' into fix/instance-assign-failure
This commit is contained in:
2 files changed
+57
-3
No files matched your search
@@ -53,7 +53,7 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
});
|
});
|
||||||
this.connector.on("close", () => {
|
this.connector.on("close", () => {
|
||||||
if (this.logTransport) {
|
if (this.logTransport) {
|
||||||
logger.remove(this.logTransport);
|
this._controller.clusterLogger.remove(this.logTransport);
|
||||||
this.logTransport = null;
|
this.logTransport = null;
|
||||||
}
|
}
|
||||||
if (this.ws_dumper) {
|
if (this.ws_dumper) {
|
||||||
@@ -1328,6 +1328,9 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleDebugDumpWsRequest(request: lib.DebugDumpWsRequest) {
|
async handleDebugDumpWsRequest(request: lib.DebugDumpWsRequest) {
|
||||||
|
if (this.ws_dumper) {
|
||||||
|
return; // Already dumping
|
||||||
|
}
|
||||||
this.ws_dumper = data => {
|
this.ws_dumper = data => {
|
||||||
if (this.connector.connected) {
|
if (this.connector.connected) {
|
||||||
this.send(new lib.DebugWsMessageEvent(data.direction, data.content));
|
this.send(new lib.DebugWsMessageEvent(data.direction, data.content));
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
|
import events from "node:events";
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import { ControlConnection, InstanceManager } from "@clusterio/controller";
|
import { ControlConnection, ControllerHooks, InstanceManager } from "@clusterio/controller";
|
||||||
import { MockController } from "../mock.js";
|
import { MockConnector, MockLogger } from "../mock.js";
|
||||||
|
|
||||||
|
const addr = lib.Address.fromShorthand;
|
||||||
|
|
||||||
describe("controller/src/ControlConnection", function() {
|
describe("controller/src/ControlConnection", function() {
|
||||||
describe(".handleControllerRestartRequest()", function() {
|
describe(".handleControllerRestartRequest()", function() {
|
||||||
@@ -73,6 +76,54 @@ describe("controller/src/ControlConnection", function() {
|
|||||||
const clone = mockController.instances.get(4002);
|
const clone = mockController.instances.get(4002);
|
||||||
assert.equal(clone.config.get("instance.name"), "clone");
|
assert.equal(clone.config.get("instance.name"), "clone");
|
||||||
assert.equal(clone.config.get("instance.assigned_host"), null);
|
assert.equal(clone.config.get("instance.assigned_host"), null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("close cleanup", function() {
|
||||||
|
let connector;
|
||||||
|
let mockController;
|
||||||
|
let connection;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
connector = new MockConnector(addr("controller"), addr({ controlId: 1 }));
|
||||||
|
connector._socket = {};
|
||||||
|
const transports = new Set();
|
||||||
|
mockController = {
|
||||||
|
hooks: new ControllerHooks(new MockLogger()),
|
||||||
|
router: null,
|
||||||
|
_registeredRequests: new Map(),
|
||||||
|
_fallbackedRequests: new Map(),
|
||||||
|
_registeredEvents: new Map(),
|
||||||
|
_snoopedEvents: new Map(),
|
||||||
|
subscriptions: { unsubscribeLink() {} },
|
||||||
|
clusterLogger: {
|
||||||
|
transports,
|
||||||
|
add(transport) { transports.add(transport); },
|
||||||
|
remove(transport) { transports.delete(transport); },
|
||||||
|
},
|
||||||
|
debugEvents: new events.EventEmitter(),
|
||||||
|
sendRequestToHostByInstanceId() {},
|
||||||
|
};
|
||||||
|
connection = new ControlConnection({ version: "test" }, connector, mockController, {}, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes the log transport from clusterLogger", async function() {
|
||||||
|
await connection.handleLogSetSubscriptionsRequest(
|
||||||
|
new lib.LogSetSubscriptionsRequest(true, false, [], [])
|
||||||
|
);
|
||||||
|
assert.equal(mockController.clusterLogger.transports.size, 1);
|
||||||
|
connector.emit("close");
|
||||||
|
assert.equal(mockController.clusterLogger.transports.size, 0);
|
||||||
|
assert.equal(connection.logTransport, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes the debug dump listener after repeated requests", async function() {
|
||||||
|
await connection.handleDebugDumpWsRequest(new lib.DebugDumpWsRequest());
|
||||||
|
await connection.handleDebugDumpWsRequest(new lib.DebugDumpWsRequest());
|
||||||
|
assert.equal(mockController.debugEvents.listenerCount("message"), 1);
|
||||||
|
assert.equal(connector._socket.clusterio_ignore_dump, true);
|
||||||
|
connector.emit("close");
|
||||||
|
assert.equal(mockController.debugEvents.listenerCount("message"), 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user