@fluidframework/container-loader 2.0.0-rc.2.0.2 → 2.0.0-rc.3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/api-report/container-loader.api.md +13 -13
- package/dist/attachment.d.ts +6 -9
- package/dist/attachment.d.ts.map +1 -1
- package/dist/attachment.js +5 -5
- package/dist/attachment.js.map +1 -1
- package/dist/audience.d.ts +1 -1
- package/dist/audience.d.ts.map +1 -1
- package/dist/audience.js +4 -4
- package/dist/audience.js.map +1 -1
- package/dist/catchUpMonitor.d.ts +1 -1
- package/dist/catchUpMonitor.d.ts.map +1 -1
- package/dist/catchUpMonitor.js +2 -2
- package/dist/catchUpMonitor.js.map +1 -1
- package/dist/connectionManager.d.ts +4 -4
- package/dist/connectionManager.d.ts.map +1 -1
- package/dist/connectionManager.js +48 -43
- package/dist/connectionManager.js.map +1 -1
- package/dist/connectionStateHandler.d.ts +3 -3
- package/dist/connectionStateHandler.d.ts.map +1 -1
- package/dist/connectionStateHandler.js +27 -27
- package/dist/connectionStateHandler.js.map +1 -1
- package/dist/container.d.ts +9 -46
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +105 -116
- package/dist/container.js.map +1 -1
- package/dist/containerContext.d.ts +19 -7
- package/dist/containerContext.d.ts.map +1 -1
- package/dist/containerContext.js +7 -2
- package/dist/containerContext.js.map +1 -1
- package/dist/containerStorageAdapter.d.ts +3 -3
- package/dist/containerStorageAdapter.d.ts.map +1 -1
- package/dist/containerStorageAdapter.js +6 -6
- package/dist/containerStorageAdapter.js.map +1 -1
- package/dist/contracts.d.ts +4 -3
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +2 -2
- package/dist/contracts.js.map +1 -1
- package/dist/debugLogger.d.ts +2 -1
- package/dist/debugLogger.d.ts.map +1 -1
- package/dist/debugLogger.js +4 -4
- package/dist/debugLogger.js.map +1 -1
- package/dist/deltaManager.d.ts +11 -7
- package/dist/deltaManager.d.ts.map +1 -1
- package/dist/deltaManager.js +53 -50
- package/dist/deltaManager.js.map +1 -1
- package/dist/deltaQueue.d.ts +1 -1
- package/dist/deltaQueue.d.ts.map +1 -1
- package/dist/deltaQueue.js +5 -5
- package/dist/deltaQueue.js.map +1 -1
- package/dist/error.d.ts +3 -2
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +5 -5
- package/dist/error.js.map +1 -1
- package/dist/legacy.d.ts +29 -0
- package/dist/loader.d.ts +4 -4
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +23 -23
- package/dist/loader.js.map +1 -1
- package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts +2 -2
- package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -1
- package/dist/location-redirection-utilities/resolveWithLocationRedirection.js +2 -2
- package/dist/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
- package/dist/noopHeuristic.d.ts +1 -1
- package/dist/noopHeuristic.d.ts.map +1 -1
- package/dist/noopHeuristic.js +6 -6
- package/dist/noopHeuristic.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/protocol.d.ts +1 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +2 -2
- package/dist/protocol.js.map +1 -1
- package/dist/protocolTreeDocumentStorageService.d.ts +4 -4
- package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/dist/protocolTreeDocumentStorageService.js.map +1 -1
- package/dist/public.d.ts +14 -0
- package/dist/quorum.d.ts +1 -1
- package/dist/quorum.d.ts.map +1 -1
- package/dist/quorum.js +4 -0
- package/dist/quorum.js.map +1 -1
- package/dist/retriableDocumentStorageService.d.ts +2 -2
- package/dist/retriableDocumentStorageService.d.ts.map +1 -1
- package/dist/retriableDocumentStorageService.js +7 -7
- package/dist/retriableDocumentStorageService.js.map +1 -1
- package/dist/serializedStateManager.d.ts +86 -16
- package/dist/serializedStateManager.d.ts.map +1 -1
- package/dist/serializedStateManager.js +182 -82
- package/dist/serializedStateManager.js.map +1 -1
- package/dist/utils.d.ts +24 -9
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +82 -25
- package/dist/utils.js.map +1 -1
- package/internal.d.ts +11 -0
- package/legacy.d.ts +11 -0
- package/lib/attachment.d.ts +6 -9
- package/lib/attachment.d.ts.map +1 -1
- package/lib/attachment.js +1 -1
- package/lib/attachment.js.map +1 -1
- package/lib/audience.d.ts +1 -1
- package/lib/audience.d.ts.map +1 -1
- package/lib/audience.js +1 -1
- package/lib/audience.js.map +1 -1
- package/lib/catchUpMonitor.d.ts +1 -1
- package/lib/catchUpMonitor.d.ts.map +1 -1
- package/lib/catchUpMonitor.js +1 -1
- package/lib/catchUpMonitor.js.map +1 -1
- package/lib/connectionManager.d.ts +4 -4
- package/lib/connectionManager.d.ts.map +1 -1
- package/lib/connectionManager.js +11 -6
- package/lib/connectionManager.js.map +1 -1
- package/lib/connectionStateHandler.d.ts +3 -3
- package/lib/connectionStateHandler.d.ts.map +1 -1
- package/lib/connectionStateHandler.js +2 -2
- package/lib/connectionStateHandler.js.map +1 -1
- package/lib/container.d.ts +9 -46
- package/lib/container.d.ts.map +1 -1
- package/lib/container.js +37 -48
- package/lib/container.js.map +1 -1
- package/lib/containerContext.d.ts +19 -7
- package/lib/containerContext.d.ts.map +1 -1
- package/lib/containerContext.js +7 -2
- package/lib/containerContext.js.map +1 -1
- package/lib/containerStorageAdapter.d.ts +3 -3
- package/lib/containerStorageAdapter.d.ts.map +1 -1
- package/lib/containerStorageAdapter.js +2 -2
- package/lib/containerStorageAdapter.js.map +1 -1
- package/lib/contracts.d.ts +4 -3
- package/lib/contracts.d.ts.map +1 -1
- package/lib/contracts.js +1 -1
- package/lib/contracts.js.map +1 -1
- package/lib/debugLogger.d.ts +2 -1
- package/lib/debugLogger.d.ts.map +1 -1
- package/lib/debugLogger.js +1 -1
- package/lib/debugLogger.js.map +1 -1
- package/lib/deltaManager.d.ts +11 -7
- package/lib/deltaManager.d.ts.map +1 -1
- package/lib/deltaManager.js +13 -10
- package/lib/deltaManager.js.map +1 -1
- package/lib/deltaQueue.d.ts +1 -1
- package/lib/deltaQueue.d.ts.map +1 -1
- package/lib/deltaQueue.js +2 -2
- package/lib/deltaQueue.js.map +1 -1
- package/lib/error.d.ts +3 -2
- package/lib/error.d.ts.map +1 -1
- package/lib/error.js +2 -2
- package/lib/error.js.map +1 -1
- package/lib/legacy.d.ts +29 -0
- package/lib/loader.d.ts +4 -4
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js +4 -4
- package/lib/loader.js.map +1 -1
- package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.ts +2 -2
- package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -1
- package/lib/location-redirection-utilities/resolveWithLocationRedirection.js +2 -2
- package/lib/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
- package/lib/noopHeuristic.d.ts +1 -1
- package/lib/noopHeuristic.d.ts.map +1 -1
- package/lib/noopHeuristic.js +2 -2
- package/lib/noopHeuristic.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/protocol.d.ts +1 -1
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +1 -1
- package/lib/protocol.js.map +1 -1
- package/lib/protocolTreeDocumentStorageService.d.ts +4 -4
- package/lib/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/lib/protocolTreeDocumentStorageService.js.map +1 -1
- package/lib/public.d.ts +14 -0
- package/lib/quorum.d.ts +1 -1
- package/lib/quorum.d.ts.map +1 -1
- package/lib/quorum.js +4 -0
- package/lib/quorum.js.map +1 -1
- package/lib/retriableDocumentStorageService.d.ts +2 -2
- package/lib/retriableDocumentStorageService.d.ts.map +1 -1
- package/lib/retriableDocumentStorageService.js +3 -3
- package/lib/retriableDocumentStorageService.js.map +1 -1
- package/lib/serializedStateManager.d.ts +86 -16
- package/lib/serializedStateManager.d.ts.map +1 -1
- package/lib/serializedStateManager.js +174 -77
- package/lib/serializedStateManager.js.map +1 -1
- package/lib/utils.d.ts +24 -9
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +69 -15
- package/lib/utils.js.map +1 -1
- package/package.json +37 -58
- package/src/attachment.ts +10 -8
- package/src/audience.ts +3 -2
- package/src/catchUpMonitor.ts +2 -2
- package/src/connectionManager.ts +27 -20
- package/src/connectionStateHandler.ts +7 -7
- package/src/container.ts +90 -143
- package/src/containerContext.ts +22 -12
- package/src/containerStorageAdapter.ts +7 -6
- package/src/contracts.ts +4 -5
- package/src/debugLogger.ts +3 -4
- package/src/deltaManager.ts +40 -30
- package/src/deltaQueue.ts +2 -2
- package/src/error.ts +5 -4
- package/src/loader.ts +25 -23
- package/src/location-redirection-utilities/resolveWithLocationRedirection.ts +4 -4
- package/src/noopHeuristic.ts +3 -3
- package/src/packageVersion.ts +1 -1
- package/src/protocol.ts +2 -2
- package/src/protocolTreeDocumentStorageService.ts +4 -1
- package/src/quorum.ts +2 -1
- package/src/retriableDocumentStorageService.ts +6 -5
- package/src/serializedStateManager.ts +299 -111
- package/src/utils.ts +103 -24
- package/api-extractor-cjs.json +0 -8
- package/dist/container-loader-alpha.d.ts +0 -275
- package/dist/container-loader-beta.d.ts +0 -101
- package/dist/container-loader-public.d.ts +0 -101
- package/dist/container-loader-untrimmed.d.ts +0 -331
- package/lib/container-loader-alpha.d.ts +0 -275
- package/lib/container-loader-beta.d.ts +0 -101
- package/lib/container-loader-public.d.ts +0 -101
- package/lib/container-loader-untrimmed.d.ts +0 -331
- package/lib/test/attachment.spec.js +0 -380
- package/lib/test/attachment.spec.js.map +0 -1
- package/lib/test/catchUpMonitor.spec.js +0 -88
- package/lib/test/catchUpMonitor.spec.js.map +0 -1
- package/lib/test/connectionManager.spec.js +0 -201
- package/lib/test/connectionManager.spec.js.map +0 -1
- package/lib/test/connectionStateHandler.spec.js +0 -555
- package/lib/test/connectionStateHandler.spec.js.map +0 -1
- package/lib/test/container.spec.js +0 -64
- package/lib/test/container.spec.js.map +0 -1
- package/lib/test/deltaManager.spec.js +0 -405
- package/lib/test/deltaManager.spec.js.map +0 -1
- package/lib/test/loader.spec.js +0 -212
- package/lib/test/loader.spec.js.map +0 -1
- package/lib/test/locationRedirectionTests.spec.js +0 -44
- package/lib/test/locationRedirectionTests.spec.js.map +0 -1
- package/lib/test/serializedStateManager.spec.js +0 -148
- package/lib/test/serializedStateManager.spec.js.map +0 -1
- package/lib/test/snapshotConversionTest.spec.js +0 -79
- package/lib/test/snapshotConversionTest.spec.js.map +0 -1
- package/lib/test/types/validateContainerLoaderPrevious.generated.js +0 -38
- package/lib/test/types/validateContainerLoaderPrevious.generated.js.map +0 -1
- package/lib/test/utils.spec.js +0 -31
- package/lib/test/utils.spec.js.map +0 -1
- /package/{dist → lib}/tsdoc-metadata.json +0 -0
|
@@ -1,555 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { strict as assert } from "assert";
|
|
6
|
-
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
7
|
-
import { useFakeTimers } from "sinon";
|
|
8
|
-
import { createChildLogger } from "@fluidframework/telemetry-utils";
|
|
9
|
-
import { Audience } from "../audience.js";
|
|
10
|
-
import { ConnectionState } from "../connectionState.js";
|
|
11
|
-
import { createConnectionStateHandlerCore, } from "../connectionStateHandler.js";
|
|
12
|
-
import { ProtocolHandler } from "../protocol.js";
|
|
13
|
-
class MockDeltaManagerForCatchingUp extends TypedEventEmitter {
|
|
14
|
-
constructor() {
|
|
15
|
-
super(...arguments);
|
|
16
|
-
this.lastSequenceNumber = 5;
|
|
17
|
-
this.lastKnownSeqNumber = 10;
|
|
18
|
-
}
|
|
19
|
-
catchUp(seq = 10) {
|
|
20
|
-
this.lastKnownSeqNumber = seq;
|
|
21
|
-
this.lastSequenceNumber = seq;
|
|
22
|
-
this.emit("op", { sequenceNumber: this.lastKnownSeqNumber });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
describe("ConnectionStateHandler Tests", () => {
|
|
26
|
-
let clock;
|
|
27
|
-
let handlerInputs;
|
|
28
|
-
let connectionStateHandler;
|
|
29
|
-
let protocolHandler;
|
|
30
|
-
let shouldClientJoinWrite;
|
|
31
|
-
let connectionDetails;
|
|
32
|
-
let connectionDetails2;
|
|
33
|
-
let connectionDetails3;
|
|
34
|
-
const expectedTimeout = 90000;
|
|
35
|
-
const pendingClientId = "pendingClientId";
|
|
36
|
-
const pendingClientId2 = "pendingClientId2";
|
|
37
|
-
const pendingClientId3 = "pendingClientId3";
|
|
38
|
-
let deltaManagerForCatchingUp;
|
|
39
|
-
let connectionStateHandler_receivedAddMemberEvent;
|
|
40
|
-
let connectionStateHandler_receivedJoinSignalEvent;
|
|
41
|
-
let connectionStateHandler_receivedRemoveMemberEvent;
|
|
42
|
-
// Stash the real setTimeout because sinon fake timers will hijack it.
|
|
43
|
-
const realSetTimeout = setTimeout;
|
|
44
|
-
// function to yield control in the Javascript event loop.
|
|
45
|
-
async function yieldEventLoop() {
|
|
46
|
-
await new Promise((resolve) => {
|
|
47
|
-
realSetTimeout(resolve, 0);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
async function tickClock(tickValue) {
|
|
51
|
-
clock.tick(tickValue);
|
|
52
|
-
// Yield the event loop because the outbound op will be processed asynchronously.
|
|
53
|
-
await yieldEventLoop();
|
|
54
|
-
}
|
|
55
|
-
function createHandler(connectedRaisedWhenCaughtUp, readClientsWaitForJoinSignal) {
|
|
56
|
-
const handler = createConnectionStateHandlerCore(connectedRaisedWhenCaughtUp, readClientsWaitForJoinSignal, handlerInputs, deltaManagerForCatchingUp, undefined);
|
|
57
|
-
handler.initProtocol(protocolHandler);
|
|
58
|
-
return handler;
|
|
59
|
-
}
|
|
60
|
-
before(() => {
|
|
61
|
-
clock = useFakeTimers();
|
|
62
|
-
});
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
connectionDetails = {
|
|
65
|
-
clientId: pendingClientId,
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
67
|
-
claims: {},
|
|
68
|
-
mode: "read",
|
|
69
|
-
version: "0.1",
|
|
70
|
-
initialClients: [],
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
72
|
-
serviceConfiguration: {},
|
|
73
|
-
checkpointSequenceNumber: undefined,
|
|
74
|
-
reason: { text: "test" },
|
|
75
|
-
};
|
|
76
|
-
connectionDetails2 = {
|
|
77
|
-
clientId: pendingClientId2,
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
79
|
-
claims: {},
|
|
80
|
-
mode: "write",
|
|
81
|
-
version: "0.1",
|
|
82
|
-
initialClients: [],
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
84
|
-
serviceConfiguration: {},
|
|
85
|
-
checkpointSequenceNumber: undefined,
|
|
86
|
-
reason: { text: "test" },
|
|
87
|
-
};
|
|
88
|
-
connectionDetails3 = {
|
|
89
|
-
clientId: pendingClientId3,
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
91
|
-
claims: {},
|
|
92
|
-
mode: "write",
|
|
93
|
-
version: "0.1",
|
|
94
|
-
initialClients: [],
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
96
|
-
serviceConfiguration: {},
|
|
97
|
-
checkpointSequenceNumber: undefined,
|
|
98
|
-
reason: { text: "test" },
|
|
99
|
-
};
|
|
100
|
-
protocolHandler = new ProtocolHandler({ minimumSequenceNumber: 0, sequenceNumber: 0 }, // attributes
|
|
101
|
-
{ members: [], proposals: [], values: [] }, // quorumSnapshot
|
|
102
|
-
(key, value) => 0, // sendProposal
|
|
103
|
-
new Audience(), (clientId) => false);
|
|
104
|
-
shouldClientJoinWrite = false;
|
|
105
|
-
handlerInputs = {
|
|
106
|
-
maxClientLeaveWaitTime: expectedTimeout,
|
|
107
|
-
shouldClientJoinWrite: () => shouldClientJoinWrite,
|
|
108
|
-
logConnectionIssue: (eventName, category, details) => {
|
|
109
|
-
throw new Error(`logConnectionIssue: ${eventName} ${JSON.stringify(details)}`);
|
|
110
|
-
},
|
|
111
|
-
connectionStateChanged: () => { },
|
|
112
|
-
logger: createChildLogger(),
|
|
113
|
-
clientShouldHaveLeft: (clientId) => { },
|
|
114
|
-
};
|
|
115
|
-
deltaManagerForCatchingUp = new MockDeltaManagerForCatchingUp();
|
|
116
|
-
connectionStateHandler = createHandler(false, // connectedRaisedWhenCaughtUp,
|
|
117
|
-
false); // readClientsWaitForJoinSignal
|
|
118
|
-
connectionStateHandler_receivedAddMemberEvent = (id) => {
|
|
119
|
-
protocolHandler.quorum.addMember(id, { client: {} });
|
|
120
|
-
};
|
|
121
|
-
connectionStateHandler_receivedRemoveMemberEvent = (id) => {
|
|
122
|
-
protocolHandler.quorum.removeMember(id);
|
|
123
|
-
};
|
|
124
|
-
connectionStateHandler_receivedJoinSignalEvent = (details) => {
|
|
125
|
-
protocolHandler.audience.addMember(details.clientId, {
|
|
126
|
-
mode: details.mode,
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
afterEach(() => {
|
|
131
|
-
// Get rid of timers
|
|
132
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "the end of test" });
|
|
133
|
-
connectionStateHandler.dispose();
|
|
134
|
-
});
|
|
135
|
-
it("Should move to connected state on normal flow for read client", async () => {
|
|
136
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in disconnected state");
|
|
137
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
138
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Read Client should be in connected state");
|
|
139
|
-
});
|
|
140
|
-
it("Should move to connected after catching up for read client #1", async () => {
|
|
141
|
-
connectionStateHandler = createHandler(true, // connectedRaisedWhenCaughtUp
|
|
142
|
-
false); // readClientsWaitForJoinSignal
|
|
143
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in Disconnected state");
|
|
144
|
-
connectionStateHandler.establishingConnection({ text: "read" });
|
|
145
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
146
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in CatchingUp state");
|
|
147
|
-
deltaManagerForCatchingUp.catchUp();
|
|
148
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Read Client should be in Connected state");
|
|
149
|
-
});
|
|
150
|
-
it("Should move to connected after catching up for read client #2", async () => {
|
|
151
|
-
connectionStateHandler = createHandler(true, // connectedRaisedWhenCaughtUp
|
|
152
|
-
true); // readClientsWaitForJoinSignal
|
|
153
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in Disconnected state");
|
|
154
|
-
connectionStateHandler.establishingConnection({ text: "read" });
|
|
155
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
156
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in CatchingUp state");
|
|
157
|
-
deltaManagerForCatchingUp.catchUp();
|
|
158
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in CatchingUp state");
|
|
159
|
-
connectionStateHandler_receivedJoinSignalEvent(connectionDetails);
|
|
160
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Read Client should be in Connected state");
|
|
161
|
-
});
|
|
162
|
-
it("Should move to connected after catching up for read client #3", async () => {
|
|
163
|
-
connectionStateHandler = createHandler(true, // connectedRaisedWhenCaughtUp
|
|
164
|
-
true); // readClientsWaitForJoinSignal
|
|
165
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in Disconnected state");
|
|
166
|
-
connectionStateHandler.establishingConnection({ text: "read" });
|
|
167
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
168
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in CatchingUp state");
|
|
169
|
-
connectionStateHandler_receivedJoinSignalEvent(connectionDetails);
|
|
170
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in CatchingUp state");
|
|
171
|
-
deltaManagerForCatchingUp.catchUp();
|
|
172
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Read Client should be in Connected state");
|
|
173
|
-
});
|
|
174
|
-
it("Should move to connected after receiving join op for read client", async () => {
|
|
175
|
-
connectionStateHandler = createHandler(false, // connectedRaisedWhenCaughtUp
|
|
176
|
-
true); // readClientsWaitForJoinSignal
|
|
177
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in Disconnected state");
|
|
178
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
179
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in CatchingUp state");
|
|
180
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
181
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Read Client should be in Connected state");
|
|
182
|
-
});
|
|
183
|
-
it("Changes in lastKnownSeqNumber by join signal should be picked up", async () => {
|
|
184
|
-
connectionStateHandler = createHandler(true, // connectedRaisedWhenCaughtUp
|
|
185
|
-
true); // readClientsWaitForJoinSignal
|
|
186
|
-
connectionStateHandler.establishingConnection({ text: "write" });
|
|
187
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
188
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in CatchingUp state");
|
|
189
|
-
const lastKnown = deltaManagerForCatchingUp.lastKnownSeqNumber;
|
|
190
|
-
const signalRef = lastKnown + 10;
|
|
191
|
-
deltaManagerForCatchingUp.catchUp(lastKnown);
|
|
192
|
-
deltaManagerForCatchingUp.lastKnownSeqNumber = signalRef;
|
|
193
|
-
connectionStateHandler_receivedJoinSignalEvent(connectionDetails);
|
|
194
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in CatchingUp state");
|
|
195
|
-
deltaManagerForCatchingUp.catchUp(signalRef);
|
|
196
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Read Client should be in Connected state");
|
|
197
|
-
});
|
|
198
|
-
it("Should move to connected state on normal flow for write client", async () => {
|
|
199
|
-
connectionDetails.mode = "write";
|
|
200
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in disconnected state");
|
|
201
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
202
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in connecting state");
|
|
203
|
-
connectionStateHandler_receivedAddMemberEvent("anotherClientId");
|
|
204
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Some other client joined.");
|
|
205
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
206
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client should be in connected state");
|
|
207
|
-
});
|
|
208
|
-
it("Should move to connected state after catching up for write client", async () => {
|
|
209
|
-
connectionDetails.mode = "write";
|
|
210
|
-
connectionStateHandler = createHandler(true, // connectedRaisedWhenCaughtUp
|
|
211
|
-
false); // readClientsWaitForJoinSignal
|
|
212
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in Disconnected state");
|
|
213
|
-
connectionStateHandler.establishingConnection({ text: "write" });
|
|
214
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
215
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in CatchingUp state");
|
|
216
|
-
connectionStateHandler_receivedAddMemberEvent("anotherClientId");
|
|
217
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Some other client joined.");
|
|
218
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
219
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in CatchingUp state until caught up");
|
|
220
|
-
deltaManagerForCatchingUp.catchUp();
|
|
221
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client should be in Connected state");
|
|
222
|
-
});
|
|
223
|
-
it("Connect write first, init protocol later #1", async () => {
|
|
224
|
-
// ConnectionStateManager without initialized protocol
|
|
225
|
-
connectionStateHandler = createConnectionStateHandlerCore(false, // connectedRaisedWhenCaughtUp,
|
|
226
|
-
false, // readClientsWaitForJoinSignal
|
|
227
|
-
handlerInputs, deltaManagerForCatchingUp, undefined);
|
|
228
|
-
connectionDetails.mode = "write";
|
|
229
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in disconnected state");
|
|
230
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
231
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in connecting state");
|
|
232
|
-
// init protocol
|
|
233
|
-
connectionStateHandler.initProtocol(protocolHandler);
|
|
234
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
235
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client should be in connected state");
|
|
236
|
-
});
|
|
237
|
-
it("Connect write first, init protocol later #2", async () => {
|
|
238
|
-
// ConnectionStateManager without initialized protocol
|
|
239
|
-
connectionStateHandler = createConnectionStateHandlerCore(false, // connectedRaisedWhenCaughtUp,
|
|
240
|
-
false, // readClientsWaitForJoinSignal
|
|
241
|
-
handlerInputs, deltaManagerForCatchingUp, undefined);
|
|
242
|
-
connectionDetails.mode = "write";
|
|
243
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in disconnected state");
|
|
244
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
245
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client should be in connecting state");
|
|
246
|
-
/*
|
|
247
|
-
There is a tiny tiny race possible, where these events happen in this order:
|
|
248
|
-
1. A connection is established (no "cached" mode is used, so it happens in parallel / faster than other steps)
|
|
249
|
-
2. Some other client produces a summary
|
|
250
|
-
3. We get "lucky" and load from that summary as our initial snapshot
|
|
251
|
-
4. ConnectionStateHandler.initProtocol is called, "self" is already in the quorum.
|
|
252
|
-
We could avoid this sequence (and delete this test case and handling in initProtocol()) if
|
|
253
|
-
we move connection lower in Container.load().
|
|
254
|
-
*/
|
|
255
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
256
|
-
// init protocol
|
|
257
|
-
connectionStateHandler.initProtocol(protocolHandler);
|
|
258
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client should be in connected state");
|
|
259
|
-
});
|
|
260
|
-
it("Should wait for previous client to leave before moving to connected state", async () => {
|
|
261
|
-
connectionDetails.mode = "write";
|
|
262
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
263
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
264
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client should be in connected state");
|
|
265
|
-
shouldClientJoinWrite = true;
|
|
266
|
-
// Disconnect the client
|
|
267
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
268
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in disconnected state");
|
|
269
|
-
// Make new client join so that it waits for previous client to leave
|
|
270
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails2);
|
|
271
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId2);
|
|
272
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should be in connecting state as we are waiting for leave");
|
|
273
|
-
// Send leave
|
|
274
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId);
|
|
275
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 2 should be in connected state");
|
|
276
|
-
});
|
|
277
|
-
it("Should wait for previous client to leave before moving to connected state, even if already in quorum", async () => {
|
|
278
|
-
connectionDetails.mode = "write";
|
|
279
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
280
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
281
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client should be in connected state");
|
|
282
|
-
shouldClientJoinWrite = true;
|
|
283
|
-
// Disconnect the client
|
|
284
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
285
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in disconnected state");
|
|
286
|
-
// Make new client join so that it waits for previous client to leave
|
|
287
|
-
// Put Client 2 in quorum before receiving connect event
|
|
288
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId2);
|
|
289
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails2);
|
|
290
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should be in connecting state as we are waiting for leave");
|
|
291
|
-
// Send leave
|
|
292
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId);
|
|
293
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 2 should be in connected state");
|
|
294
|
-
});
|
|
295
|
-
it("read connection following write connection won't have leave timer", async () => {
|
|
296
|
-
// Connect a write client, to be Disconnected
|
|
297
|
-
connectionDetails.mode = "write";
|
|
298
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
299
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
300
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client should be in connected state");
|
|
301
|
-
// Disconnect the first client, indicating all pending ops were ack'd
|
|
302
|
-
shouldClientJoinWrite = false;
|
|
303
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
304
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in disconnected state");
|
|
305
|
-
// Make new client join as read - no waiting for leave since shouldClientJoinWrite is false
|
|
306
|
-
connectionDetails3.mode = "read";
|
|
307
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails3);
|
|
308
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 2 should be in connected state");
|
|
309
|
-
});
|
|
310
|
-
it("Should wait for timeout before moving to connected state if no leave received", async () => {
|
|
311
|
-
connectionDetails.mode = "write";
|
|
312
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
313
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
314
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client should be in connected state");
|
|
315
|
-
shouldClientJoinWrite = true;
|
|
316
|
-
// Disconnect the client
|
|
317
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
318
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in disconnected state");
|
|
319
|
-
// Make new client join so that it waits for previous client to leave
|
|
320
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails2);
|
|
321
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId2);
|
|
322
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should be in connecting state as we are waiting for timeout");
|
|
323
|
-
// Check state before timeout
|
|
324
|
-
await tickClock(expectedTimeout - 1);
|
|
325
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should still be in connecting state as we are waiting for timeout");
|
|
326
|
-
await tickClock(1);
|
|
327
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 2 should now be in connected state");
|
|
328
|
-
});
|
|
329
|
-
it("Should wait for Saved event before moving to connected state if no leave received", async () => {
|
|
330
|
-
connectionDetails.mode = "write";
|
|
331
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
332
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
333
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client should be in connected state");
|
|
334
|
-
shouldClientJoinWrite = true;
|
|
335
|
-
// Disconnect the client
|
|
336
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
337
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client should be in disconnected state");
|
|
338
|
-
// Make new client join so that it waits for previous client to leave
|
|
339
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails2);
|
|
340
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId2);
|
|
341
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should be in connecting state as we are waiting for timeout");
|
|
342
|
-
// Check state before timeout
|
|
343
|
-
await tickClock(expectedTimeout - 1);
|
|
344
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should still be in connecting state as we are waiting for timeout");
|
|
345
|
-
// Fire the container saved event.
|
|
346
|
-
connectionStateHandler.containerSaved();
|
|
347
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 2 should now be in connected state");
|
|
348
|
-
});
|
|
349
|
-
it("All pending state should be cleared after disconnect", async () => {
|
|
350
|
-
connectionDetails.mode = "write";
|
|
351
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
352
|
-
assert(connectionStateHandler.pendingClientId !== undefined, "pendingClientId should be set after receiving 'connect' event");
|
|
353
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "test" });
|
|
354
|
-
assert(connectionStateHandler.pendingClientId === undefined, "pendingClientId should not be set after receiving 'disconnect' event");
|
|
355
|
-
});
|
|
356
|
-
async function testComplex(client3mode) {
|
|
357
|
-
connectionDetails.mode = "write";
|
|
358
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
359
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
360
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 1 should be in connected state");
|
|
361
|
-
shouldClientJoinWrite = true;
|
|
362
|
-
// Disconnect the client
|
|
363
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
364
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 1 should be in disconnected state");
|
|
365
|
-
// Make new client join but disconnect it from connecting state
|
|
366
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails2);
|
|
367
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should be in connecting state");
|
|
368
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
369
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 2 should be in disconnected state");
|
|
370
|
-
// Make new client 3 join so that it waits for client 1 to leave
|
|
371
|
-
// This is rather tricky case when client3mode === "read", as we are testing adding "read" client when
|
|
372
|
-
// shouldClientJoinWrite() reports true.
|
|
373
|
-
connectionDetails3.mode = client3mode;
|
|
374
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails3);
|
|
375
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId3);
|
|
376
|
-
// Send leave for client 2 and check that client 3 should not move to connected state as we were waiting
|
|
377
|
-
// on client 1 leave
|
|
378
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId2);
|
|
379
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId2);
|
|
380
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state");
|
|
381
|
-
// Client 1 leaves.
|
|
382
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId);
|
|
383
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 3 should move to connected state");
|
|
384
|
-
// Timeout should not raise any error as timer should be cleared
|
|
385
|
-
await tickClock(expectedTimeout);
|
|
386
|
-
}
|
|
387
|
-
it("Should wait for client 1 to leave before moving to connected state(Client 3) when client 2 got disconnected from connecting state #1", async () => {
|
|
388
|
-
return testComplex("read");
|
|
389
|
-
});
|
|
390
|
-
it("Should wait for client 1 to leave before moving to connected state(Client 3) when client 2 got disconnected from connecting state #2", async () => {
|
|
391
|
-
return testComplex("write");
|
|
392
|
-
});
|
|
393
|
-
it("Should wait for client 1 timeout before moving to connected state(Client 3) when client 2 got disconnected from connecting state #3", async () => {
|
|
394
|
-
connectionDetails.mode = "write";
|
|
395
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
396
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
397
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 1 should be in connected state");
|
|
398
|
-
shouldClientJoinWrite = true;
|
|
399
|
-
// Disconnect the client
|
|
400
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
401
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 1 should be in disconnected state");
|
|
402
|
-
// Make new client join but disconnect it from connecting state
|
|
403
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails2);
|
|
404
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should be in connecting state");
|
|
405
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
406
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 2 should be in disconnected state");
|
|
407
|
-
// Make new client 3 join so that it waits for client 1 to leave
|
|
408
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails3);
|
|
409
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId3);
|
|
410
|
-
// Send leave for client 2 and check that client 3 should not move to connected state as we were waiting
|
|
411
|
-
// on client 1 leave.
|
|
412
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId2);
|
|
413
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId2);
|
|
414
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state");
|
|
415
|
-
// Pass some time.
|
|
416
|
-
await tickClock(expectedTimeout - 1);
|
|
417
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state as timeout has not occured");
|
|
418
|
-
await tickClock(1);
|
|
419
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 3 should move to connected state");
|
|
420
|
-
// Sending client 1 leave now should not cause any error
|
|
421
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId);
|
|
422
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 3 should move to connected state");
|
|
423
|
-
});
|
|
424
|
-
it("Should wait for savedEvent before moving to connected state(Client 3) when client 2 got disconnected from connecting state", async () => {
|
|
425
|
-
connectionDetails.mode = "write";
|
|
426
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
427
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
428
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 1 should be in connected state");
|
|
429
|
-
shouldClientJoinWrite = true;
|
|
430
|
-
// Disconnect the client
|
|
431
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
432
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 1 should be in disconnected state");
|
|
433
|
-
// Make new client join but disconnect it from connecting state
|
|
434
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails2);
|
|
435
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should be in connecting state");
|
|
436
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
437
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 2 should be in disconnected state");
|
|
438
|
-
// Make new client 3 join so that it waits for client 1 to leave
|
|
439
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails3);
|
|
440
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId3);
|
|
441
|
-
// Send leave for client 2 and check that client 3 should not move to connected state as we were waiting
|
|
442
|
-
// on client 1 leave.
|
|
443
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId2);
|
|
444
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId2);
|
|
445
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state");
|
|
446
|
-
// Pass some time.
|
|
447
|
-
await tickClock(expectedTimeout - 1);
|
|
448
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state as timeout has not occured");
|
|
449
|
-
connectionStateHandler.containerSaved();
|
|
450
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 3 should move to connected state");
|
|
451
|
-
// Sending client 1 leave now should not cause any error
|
|
452
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId);
|
|
453
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 3 should move to connected state");
|
|
454
|
-
});
|
|
455
|
-
it("Should wait for client 1 to leave before moving to connected state(Client 3) when client 2 " +
|
|
456
|
-
"got disconnected from connected state", async () => {
|
|
457
|
-
connectionDetails.mode = "write";
|
|
458
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
459
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
460
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 1 should be in connected state");
|
|
461
|
-
shouldClientJoinWrite = true;
|
|
462
|
-
// Disconnect the client
|
|
463
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
464
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 1 should be in disconnected state");
|
|
465
|
-
// Make new client join but disconnect it from connected state
|
|
466
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails2);
|
|
467
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId2);
|
|
468
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should still be in connecting state");
|
|
469
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
470
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 2 should be in disconnected state");
|
|
471
|
-
// Make new client 3 join so that it waits for client 1 to leave
|
|
472
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails3);
|
|
473
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId3);
|
|
474
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state");
|
|
475
|
-
// Send leave for client 2 and check that client 3 should not move to connected state as we were waiting
|
|
476
|
-
// on client 1 leave
|
|
477
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId2);
|
|
478
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state");
|
|
479
|
-
// Client 1 leaves.
|
|
480
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId);
|
|
481
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 3 should move to connected state");
|
|
482
|
-
// Timeout should not raise any error as timer should be cleared
|
|
483
|
-
await tickClock(expectedTimeout);
|
|
484
|
-
});
|
|
485
|
-
it("Should wait for client 1 timeout before moving to connected state(Client 3) when client 2 " +
|
|
486
|
-
"got disconnected from connected state", async () => {
|
|
487
|
-
connectionDetails.mode = "write";
|
|
488
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
489
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
490
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 1 should be in connected state");
|
|
491
|
-
shouldClientJoinWrite = true;
|
|
492
|
-
// Disconnect the client
|
|
493
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
494
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 1 should be in disconnected state");
|
|
495
|
-
// Make new client join but disconnect it from connecting state
|
|
496
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails2);
|
|
497
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId2);
|
|
498
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should still be in connecting state");
|
|
499
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
500
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 2 should be in disconnected state");
|
|
501
|
-
// Make new client 3 join so that it waits for client 1 to leave
|
|
502
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails3);
|
|
503
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId3);
|
|
504
|
-
// Send leave for client 2 and check that client 3 should not move to connected state as we were waiting
|
|
505
|
-
// on client 1 leave.
|
|
506
|
-
connectionStateHandler_receivedRemoveMemberEvent("pendingClientId2");
|
|
507
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state");
|
|
508
|
-
// Pass some time.
|
|
509
|
-
await tickClock(expectedTimeout - 1);
|
|
510
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state as timeout has not occured");
|
|
511
|
-
await tickClock(1);
|
|
512
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 3 should move to connected state");
|
|
513
|
-
// Sending client 1 leave now should not cause any error
|
|
514
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId);
|
|
515
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 3 should move to connected state");
|
|
516
|
-
});
|
|
517
|
-
it("Client 3 should wait for client 2(which got disconnected without sending any ops) to leave " +
|
|
518
|
-
"when client 2 already waited on client 1", async () => {
|
|
519
|
-
connectionDetails.mode = "write";
|
|
520
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails);
|
|
521
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId);
|
|
522
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 1 should be in connected state");
|
|
523
|
-
shouldClientJoinWrite = true;
|
|
524
|
-
// Disconnect the client
|
|
525
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
526
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 1 should be in disconnected state");
|
|
527
|
-
// Make new client join but disconnect it from connected state
|
|
528
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails2);
|
|
529
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId2);
|
|
530
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 2 should still be in connecting state");
|
|
531
|
-
// Client 1 leaves.
|
|
532
|
-
connectionStateHandler_receivedRemoveMemberEvent(pendingClientId);
|
|
533
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 2 should move to connected state");
|
|
534
|
-
// Client 2 leaves without sending any ops.
|
|
535
|
-
connectionStateHandler.receivedDisconnectEvent({ text: "Test" });
|
|
536
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Disconnected, "Client 2 should be in disconnected state");
|
|
537
|
-
// Make new client 3 join. Now it should not wait for previous client as client 2 already waited.
|
|
538
|
-
connectionStateHandler.receivedConnectEvent(connectionDetails3);
|
|
539
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state");
|
|
540
|
-
connectionStateHandler_receivedAddMemberEvent(pendingClientId3);
|
|
541
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.CatchingUp, "Client 3 should still be in connecting state");
|
|
542
|
-
// Client 2 leaves.
|
|
543
|
-
connectionStateHandler_receivedRemoveMemberEvent("pendingClientId2");
|
|
544
|
-
assert.strictEqual(connectionStateHandler.connectionState, ConnectionState.Connected, "Client 3 should move to connected state");
|
|
545
|
-
// Timeout should not raise any error as timer should be cleared
|
|
546
|
-
await tickClock(expectedTimeout);
|
|
547
|
-
});
|
|
548
|
-
afterEach(() => {
|
|
549
|
-
clock.reset();
|
|
550
|
-
});
|
|
551
|
-
after(() => {
|
|
552
|
-
clock.restore();
|
|
553
|
-
});
|
|
554
|
-
});
|
|
555
|
-
//# sourceMappingURL=connectionStateHandler.spec.js.map
|