Add SIGKILL detection to lib/factorio/server

Check if Factorio terminated as a result of SIGKILL and throw an error
suggesting the system may be low on memory as a cause.  Also print exit
code if the unexpected shutdown occured without a signal.
This commit is contained in:
Hornwitser committed 2019-11-23 15:18:20 +01:00
1 parent 7a2abaa5db
commit 554cab4fb0
3 files changed
+51 -1

No files matched your search

+30
View File
@@ -4,6 +4,7 @@ const fs = require("fs-extra");
const path = require("path");
const factorio = require("lib/factorio");
const errors = require("lib/errors");
describe("Integration of lib/factorio/server", function() {
@@ -182,5 +183,34 @@ describe("Integration of lib/factorio/server", function() {
await server.stop();
});
});
describe(".start() termination detection", function() {
it("should tell if Factorio got killed", async function() {
// This does not work on Windows
if (process.platform == "win32") {
this.skip();
}
slowTest(this);
log(".start() for kill detection");
let startPromise = server.start("test.zip");
server.once('output', () => server._server.kill('SIGKILL'));
await assert.rejects(
startPromise,
new errors.EnvironmentError("Factorio server was unexpectedly killed, is the system low on memory?")
);
});
it("should tell if Factorio unexpectedly closed with a code", async function() {
slowTest(this);
log(".start() for unexpected close detection");
await assert.rejects(
server.start("does-not-exist.zip"),
new errors.EnvironmentError("Factorio server unexpectedly shut down with code 1")
);
});
});
});
});