Fix statistics_exporter sending commands before start

Fix statistics_exporter potentially sending commands before an instance
is started when metrics are collected.
This commit is contained in:
Hornwitser committed 2021-10-01 01:52:18 +02:00
1 parent c40362fa7f
commit 2b101d594a
3 files changed
+12

No files matched your search

+4
View File
@@ -77,6 +77,10 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
}
async onMetrics() {
if (this.instance.status !== "running") {
return;
}
// Wait configured timeout for the metrics to be collected. It may
// take a long time for the command to go through if the command
// stream is overloaded. Should the timeout be exceeded the
@@ -17,7 +17,14 @@ describe("statistics_exporter plugin", function() {
});
describe(".onMetrics()", function() {
it("should not send commands before running", async function() {
instancePlugin.instance.server.rconCommands.length = 0;
instancePlugin.instance.status = "starting";
await instancePlugin.onMetrics();
assert(instancePlugin.instance.server.rconCommands.length === 0, "commands were run");
});
it("should record statistics", async function() {
instancePlugin.instance.status = "running";
instancePlugin.instance.server.rconCommandResults.set(
"/sc statistics_exporter.export()",
JSON.stringify({
+1
View File
@@ -130,6 +130,7 @@ class MockInstance extends libLink.Link {
this.server = new MockServer();
this.name = "test";
this.id = 7357;
this.status = "running";
this.mockConfigEntries = new Map([
["instance.id", 7357],
["factorio.enable_save_patching", true],