mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 23:24:52 +09:00
Cache save details on the controller
Keep a copy of the instance saves details on the controller so that saves can be queried even when the host is disconnected and the controller can properly track and provide updates on the saves to its clients.
This commit is contained in:
1 parent
d186f85773
commit
a2914bda33
13 files changed
+219
-66
No files matched your search
@@ -315,16 +315,16 @@ describe("Integration of Clusterio", function() {
|
||||
describe("instance save create", function() {
|
||||
it("creates a save", async function() {
|
||||
slowTest(this);
|
||||
getControl().saveListUpdates = [];
|
||||
getControl().saveUpdates = [];
|
||||
await execCtl("instance save create test");
|
||||
await checkInstanceStatus(44, "stopped");
|
||||
});
|
||||
});
|
||||
|
||||
describe("saveListUpdateEventHandler()", function() {
|
||||
describe("InstanceSaveDetailsUpdatesEvent", function() {
|
||||
it("should have triggered for the created save", function() {
|
||||
slowTest(this);
|
||||
assert.equal(getControl().saveListUpdates.slice(-1)[0].saves[0].name, "world.zip");
|
||||
assert.equal(getControl().saveUpdates.slice(-1)[0].updates[0].name, "world.zip");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -391,7 +391,7 @@ describe("Integration of Clusterio", function() {
|
||||
let savesDir = path.join("temp", "test", "instances", "test", "saves");
|
||||
await fs.copy(path.join(savesDir, "world.zip"), path.join(savesDir, "_autosave1.zip"));
|
||||
await execCtl("instance start test");
|
||||
let saves = await getControl().sendTo({ instanceId: 44 }, new lib.InstanceListSavesRequest());
|
||||
let saves = await getControl().sendTo({ instanceId: 44 }, new lib.InstanceSaveDetailsListRequest());
|
||||
let running = saves.find(s => s.loaded);
|
||||
assert(running.name !== "_autosave1.zip");
|
||||
});
|
||||
@@ -407,19 +407,19 @@ describe("Integration of Clusterio", function() {
|
||||
assert(log.some(info => /technobabble/.test(info.message)), "Command was not sent");
|
||||
});
|
||||
|
||||
it("should trigger saveListUpdate on save", async function() {
|
||||
it("should trigger InstanceSaveDetailsUpdatesEvent on save", async function() {
|
||||
slowTest(this);
|
||||
getControl().saveListUpdates = [];
|
||||
getControl().saveUpdates = [];
|
||||
await execCtl("instance send-rcon test /server-save");
|
||||
let received = false;
|
||||
for (let x = 0; x < 10; x++) {
|
||||
if (getControl().saveListUpdates.length) {
|
||||
if (getControl().saveUpdates.length) {
|
||||
received = true;
|
||||
break;
|
||||
}
|
||||
await wait(100);
|
||||
}
|
||||
assert(received, "saveListUpdate not sent");
|
||||
assert(received, "InstanceSaveDetailsUpdatesEvent not sent");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -827,10 +827,16 @@ describe("Integration of Clusterio", function() {
|
||||
describe("instance delete", function() {
|
||||
it("deletes the instance", async function() {
|
||||
slowTest(this);
|
||||
getControl().saveUpdates = [];
|
||||
await execCtl("instance delete test");
|
||||
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 controller");
|
||||
|
||||
const saveUpdates = getControl().saveUpdates;
|
||||
assert.equal(saveUpdates.length, 1, "Expected one update sent on saves");
|
||||
assert(saveUpdates[0].updates.length > 0, "Expected saves update to contain at least one save updated");
|
||||
assert(saveUpdates[0].updates.every(update => update.isDeleted), "Expected all saves to be deleted");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class TestControl extends lib.Link {
|
||||
super(connector);
|
||||
this.hostUpdates = [];
|
||||
this.instanceUpdates = [];
|
||||
this.saveListUpdates = [];
|
||||
this.saveUpdates = [];
|
||||
this.modUpdates = [];
|
||||
this.modPackUpdates = [];
|
||||
this.userUpdates = [];
|
||||
@@ -42,8 +42,8 @@ class TestControl extends lib.Link {
|
||||
new lib.SubscriptionRequest(lib.InstanceDetailsUpdatesEvent.name, true)
|
||||
).catch(err => logger.error(`Error setting instance subscriptions:\n${err.stack}`));
|
||||
this.send(
|
||||
new lib.SubscriptionRequest(lib.InstanceSaveListUpdateEvent.name, true)
|
||||
).catch(err => logger.error(`Error setting save list subscriptions:\n${err.stack}`));
|
||||
new lib.SubscriptionRequest(lib.InstanceSaveDetailsUpdatesEvent.name, true)
|
||||
).catch(err => logger.error(`Error setting save subscriptions:\n${err.stack}`));
|
||||
this.send(
|
||||
new lib.SubscriptionRequest(lib.ModUpdatesEvent.name, true)
|
||||
).catch(err => logger.error(`Error setting mod subscriptions:\n${err.stack}`));
|
||||
@@ -58,7 +58,7 @@ class TestControl extends lib.Link {
|
||||
this.handle(lib.AccountUpdateEvent);
|
||||
this.handle(lib.HostUpdatesEvent, this.handleHostUpdatesEvent.bind(this));
|
||||
this.handle(lib.InstanceDetailsUpdatesEvent, this.handleInstanceDetailsUpdatesEvent.bind(this));
|
||||
this.handle(lib.InstanceSaveListUpdateEvent, this.handleInstanceSaveListUpdateEvent.bind(this));
|
||||
this.handle(lib.InstanceSaveDetailsUpdatesEvent, this.handleInstanceSaveDetailsUpdatesEvent.bind(this));
|
||||
this.handle(lib.ModUpdatesEvent, this.handleModUpdatesEvent.bind(this));
|
||||
this.handle(lib.ModPackUpdatesEvent, this.handleModPackUpdatesEvent.bind(this));
|
||||
this.handle(lib.UserUpdatesEvent, this.handleUserUpdatesEvent.bind(this));
|
||||
@@ -72,8 +72,8 @@ class TestControl extends lib.Link {
|
||||
this.instanceUpdates.push(...event.updates);
|
||||
}
|
||||
|
||||
async handleInstanceSaveListUpdateEvent(event) {
|
||||
this.saveListUpdates.push(event);
|
||||
async handleInstanceSaveDetailsUpdatesEvent(event) {
|
||||
this.saveUpdates.push(event);
|
||||
}
|
||||
|
||||
async handleModUpdatesEvent(event) {
|
||||
|
||||
Reference in new issue
Block a user