From 003b035abdfc71514967fd1dd3d876ccb22696a3 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 29 Sep 2020 01:18:17 +0200 Subject: [PATCH] Send instance status in listInstances request Send the status of the instance in the repsonse to the listInstances request and use this status in the integration tests to check if the instance was started/stopped. --- packages/lib/link/messages.js | 5 ++++- packages/master/master.js | 1 + test/integration/clusterio.js | 28 +++++++++++++++++++++++----- test/lib/command.js | 2 +- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/packages/lib/link/messages.js b/packages/lib/link/messages.js index 7174b3e6..b7951c90 100644 --- a/packages/lib/link/messages.js +++ b/packages/lib/link/messages.js @@ -290,11 +290,14 @@ messages.listInstances = new Request({ type: "array", items: { additionalProperties: false, - required: ["name", "id", "assigned_slave"], + required: ["name", "id", "assigned_slave", "status"], properties: { "name": { type: "string" }, "id": { type: "integer" }, "assigned_slave": { type: ["null", "integer"] }, + "status": { enum: [ + "unknown", "unassigned", "stopped", "starting", "running", "creating_save", "exporting_data", + ]}, }, }, }, diff --git a/packages/master/master.js b/packages/master/master.js index b1aa838f..e3832fba 100755 --- a/packages/master/master.js +++ b/packages/master/master.js @@ -612,6 +612,7 @@ class ControlConnection extends BaseConnection { id: instance.config.get("instance.id"), name: instance.config.get("instance.name"), assigned_slave: instance.config.get("instance.assigned_slave"), + status: instance.status, }); } return { list }; diff --git a/test/integration/clusterio.js b/test/integration/clusterio.js index 584164c0..3ec94b1e 100644 --- a/test/integration/clusterio.js +++ b/test/integration/clusterio.js @@ -8,6 +8,16 @@ const link = require("@clusterio/lib/link"); const { slowTest, get, execCtl, sendRcon, getControl, instancesDir } = require("./index"); +async function getInstances() { + let result = await link.messages.listInstances.send(getControl()); + return new Map(result.list.map(instance => [instance.id, instance])); +} + +async function checkInstanceStatus(id, status) { + let instances = await getInstances(); + assert.equal(instances.get(44).status, status, "incorrect instance status"); +} + describe("Integration of Clusterio", function() { describe("clusterioctl", function() { describe("slave list", function() { @@ -22,15 +32,19 @@ describe("Integration of Clusterio", function() { }); describe("instance create", function() { - it("runs", async function() { + it("creates the instance", async function() { await execCtl("instance create test --id 44"); + let instances = await getInstances(); + assert(instances.has(44), "instance was not created"); + assert.equal(instances.get(44).status, "unassigned", "incorrect instance status"); }); }); describe("instance assign", function() { it("creates the instance files", async function() { await execCtl("instance assign test 4"); - assert(await fs.exists(path.join(instancesDir, "test")), "Instance was not created"); + assert(await fs.exists(path.join(instancesDir, "test")), "Instance directory was not created"); + await checkInstanceStatus(44, "stopped"); }); }); @@ -38,6 +52,7 @@ describe("Integration of Clusterio", function() { it("creates a save", async function() { slowTest(this); await execCtl("instance create-save test"); + await checkInstanceStatus(44, "stopped"); }); }); @@ -46,6 +61,7 @@ describe("Integration of Clusterio", function() { slowTest(this); await execCtl("instance export-data test"); assert(await fs.exists(path.join("static", "export", "locale.json")), "Export was not created"); + await checkInstanceStatus(44, "stopped"); }); }); @@ -53,7 +69,7 @@ describe("Integration of Clusterio", function() { it("starts the instance", async function() { slowTest(this); await execCtl("instance start test"); - // TODO check that the instance actually started + await checkInstanceStatus(44, "running"); }); }); @@ -200,7 +216,7 @@ describe("Integration of Clusterio", function() { it("stops the instance", async function() { slowTest(this); await execCtl("instance stop test"); - // TODO check that the instance actually stopped + await checkInstanceStatus(44, "stopped"); }); }); @@ -208,7 +224,9 @@ describe("Integration of Clusterio", function() { it("deletes the instance", async function() { slowTest(this); await execCtl("instance delete test"); - assert(!await fs.exists(path.join(instancesDir, "test")), "Instance was not deleted"); + assert(!await fs.exists(path.join(instancesDir, "test")), "Instance files was not deleted"); + let instances = await getInstances(); + assert(!instances.has(44), "instance was not deleted from master"); }); }); diff --git a/test/lib/command.js b/test/lib/command.js index f09db22e..ceaa3a61 100644 --- a/test/lib/command.js +++ b/test/lib/command.js @@ -24,7 +24,7 @@ describe("lib/command", function() { seq: 1, type: "list_instances_response", data: { seq: message.seq, - list: [{ id: 57, assigned_slave: 4, name: "Test Instance" }], + list: [{ id: 57, assigned_slave: 4, name: "Test Instance", status: "stopped" }], }, }); } else if (message.type === "list_roles_request") {