mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 23:33:12 +09:00
Create FactorioServer and Instance through async factories
FactorioServer.fromOptions finds the Factorio install and generates the RCON password before constructing, so _version and _dataDir are never null and setTargetVersion and init are gone. checkForUpdates is now a module function called before fromOptions. Instance.fromConfig resolves the version, downloads Factorio if needed and builds the server, then constructs the instance with it. It runs before the instance is connected, so the starting and stopped statuses and the version requests go through the host link. FactorioVersionsRequest and LatestReleasesRequest now accept host as a source, and the host tracks starting instances so a second start during a download is rejected. Plugin loading stays a separate loadPlugins step after the instance is connected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a81cfd94b
commit
abb04f3258
12 files changed
+364
-221
No files matched your search
@@ -77,6 +77,29 @@ describe("host/src/Host", function() {
|
||||
await fs.access(modsDirectory);
|
||||
});
|
||||
});
|
||||
describe("._connectInstance()", function() {
|
||||
const originalFromConfig = Instance.fromConfig;
|
||||
afterEach(function() {
|
||||
Instance.fromConfig = originalFromConfig;
|
||||
});
|
||||
it("should reject a second start while the instance is starting", async function() {
|
||||
const hostConfig = new lib.HostConfig("host");
|
||||
const host = new Host(new HostConnector(hostConfig, []), hostConfig, []);
|
||||
const instanceConfig = new lib.InstanceConfig("host", { "instance.id": 7 });
|
||||
host.assignedInstances.set(7, { path: "dir", config: instanceConfig });
|
||||
let fail;
|
||||
Instance.fromConfig = () => new Promise((resolve, reject) => { fail = reject; });
|
||||
|
||||
const first = host._connectInstance(7);
|
||||
await assert.rejects(host._connectInstance(7), /Instance with ID 7 is running/);
|
||||
assert.equal(host._unconnectedStatus(7), "starting");
|
||||
|
||||
fail(new Error("start failed"));
|
||||
await assert.rejects(first, /start failed/);
|
||||
assert.equal(host._unconnectedStatus(7), "stopped");
|
||||
assert.equal(host.instanceConnections.has(7), false);
|
||||
});
|
||||
});
|
||||
describe(".handleSyncUserListsEvent()", function() {
|
||||
const hostAddress = lib.Address.fromShorthand({ hostId: 1 });
|
||||
const instanceAddress = lib.Address.fromShorthand({ instanceId: 1 });
|
||||
|
||||
Reference in new issue
Block a user