Fix instance auto start

Bypass the Link layer and invoke the handleInstanceStartRequest method
directly on the Instance object during the host's instance auto start
phase.
This commit is contained in:
Hornwitser committed 2024-01-23 16:23:09 +01:00
1 parent 256b455315
commit fc5701f243
5 files changed
+41 -3

No files matched your search

+38 -1
View File
@@ -17,6 +17,7 @@ const {
} = require("./index");
/** @returns {Promise<Map<number, lib.InstanceDetails>>} */
async function getInstances() {
let instances = await getControl().send(new lib.InstanceDetailsListRequest());
return new Map(instances.map(instance => [instance.id, instance]));
@@ -27,6 +28,10 @@ async function checkInstanceStatus(id, status) {
assert.equal(instances.get(44).status, status, "incorrect instance status");
}
async function spawnAltHost(config = "alt-host-config.json") {
return await spawn("alt-host:", `node ../../packages/host run --config ${config}`, /Started host/);
}
async function startAltHost() {
let config = "alt-host-config.json";
let configPath = path.join("temp", "test", config);
@@ -38,7 +43,7 @@ async function startAltHost() {
await exec(`node ../../packages/host --config ${config} config set host.instances_directory alt-instances`);
await exec(`node ../../packages/host --config ${config} config set host.factorio_directory ../../factorio`);
await exec(`node ../../packages/host --config ${config} config set host.mods_directory alt-mods`);
return await spawn("alt-host:", `node ../../packages/host run --config ${config}`, /Started host/);
return await spawnAltHost(config);
}
async function stopAltHost(hostProcess) {
@@ -200,6 +205,38 @@ describe("Integration of Clusterio", function() {
assert(await fs.pathExists(clusterioLib), "mod was not downloaded by the test");
});
});
it("should auto start instances with auto_start enabled", async function() {
slowTest(this);
let hostProcess;
try {
hostProcess = await startAltHost();
await execCtl("instance create alt-start --id 97");
await execCtl("instance assign alt-start 5");
await execCtl("instance config set alt-start instance.auto_start true");
await stopAltHost(hostProcess);
hostProcess = await spawnAltHost();
// Stop the host immediatly to test the handling of stopping
// instances while automatically started and a save is being created
await stopAltHost(hostProcess);
hostProcess = await spawnAltHost();
let status;
// Wait for instance status to become running.
for (let i = 0; i < 100; i++) {
const instances = await getInstances();
status = instances.get(97)?.status ?? "not_present";
if (status === "running") {
break;
}
await wait(100); // Try again 10 times per second.
}
assert.equal(status, "running");
await execCtl("instance stop alt-start");
await execCtl("instance delete alt-start");
} finally {
await stopAltHost(hostProcess);
}
});
});
describe("clusterioctl", function() {