mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33: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
@@ -1584,6 +1584,34 @@ describe("lib/subscriptions", function() {
|
||||
assert.equal(snap2.has(2), true);
|
||||
});
|
||||
|
||||
it("should fetch everything again when a new session starts", async function() {
|
||||
subscriber.subscribe(() => {});
|
||||
await events.once(mockControl.connector, "send");
|
||||
await subscriber._handleEvent(new MapEvent([
|
||||
{ id: 1, updatedAtMs: 10, isDeleted: false },
|
||||
]));
|
||||
const [before] = subscriber.getSnapshot();
|
||||
mockControl.connector.sentMessages.length = 0;
|
||||
|
||||
mockControl.connector.emit("connect");
|
||||
assert.equal(subscriber.values.size, 0);
|
||||
assert.notStrictEqual(subscriber.getSnapshot()[0], before);
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
const requests = mockControl.connector.sentMessages.filter(m => m.name === "SubscriptionRequest");
|
||||
assert.equal(requests.length, 1);
|
||||
assert.equal(requests[0].data.lastRequestTimeMs, -1);
|
||||
});
|
||||
|
||||
it("should keep values when a session is resumed", async function() {
|
||||
await subscriber._handleEvent(new MapEvent([
|
||||
{ id: 1, updatedAtMs: 10, isDeleted: false },
|
||||
]));
|
||||
subscriber.handleConnectionEvent("drop");
|
||||
subscriber.handleConnectionEvent("resume");
|
||||
assert.equal(subscriber.values.size, 1);
|
||||
assert.equal(subscriber.lastUpdatedMs, 10);
|
||||
});
|
||||
|
||||
it("should handle multiple updates correctly", async function() {
|
||||
await subscriber._handleEvent(new MapEvent([
|
||||
{ id: 1, updatedAtMs: 10, isDeleted: false },
|
||||
|
||||
Reference in new issue
Block a user