mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Fix issues found in review of host pairing
- Saves of a datastore run one at a time, and changes made while saving are saved by the next save. Overlapping saves from approving and revoking hosts could write an older snapshot after a newer one. - Map subscribers fetch everything again when a new session starts, as the controller only sends values that exist. A host revoked while a browser was disconnected stayed in its list. - The host token check accepts the same pre-rename tokens as the WebSocket, so upgrading a host with such a token does not make it ask to join again.
This commit is contained in:
8 files changed
+121
-30
No files matched your search
@@ -346,6 +346,41 @@ describe("lib/datastore", function() {
|
||||
await datastore.save();
|
||||
assert.equal(datastoreProvider.methodCalls.length, 2);
|
||||
});
|
||||
it("should write overlapping saves in order with the latest data", async function() {
|
||||
const written = [];
|
||||
let release;
|
||||
datastoreProvider.save = async data => {
|
||||
const keys = [...data.keys()];
|
||||
if (!written.length) {
|
||||
await new Promise(resolve => { release = resolve; });
|
||||
}
|
||||
written.push(keys);
|
||||
};
|
||||
datastore = new MockDatastore(datastoreProvider, new Map([["a", 1]]));
|
||||
datastore.callTouch();
|
||||
const first = datastore.save();
|
||||
await new Promise(resolve => setImmediate(resolve)); // First write in progress
|
||||
datastore.getData().set("b", 2);
|
||||
datastore.callTouch();
|
||||
const second = datastore.save();
|
||||
release();
|
||||
await Promise.all([first, second]);
|
||||
assert.deepEqual(written, [["a"], ["a", "b"]]);
|
||||
});
|
||||
it("should save again after a failed save", async function() {
|
||||
let fail = true;
|
||||
datastoreProvider.save = async () => {
|
||||
if (fail) {
|
||||
fail = false;
|
||||
throw new Error("disk full");
|
||||
}
|
||||
datastoreProvider.methodCalls.push(["save"]);
|
||||
};
|
||||
datastore.callTouch();
|
||||
await assert.rejects(datastore.save(), /disk full/);
|
||||
await datastore.save();
|
||||
assert.deepEqual(datastoreProvider.methodCalls.at(-1), ["save"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("load", function() {
|
||||
|
||||
Reference in new issue
Block a user