@peers-app/peers-device 0.15.0 → 0.15.1
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/dist/chunk-download-manager.d.ts +2 -2
- package/dist/chunk-download-manager.js +1 -1
- package/dist/chunk-download-manager.js.map +1 -1
- package/dist/chunk-download-manager.test.js +57 -57
- package/dist/chunk-download-manager.test.js.map +1 -1
- package/dist/chunk-download.types.d.ts +1 -1
- package/dist/connection-manager/connection-manager-priorities.d.ts +1 -1
- package/dist/connection-manager/connection-manager-priorities.js +10 -6
- package/dist/connection-manager/connection-manager-priorities.js.map +1 -1
- package/dist/connection-manager/connection-manager-priorities.test.js +192 -194
- package/dist/connection-manager/connection-manager-priorities.test.js.map +1 -1
- package/dist/connection-manager/connection-manager.d.ts +2 -2
- package/dist/connection-manager/connection-manager.js +71 -55
- package/dist/connection-manager/connection-manager.js.map +1 -1
- package/dist/connection-manager/connection-manager.test.js +165 -147
- package/dist/connection-manager/connection-manager.test.js.map +1 -1
- package/dist/connection-manager/connection-state.type.d.ts +1 -1
- package/dist/connection-manager/device-message-handler.types.d.ts +6 -6
- package/dist/connection-manager/device-messages.d.ts +4 -4
- package/dist/connection-manager/device-messages.js +56 -40
- package/dist/connection-manager/device-messages.js.map +1 -1
- package/dist/connection-manager/group-invite-messages.d.ts +2 -2
- package/dist/connection-manager/group-invite-messages.js +36 -47
- package/dist/connection-manager/group-invite-messages.js.map +1 -1
- package/dist/connection-manager/hops-map.js +4 -4
- package/dist/connection-manager/hops-map.js.map +1 -1
- package/dist/connection-manager/hops-map.test.js +3 -3
- package/dist/connection-manager/hops-map.test.js.map +1 -1
- package/dist/connection-manager/network-manager.d.ts +2 -2
- package/dist/connection-manager/network-manager.js +81 -75
- package/dist/connection-manager/network-manager.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/json-diff.d.ts +2 -2
- package/dist/json-diff.js +30 -27
- package/dist/json-diff.js.map +1 -1
- package/dist/local.data-source.d.ts +1 -1
- package/dist/local.data-source.js +23 -23
- package/dist/local.data-source.js.map +1 -1
- package/dist/local.data-source.test.js +17 -17
- package/dist/local.data-source.test.js.map +1 -1
- package/dist/machine-stats.js +57 -51
- package/dist/machine-stats.js.map +1 -1
- package/dist/machine-stats.test.js +42 -42
- package/dist/machine-stats.test.js.map +1 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.js +10 -8
- package/dist/main.js.map +1 -1
- package/dist/packages.tracked-data-source.d.ts +1 -1
- package/dist/packages.tracked-data-source.js.map +1 -1
- package/dist/persistent-vars.test.js +148 -148
- package/dist/persistent-vars.test.js.map +1 -1
- package/dist/pvars.tracked-data-source.d.ts +1 -1
- package/dist/pvars.tracked-data-source.js +12 -10
- package/dist/pvars.tracked-data-source.js.map +1 -1
- package/dist/sync-group.d.ts +2 -2
- package/dist/sync-group.js +110 -88
- package/dist/sync-group.js.map +1 -1
- package/dist/sync-group.test.js +157 -120
- package/dist/sync-group.test.js.map +1 -1
- package/dist/tracked-data-source.d.ts +1 -1
- package/dist/tracked-data-source.js +61 -62
- package/dist/tracked-data-source.js.map +1 -1
- package/dist/tracked-data-source.test.js +507 -299
- package/dist/tracked-data-source.test.js.map +1 -1
- package/dist/websocket-client.d.ts +1 -1
- package/dist/websocket-client.js +50 -41
- package/dist/websocket-client.js.map +1 -1
- package/package.json +3 -3
|
@@ -8,10 +8,10 @@ const connection_manager_priorities_1 = require("./connection-manager-priorities
|
|
|
8
8
|
describe("getLeastPreferredManagerConnection", () => {
|
|
9
9
|
const syncGroups = [];
|
|
10
10
|
afterAll(async () => {
|
|
11
|
-
await Promise.all(syncGroups.map(d => d.dispose()));
|
|
11
|
+
await Promise.all(syncGroups.map((d) => d.dispose()));
|
|
12
12
|
});
|
|
13
13
|
function createMockSyncGroup(userId = (0, peers_sdk_1.newid)(), deviceId = (0, peers_sdk_1.newid)(), groupId = (0, peers_sdk_1.newid)()) {
|
|
14
|
-
const db = new local_data_source_1.DBLocal(
|
|
14
|
+
const db = new local_data_source_1.DBLocal(":memory:");
|
|
15
15
|
const changeTrackingTable = new peers_sdk_1.ChangeTrackingTable({ db });
|
|
16
16
|
const mockUserContext = {
|
|
17
17
|
userId: () => userId,
|
|
@@ -22,13 +22,13 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
22
22
|
return sqlDS;
|
|
23
23
|
}
|
|
24
24
|
return new tracked_data_source_1.TrackedDataSource(sqlDS, changeTrackingTable);
|
|
25
|
-
}
|
|
25
|
+
},
|
|
26
26
|
};
|
|
27
27
|
const dataContext = new peers_sdk_1.DataContext(mockUserContext);
|
|
28
28
|
// Mock the dataContextId getter
|
|
29
|
-
Object.defineProperty(dataContext,
|
|
29
|
+
Object.defineProperty(dataContext, "dataContextId", {
|
|
30
30
|
get: () => groupId,
|
|
31
|
-
configurable: true
|
|
31
|
+
configurable: true,
|
|
32
32
|
});
|
|
33
33
|
const syncGroup = new sync_group_1.SyncGroup(dataContext, changeTrackingTable);
|
|
34
34
|
syncGroups.push(syncGroup);
|
|
@@ -56,7 +56,7 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
56
56
|
id,
|
|
57
57
|
send: jest.fn(),
|
|
58
58
|
on: jest.fn(),
|
|
59
|
-
dispose: jest.fn()
|
|
59
|
+
dispose: jest.fn(),
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
afterEach(() => {
|
|
@@ -70,8 +70,8 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
70
70
|
it("should return undefined when devices have no connections", () => {
|
|
71
71
|
const device1 = createMockSyncGroup();
|
|
72
72
|
const device2 = createMockSyncGroup();
|
|
73
|
-
jest.spyOn(device1,
|
|
74
|
-
jest.spyOn(device2,
|
|
73
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([]);
|
|
74
|
+
jest.spyOn(device2, "getConnections").mockReturnValue([]);
|
|
75
75
|
const connectionStates = new Map();
|
|
76
76
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1, device2], connectionStates);
|
|
77
77
|
expect(result).toBeUndefined();
|
|
@@ -80,17 +80,17 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
80
80
|
it("should prioritize removing null group connections over regular connections", () => {
|
|
81
81
|
const device1 = createMockSyncGroup("user1", "device1", "group1");
|
|
82
82
|
const connection1 = createMockConnection("remote1", 0.9, 500); // High error rate but in a group
|
|
83
|
-
jest.spyOn(device1,
|
|
84
|
-
jest.spyOn(device1,
|
|
83
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1]);
|
|
84
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
85
85
|
preferredDeviceIds: [],
|
|
86
86
|
preferredByDeviceIds: [],
|
|
87
|
-
priorityDeviceIds: []
|
|
87
|
+
priorityDeviceIds: [],
|
|
88
88
|
});
|
|
89
89
|
// Create connection states: one with groups, one without
|
|
90
90
|
const socketConn1 = createMockSocketConnection("conn1");
|
|
91
91
|
const socketConn2 = createMockSocketConnection("conn2");
|
|
92
92
|
const connectionStates = new Map();
|
|
93
|
-
connectionStates.set(socketConn1, createMockConnectionState("user1", {
|
|
93
|
+
connectionStates.set(socketConn1, createMockConnectionState("user1", { group1_device1: {} }));
|
|
94
94
|
connectionStates.set(socketConn2, createMockConnectionState("user2", {})); // No groups - null connection
|
|
95
95
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1], connectionStates);
|
|
96
96
|
expect(result).toBeDefined();
|
|
@@ -99,11 +99,11 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
99
99
|
});
|
|
100
100
|
it("should randomly select one null group connection when multiple exist", () => {
|
|
101
101
|
const device1 = createMockSyncGroup("user1", "device1", "group1");
|
|
102
|
-
jest.spyOn(device1,
|
|
103
|
-
jest.spyOn(device1,
|
|
102
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([]);
|
|
103
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
104
104
|
preferredDeviceIds: [],
|
|
105
105
|
preferredByDeviceIds: [],
|
|
106
|
-
priorityDeviceIds: []
|
|
106
|
+
priorityDeviceIds: [],
|
|
107
107
|
});
|
|
108
108
|
// Create multiple null group connections
|
|
109
109
|
const socketConn1 = createMockSocketConnection("conn1");
|
|
@@ -121,16 +121,16 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
121
121
|
it("should fall back to priority logic when no null group connections exist", () => {
|
|
122
122
|
const device1 = createMockSyncGroup("user1", "device1", "group1");
|
|
123
123
|
const connection1 = createMockConnection("remote1", 0.5, 100);
|
|
124
|
-
jest.spyOn(device1,
|
|
125
|
-
jest.spyOn(device1,
|
|
124
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1]);
|
|
125
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
126
126
|
preferredDeviceIds: [],
|
|
127
127
|
preferredByDeviceIds: [],
|
|
128
|
-
priorityDeviceIds: []
|
|
128
|
+
priorityDeviceIds: [],
|
|
129
129
|
});
|
|
130
130
|
// All connections have groups
|
|
131
131
|
const socketConn1 = createMockSocketConnection("conn1");
|
|
132
132
|
const connectionStates = new Map();
|
|
133
|
-
connectionStates.set(socketConn1, createMockConnectionState("user1", {
|
|
133
|
+
connectionStates.set(socketConn1, createMockConnectionState("user1", { group1_device1: {} }));
|
|
134
134
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1], connectionStates);
|
|
135
135
|
expect(result).toBeDefined();
|
|
136
136
|
// Should fall back to the device connection from priority logic
|
|
@@ -139,11 +139,11 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
139
139
|
it("should handle empty connectionStates map", () => {
|
|
140
140
|
const device1 = createMockSyncGroup("user1", "device1", "group1");
|
|
141
141
|
const connection1 = createMockConnection("remote1", 0.5, 100);
|
|
142
|
-
jest.spyOn(device1,
|
|
143
|
-
jest.spyOn(device1,
|
|
142
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1]);
|
|
143
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
144
144
|
preferredDeviceIds: [],
|
|
145
145
|
preferredByDeviceIds: [],
|
|
146
|
-
priorityDeviceIds: []
|
|
146
|
+
priorityDeviceIds: [],
|
|
147
147
|
});
|
|
148
148
|
const connectionStates = new Map();
|
|
149
149
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1], connectionStates);
|
|
@@ -157,17 +157,17 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
157
157
|
const connection1 = createMockConnection("remote1", 0.1, 100);
|
|
158
158
|
const connection2 = createMockConnection("remote1", 0.2, 200);
|
|
159
159
|
const connection3 = createMockConnection("remote2", 0.5, 50);
|
|
160
|
-
jest.spyOn(device1,
|
|
161
|
-
jest.spyOn(device2,
|
|
162
|
-
jest.spyOn(device1,
|
|
160
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1, connection3]);
|
|
161
|
+
jest.spyOn(device2, "getConnections").mockReturnValue([connection2]);
|
|
162
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
163
163
|
preferredDeviceIds: [],
|
|
164
164
|
preferredByDeviceIds: [],
|
|
165
|
-
priorityDeviceIds: []
|
|
165
|
+
priorityDeviceIds: [],
|
|
166
166
|
});
|
|
167
|
-
jest.spyOn(device2,
|
|
167
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
168
168
|
preferredDeviceIds: [],
|
|
169
169
|
preferredByDeviceIds: [],
|
|
170
|
-
priorityDeviceIds: []
|
|
170
|
+
priorityDeviceIds: [],
|
|
171
171
|
});
|
|
172
172
|
const connectionStates = new Map();
|
|
173
173
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1, device2], connectionStates);
|
|
@@ -183,17 +183,17 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
183
183
|
// Same remote device connected to both groups with different metrics
|
|
184
184
|
const connection1 = createMockConnection("remote1", 0.1, 100);
|
|
185
185
|
const connection2 = createMockConnection("remote1", 0.3, 200);
|
|
186
|
-
jest.spyOn(device1,
|
|
187
|
-
jest.spyOn(device2,
|
|
188
|
-
jest.spyOn(device1,
|
|
186
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1]);
|
|
187
|
+
jest.spyOn(device2, "getConnections").mockReturnValue([connection2]);
|
|
188
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
189
189
|
preferredDeviceIds: [],
|
|
190
190
|
preferredByDeviceIds: [],
|
|
191
|
-
priorityDeviceIds: []
|
|
191
|
+
priorityDeviceIds: [],
|
|
192
192
|
});
|
|
193
|
-
jest.spyOn(device2,
|
|
193
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
194
194
|
preferredDeviceIds: [],
|
|
195
195
|
preferredByDeviceIds: [],
|
|
196
|
-
priorityDeviceIds: []
|
|
196
|
+
priorityDeviceIds: [],
|
|
197
197
|
});
|
|
198
198
|
const connectionStates = new Map();
|
|
199
199
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1, device2], connectionStates);
|
|
@@ -209,11 +209,11 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
209
209
|
const connection1 = createMockConnection("remote1", 0.1, 100);
|
|
210
210
|
const connection2 = createMockConnection("remote2", 0.5, 200); // Higher error rate
|
|
211
211
|
const connection3 = createMockConnection("remote3", 0.2, 150);
|
|
212
|
-
jest.spyOn(device1,
|
|
213
|
-
jest.spyOn(device1,
|
|
214
|
-
preferredDeviceIds: [
|
|
212
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1, connection2, connection3]);
|
|
213
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
214
|
+
preferredDeviceIds: ["remote1"], // remote1 is preferred, so shouldn't be removed
|
|
215
215
|
preferredByDeviceIds: [],
|
|
216
|
-
priorityDeviceIds: [
|
|
216
|
+
priorityDeviceIds: ["remote1"],
|
|
217
217
|
});
|
|
218
218
|
const connectionStates = new Map();
|
|
219
219
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1], connectionStates);
|
|
@@ -228,11 +228,11 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
228
228
|
const connection1 = createMockConnection("remote1", 0.1, 100);
|
|
229
229
|
const connection2 = createMockConnection("remote2", 0.5, 200);
|
|
230
230
|
const connection3 = createMockConnection("remote3", 0.2, 150);
|
|
231
|
-
jest.spyOn(device1,
|
|
232
|
-
jest.spyOn(device1,
|
|
231
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1, connection2, connection3]);
|
|
232
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
233
233
|
preferredDeviceIds: [],
|
|
234
234
|
preferredByDeviceIds: [],
|
|
235
|
-
priorityDeviceIds: []
|
|
235
|
+
priorityDeviceIds: [],
|
|
236
236
|
});
|
|
237
237
|
const connectionStates = new Map();
|
|
238
238
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1], connectionStates);
|
|
@@ -244,11 +244,11 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
244
244
|
});
|
|
245
245
|
it("should handle empty connections gracefully", () => {
|
|
246
246
|
const device1 = createMockSyncGroup("user1", "device1", "group1");
|
|
247
|
-
jest.spyOn(device1,
|
|
248
|
-
jest.spyOn(device1,
|
|
247
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([]);
|
|
248
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
249
249
|
preferredDeviceIds: [],
|
|
250
250
|
preferredByDeviceIds: [],
|
|
251
|
-
priorityDeviceIds: []
|
|
251
|
+
priorityDeviceIds: [],
|
|
252
252
|
});
|
|
253
253
|
const connectionStates = new Map();
|
|
254
254
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1], connectionStates);
|
|
@@ -262,23 +262,23 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
262
262
|
const connection1 = createMockConnection("remote1", 0.1, 100);
|
|
263
263
|
const connection2 = createMockConnection("remote1", 0.2, 200);
|
|
264
264
|
const connection3 = createMockConnection("remote1", 0.3, 300);
|
|
265
|
-
jest.spyOn(device1,
|
|
266
|
-
jest.spyOn(device2,
|
|
267
|
-
jest.spyOn(device3,
|
|
268
|
-
jest.spyOn(device1,
|
|
265
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1]);
|
|
266
|
+
jest.spyOn(device2, "getConnections").mockReturnValue([connection2]);
|
|
267
|
+
jest.spyOn(device3, "getConnections").mockReturnValue([connection3]);
|
|
268
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
269
269
|
preferredDeviceIds: [],
|
|
270
270
|
preferredByDeviceIds: [],
|
|
271
|
-
priorityDeviceIds: []
|
|
271
|
+
priorityDeviceIds: [],
|
|
272
272
|
});
|
|
273
|
-
jest.spyOn(device2,
|
|
273
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
274
274
|
preferredDeviceIds: [],
|
|
275
275
|
preferredByDeviceIds: [],
|
|
276
|
-
priorityDeviceIds: []
|
|
276
|
+
priorityDeviceIds: [],
|
|
277
277
|
});
|
|
278
|
-
jest.spyOn(device3,
|
|
278
|
+
jest.spyOn(device3, "priorityDeviceIds", "get").mockReturnValue({
|
|
279
279
|
preferredDeviceIds: [],
|
|
280
280
|
preferredByDeviceIds: [],
|
|
281
|
-
priorityDeviceIds: []
|
|
281
|
+
priorityDeviceIds: [],
|
|
282
282
|
});
|
|
283
283
|
const connectionStates = new Map();
|
|
284
284
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1, device2, device3], connectionStates);
|
|
@@ -296,24 +296,24 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
296
296
|
const connection2 = createMockConnection("remote2", 0.2, 200);
|
|
297
297
|
const connection3 = createMockConnection("remote3", 0.3, 150);
|
|
298
298
|
const connection4 = createMockConnection("remote4", 0.8, 1); // Highest error rate
|
|
299
|
-
jest.spyOn(device1,
|
|
300
|
-
jest.spyOn(device2,
|
|
301
|
-
jest.spyOn(device3,
|
|
299
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1, connection4]);
|
|
300
|
+
jest.spyOn(device2, "getConnections").mockReturnValue([connection2]);
|
|
301
|
+
jest.spyOn(device3, "getConnections").mockReturnValue([connection3]);
|
|
302
302
|
// Different priority lists for each group
|
|
303
|
-
jest.spyOn(device1,
|
|
304
|
-
preferredDeviceIds: [
|
|
305
|
-
preferredByDeviceIds: [
|
|
306
|
-
priorityDeviceIds: [
|
|
303
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
304
|
+
preferredDeviceIds: ["remote1", "remote2"],
|
|
305
|
+
preferredByDeviceIds: ["remote3"],
|
|
306
|
+
priorityDeviceIds: ["remote1", "remote2", "remote3"],
|
|
307
307
|
});
|
|
308
|
-
jest.spyOn(device2,
|
|
309
|
-
preferredDeviceIds: [
|
|
310
|
-
preferredByDeviceIds: [
|
|
311
|
-
priorityDeviceIds: [
|
|
308
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
309
|
+
preferredDeviceIds: ["remote2", "remote3"],
|
|
310
|
+
preferredByDeviceIds: ["remote1"],
|
|
311
|
+
priorityDeviceIds: ["remote1", "remote2", "remote3"],
|
|
312
312
|
});
|
|
313
|
-
jest.spyOn(device3,
|
|
314
|
-
preferredDeviceIds: [
|
|
315
|
-
preferredByDeviceIds: [
|
|
316
|
-
priorityDeviceIds: [
|
|
313
|
+
jest.spyOn(device3, "priorityDeviceIds", "get").mockReturnValue({
|
|
314
|
+
preferredDeviceIds: ["remote1"],
|
|
315
|
+
preferredByDeviceIds: ["remote2", "remote3"],
|
|
316
|
+
priorityDeviceIds: ["remote1", "remote2", "remote3"],
|
|
317
317
|
});
|
|
318
318
|
const connectionStates = new Map();
|
|
319
319
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1, device2, device3], connectionStates);
|
|
@@ -336,24 +336,26 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
336
336
|
const connection2b = createMockConnection("remote2", 0.1, 100);
|
|
337
337
|
// remote3: connected to only 1 group (least critical - should be removed)
|
|
338
338
|
const connection3 = createMockConnection("remote3", 0.1, 100);
|
|
339
|
-
jest
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
jest
|
|
340
|
+
.spyOn(device1, "getConnections")
|
|
341
|
+
.mockReturnValue([connection1a, connection2a, connection3]);
|
|
342
|
+
jest.spyOn(device2, "getConnections").mockReturnValue([connection1b, connection2b]);
|
|
343
|
+
jest.spyOn(device3, "getConnections").mockReturnValue([connection1c]);
|
|
342
344
|
// No preferences - should select based on group count
|
|
343
|
-
jest.spyOn(device1,
|
|
345
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
344
346
|
preferredDeviceIds: [],
|
|
345
347
|
preferredByDeviceIds: [],
|
|
346
|
-
priorityDeviceIds: []
|
|
348
|
+
priorityDeviceIds: [],
|
|
347
349
|
});
|
|
348
|
-
jest.spyOn(device2,
|
|
350
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
349
351
|
preferredDeviceIds: [],
|
|
350
352
|
preferredByDeviceIds: [],
|
|
351
|
-
priorityDeviceIds: []
|
|
353
|
+
priorityDeviceIds: [],
|
|
352
354
|
});
|
|
353
|
-
jest.spyOn(device3,
|
|
355
|
+
jest.spyOn(device3, "priorityDeviceIds", "get").mockReturnValue({
|
|
354
356
|
preferredDeviceIds: [],
|
|
355
357
|
preferredByDeviceIds: [],
|
|
356
|
-
priorityDeviceIds: []
|
|
358
|
+
priorityDeviceIds: [],
|
|
357
359
|
});
|
|
358
360
|
const connectionStates = new Map();
|
|
359
361
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1, device2, device3], connectionStates);
|
|
@@ -370,17 +372,17 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
370
372
|
const connection1b = createMockConnection("remote1", 0.1, 100);
|
|
371
373
|
// remote2: connected to only 1 group but with zero errors
|
|
372
374
|
const connection2 = createMockConnection("remote2", 0, 200);
|
|
373
|
-
jest.spyOn(device1,
|
|
374
|
-
jest.spyOn(device2,
|
|
375
|
-
jest.spyOn(device1,
|
|
375
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1a, connection2]);
|
|
376
|
+
jest.spyOn(device2, "getConnections").mockReturnValue([connection1b]);
|
|
377
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
376
378
|
preferredDeviceIds: [],
|
|
377
379
|
preferredByDeviceIds: [],
|
|
378
|
-
priorityDeviceIds: []
|
|
380
|
+
priorityDeviceIds: [],
|
|
379
381
|
});
|
|
380
|
-
jest.spyOn(device2,
|
|
382
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
381
383
|
preferredDeviceIds: [],
|
|
382
384
|
preferredByDeviceIds: [],
|
|
383
|
-
priorityDeviceIds: []
|
|
385
|
+
priorityDeviceIds: [],
|
|
384
386
|
});
|
|
385
387
|
const connectionStates = new Map();
|
|
386
388
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1, device2], connectionStates);
|
|
@@ -395,11 +397,11 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
395
397
|
// Both connections are only in 1 group, so should use error rate to decide
|
|
396
398
|
const connection1 = createMockConnection("remote1", 0.1, 100); // Lower error rate
|
|
397
399
|
const connection2 = createMockConnection("remote2", 0.5, 200); // Higher error rate
|
|
398
|
-
jest.spyOn(device1,
|
|
399
|
-
jest.spyOn(device1,
|
|
400
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1, connection2]);
|
|
401
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
400
402
|
preferredDeviceIds: [],
|
|
401
403
|
preferredByDeviceIds: [],
|
|
402
|
-
priorityDeviceIds: []
|
|
404
|
+
priorityDeviceIds: [],
|
|
403
405
|
});
|
|
404
406
|
const connectionStates = new Map();
|
|
405
407
|
const result = (0, connection_manager_priorities_1.getLeastPreferredManagerConnection)([device1], connectionStates);
|
|
@@ -413,10 +415,10 @@ describe("getLeastPreferredManagerConnection", () => {
|
|
|
413
415
|
describe("getPreferredDeviceIds", () => {
|
|
414
416
|
const devices = [];
|
|
415
417
|
afterAll(async () => {
|
|
416
|
-
await Promise.all(devices.map(d => d.dispose()));
|
|
418
|
+
await Promise.all(devices.map((d) => d.dispose()));
|
|
417
419
|
});
|
|
418
420
|
function createMockDeviceSync(userId = (0, peers_sdk_1.newid)(), deviceId = (0, peers_sdk_1.newid)(), groupId = (0, peers_sdk_1.newid)()) {
|
|
419
|
-
const db = new local_data_source_1.DBLocal(
|
|
421
|
+
const db = new local_data_source_1.DBLocal(":memory:");
|
|
420
422
|
const changeTrackingTable = new peers_sdk_1.ChangeTrackingTable({ db });
|
|
421
423
|
const mockUserContext = {
|
|
422
424
|
userId: () => userId,
|
|
@@ -427,13 +429,13 @@ describe("getPreferredDeviceIds", () => {
|
|
|
427
429
|
return sqlDS;
|
|
428
430
|
}
|
|
429
431
|
return new tracked_data_source_1.TrackedDataSource(sqlDS, changeTrackingTable);
|
|
430
|
-
}
|
|
432
|
+
},
|
|
431
433
|
};
|
|
432
434
|
const dataContext = new peers_sdk_1.DataContext(mockUserContext);
|
|
433
435
|
// Mock the dataContextId getter
|
|
434
|
-
Object.defineProperty(dataContext,
|
|
436
|
+
Object.defineProperty(dataContext, "dataContextId", {
|
|
435
437
|
get: () => groupId,
|
|
436
|
-
configurable: true
|
|
438
|
+
configurable: true,
|
|
437
439
|
});
|
|
438
440
|
const deviceSync = new sync_group_1.SyncGroup(dataContext, changeTrackingTable);
|
|
439
441
|
devices.push(deviceSync);
|
|
@@ -447,15 +449,15 @@ describe("getPreferredDeviceIds", () => {
|
|
|
447
449
|
it("should return empty arrays when devices have no priority device IDs", () => {
|
|
448
450
|
const device1 = createMockDeviceSync();
|
|
449
451
|
const device2 = createMockDeviceSync();
|
|
450
|
-
jest.spyOn(device1,
|
|
452
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
451
453
|
preferredDeviceIds: [],
|
|
452
454
|
preferredByDeviceIds: [],
|
|
453
|
-
priorityDeviceIds: []
|
|
455
|
+
priorityDeviceIds: [],
|
|
454
456
|
});
|
|
455
|
-
jest.spyOn(device2,
|
|
457
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
456
458
|
preferredDeviceIds: [],
|
|
457
459
|
preferredByDeviceIds: [],
|
|
458
|
-
priorityDeviceIds: []
|
|
460
|
+
priorityDeviceIds: [],
|
|
459
461
|
});
|
|
460
462
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1, device2]);
|
|
461
463
|
expect(result.preferredDeviceIds).toEqual([]);
|
|
@@ -463,45 +465,41 @@ describe("getPreferredDeviceIds", () => {
|
|
|
463
465
|
});
|
|
464
466
|
it("should collect preferred device IDs from a single device", () => {
|
|
465
467
|
const device1 = createMockDeviceSync();
|
|
466
|
-
jest.spyOn(device1,
|
|
467
|
-
preferredDeviceIds: [
|
|
468
|
-
preferredByDeviceIds: [
|
|
469
|
-
priorityDeviceIds: [
|
|
468
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
469
|
+
preferredDeviceIds: ["device1", "device2"],
|
|
470
|
+
preferredByDeviceIds: ["device3"],
|
|
471
|
+
priorityDeviceIds: ["device1", "device2", "device3"],
|
|
470
472
|
});
|
|
471
473
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1]);
|
|
472
|
-
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining([
|
|
474
|
+
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining(["device1", "device2"]));
|
|
473
475
|
expect(result.preferredDeviceIds.length).toBe(2);
|
|
474
|
-
expect(result.preferredByDeviceIds).toEqual([
|
|
476
|
+
expect(result.preferredByDeviceIds).toEqual(["device3"]);
|
|
475
477
|
});
|
|
476
478
|
it("should merge preferred device IDs from multiple devices", () => {
|
|
477
479
|
const device1 = createMockDeviceSync();
|
|
478
480
|
const device2 = createMockDeviceSync();
|
|
479
481
|
const device3 = createMockDeviceSync();
|
|
480
|
-
jest.spyOn(device1,
|
|
481
|
-
preferredDeviceIds: [
|
|
482
|
-
preferredByDeviceIds: [
|
|
483
|
-
priorityDeviceIds: [
|
|
482
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
483
|
+
preferredDeviceIds: ["device1", "device2"],
|
|
484
|
+
preferredByDeviceIds: ["device3"],
|
|
485
|
+
priorityDeviceIds: ["device1", "device2", "device3"],
|
|
484
486
|
});
|
|
485
|
-
jest.spyOn(device2,
|
|
486
|
-
preferredDeviceIds: [
|
|
487
|
-
preferredByDeviceIds: [
|
|
488
|
-
priorityDeviceIds: [
|
|
487
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
488
|
+
preferredDeviceIds: ["device2", "device4"],
|
|
489
|
+
preferredByDeviceIds: ["device5", "device6"],
|
|
490
|
+
priorityDeviceIds: ["device2", "device4", "device5", "device6"],
|
|
489
491
|
});
|
|
490
|
-
jest.spyOn(device3,
|
|
491
|
-
preferredDeviceIds: [
|
|
492
|
-
preferredByDeviceIds: [
|
|
493
|
-
priorityDeviceIds: [
|
|
492
|
+
jest.spyOn(device3, "priorityDeviceIds", "get").mockReturnValue({
|
|
493
|
+
preferredDeviceIds: ["device7"],
|
|
494
|
+
preferredByDeviceIds: ["device3", "device8"],
|
|
495
|
+
priorityDeviceIds: ["device3", "device7", "device8"],
|
|
494
496
|
});
|
|
495
497
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1, device2, device3]);
|
|
496
498
|
// Should contain all unique preferred device IDs
|
|
497
|
-
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining([
|
|
498
|
-
'device1', 'device2', 'device4', 'device7'
|
|
499
|
-
]));
|
|
499
|
+
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining(["device1", "device2", "device4", "device7"]));
|
|
500
500
|
expect(result.preferredDeviceIds.length).toBe(4);
|
|
501
501
|
// Should contain all unique preferredBy device IDs
|
|
502
|
-
expect(result.preferredByDeviceIds).toEqual(expect.arrayContaining([
|
|
503
|
-
'device3', 'device5', 'device6', 'device8'
|
|
504
|
-
]));
|
|
502
|
+
expect(result.preferredByDeviceIds).toEqual(expect.arrayContaining(["device3", "device5", "device6", "device8"]));
|
|
505
503
|
expect(result.preferredByDeviceIds.length).toBe(4);
|
|
506
504
|
});
|
|
507
505
|
it("should deduplicate device IDs across multiple devices", () => {
|
|
@@ -509,118 +507,118 @@ describe("getPreferredDeviceIds", () => {
|
|
|
509
507
|
const device2 = createMockDeviceSync();
|
|
510
508
|
const device3 = createMockDeviceSync();
|
|
511
509
|
// All devices prefer the same devices
|
|
512
|
-
jest.spyOn(device1,
|
|
513
|
-
preferredDeviceIds: [
|
|
514
|
-
preferredByDeviceIds: [
|
|
515
|
-
priorityDeviceIds: [
|
|
510
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
511
|
+
preferredDeviceIds: ["deviceA", "deviceB"],
|
|
512
|
+
preferredByDeviceIds: ["deviceC"],
|
|
513
|
+
priorityDeviceIds: ["deviceA", "deviceB", "deviceC"],
|
|
516
514
|
});
|
|
517
|
-
jest.spyOn(device2,
|
|
518
|
-
preferredDeviceIds: [
|
|
519
|
-
preferredByDeviceIds: [
|
|
520
|
-
priorityDeviceIds: [
|
|
515
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
516
|
+
preferredDeviceIds: ["deviceA", "deviceB"],
|
|
517
|
+
preferredByDeviceIds: ["deviceC"],
|
|
518
|
+
priorityDeviceIds: ["deviceA", "deviceB", "deviceC"],
|
|
521
519
|
});
|
|
522
|
-
jest.spyOn(device3,
|
|
523
|
-
preferredDeviceIds: [
|
|
524
|
-
preferredByDeviceIds: [
|
|
525
|
-
priorityDeviceIds: [
|
|
520
|
+
jest.spyOn(device3, "priorityDeviceIds", "get").mockReturnValue({
|
|
521
|
+
preferredDeviceIds: ["deviceA", "deviceB"],
|
|
522
|
+
preferredByDeviceIds: ["deviceC"],
|
|
523
|
+
priorityDeviceIds: ["deviceA", "deviceB", "deviceC"],
|
|
526
524
|
});
|
|
527
525
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1, device2, device3]);
|
|
528
526
|
// Should only contain unique entries
|
|
529
|
-
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining([
|
|
527
|
+
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining(["deviceA", "deviceB"]));
|
|
530
528
|
expect(result.preferredDeviceIds.length).toBe(2);
|
|
531
|
-
expect(result.preferredByDeviceIds).toEqual([
|
|
529
|
+
expect(result.preferredByDeviceIds).toEqual(["deviceC"]);
|
|
532
530
|
expect(result.preferredByDeviceIds.length).toBe(1);
|
|
533
531
|
});
|
|
534
532
|
it("should handle devices with only preferredDeviceIds", () => {
|
|
535
533
|
const device1 = createMockDeviceSync();
|
|
536
|
-
jest.spyOn(device1,
|
|
537
|
-
preferredDeviceIds: [
|
|
534
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
535
|
+
preferredDeviceIds: ["device1", "device2", "device3"],
|
|
538
536
|
preferredByDeviceIds: [],
|
|
539
|
-
priorityDeviceIds: [
|
|
537
|
+
priorityDeviceIds: ["device1", "device2", "device3"],
|
|
540
538
|
});
|
|
541
539
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1]);
|
|
542
|
-
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining([
|
|
540
|
+
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining(["device1", "device2", "device3"]));
|
|
543
541
|
expect(result.preferredDeviceIds.length).toBe(3);
|
|
544
542
|
expect(result.preferredByDeviceIds).toEqual([]);
|
|
545
543
|
});
|
|
546
544
|
it("should handle devices with only preferredByDeviceIds", () => {
|
|
547
545
|
const device1 = createMockDeviceSync();
|
|
548
|
-
jest.spyOn(device1,
|
|
546
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
549
547
|
preferredDeviceIds: [],
|
|
550
|
-
preferredByDeviceIds: [
|
|
551
|
-
priorityDeviceIds: [
|
|
548
|
+
preferredByDeviceIds: ["device1", "device2", "device3"],
|
|
549
|
+
priorityDeviceIds: ["device1", "device2", "device3"],
|
|
552
550
|
});
|
|
553
551
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1]);
|
|
554
552
|
expect(result.preferredDeviceIds).toEqual([]);
|
|
555
|
-
expect(result.preferredByDeviceIds).toEqual(expect.arrayContaining([
|
|
553
|
+
expect(result.preferredByDeviceIds).toEqual(expect.arrayContaining(["device1", "device2", "device3"]));
|
|
556
554
|
expect(result.preferredByDeviceIds.length).toBe(3);
|
|
557
555
|
});
|
|
558
556
|
it("should handle a mix of devices with and without priority IDs", () => {
|
|
559
557
|
const device1 = createMockDeviceSync();
|
|
560
558
|
const device2 = createMockDeviceSync();
|
|
561
559
|
const device3 = createMockDeviceSync();
|
|
562
|
-
jest.spyOn(device1,
|
|
563
|
-
preferredDeviceIds: [
|
|
564
|
-
preferredByDeviceIds: [
|
|
565
|
-
priorityDeviceIds: [
|
|
560
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
561
|
+
preferredDeviceIds: ["device1"],
|
|
562
|
+
preferredByDeviceIds: ["device2"],
|
|
563
|
+
priorityDeviceIds: ["device1", "device2"],
|
|
566
564
|
});
|
|
567
|
-
jest.spyOn(device2,
|
|
565
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
568
566
|
preferredDeviceIds: [],
|
|
569
567
|
preferredByDeviceIds: [],
|
|
570
|
-
priorityDeviceIds: []
|
|
568
|
+
priorityDeviceIds: [],
|
|
571
569
|
});
|
|
572
|
-
jest.spyOn(device3,
|
|
573
|
-
preferredDeviceIds: [
|
|
570
|
+
jest.spyOn(device3, "priorityDeviceIds", "get").mockReturnValue({
|
|
571
|
+
preferredDeviceIds: ["device3"],
|
|
574
572
|
preferredByDeviceIds: [],
|
|
575
|
-
priorityDeviceIds: [
|
|
573
|
+
priorityDeviceIds: ["device3"],
|
|
576
574
|
});
|
|
577
575
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1, device2, device3]);
|
|
578
|
-
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining([
|
|
576
|
+
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining(["device1", "device3"]));
|
|
579
577
|
expect(result.preferredDeviceIds.length).toBe(2);
|
|
580
|
-
expect(result.preferredByDeviceIds).toEqual([
|
|
578
|
+
expect(result.preferredByDeviceIds).toEqual(["device2"]);
|
|
581
579
|
});
|
|
582
580
|
it("should handle the same device ID appearing in both preferred lists", () => {
|
|
583
581
|
const device1 = createMockDeviceSync();
|
|
584
582
|
const device2 = createMockDeviceSync();
|
|
585
583
|
// device1 prefers deviceX, device2 is preferred by deviceX
|
|
586
|
-
jest.spyOn(device1,
|
|
587
|
-
preferredDeviceIds: [
|
|
584
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
585
|
+
preferredDeviceIds: ["deviceX", "deviceY"],
|
|
588
586
|
preferredByDeviceIds: [],
|
|
589
|
-
priorityDeviceIds: [
|
|
587
|
+
priorityDeviceIds: ["deviceX", "deviceY"],
|
|
590
588
|
});
|
|
591
|
-
jest.spyOn(device2,
|
|
589
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
592
590
|
preferredDeviceIds: [],
|
|
593
|
-
preferredByDeviceIds: [
|
|
594
|
-
priorityDeviceIds: [
|
|
591
|
+
preferredByDeviceIds: ["deviceX", "deviceZ"],
|
|
592
|
+
priorityDeviceIds: ["deviceX", "deviceZ"],
|
|
595
593
|
});
|
|
596
594
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1, device2]);
|
|
597
595
|
// deviceX can appear in both lists
|
|
598
|
-
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining([
|
|
596
|
+
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining(["deviceX", "deviceY"]));
|
|
599
597
|
expect(result.preferredDeviceIds.length).toBe(2);
|
|
600
|
-
expect(result.preferredByDeviceIds).toEqual(expect.arrayContaining([
|
|
598
|
+
expect(result.preferredByDeviceIds).toEqual(expect.arrayContaining(["deviceX", "deviceZ"]));
|
|
601
599
|
expect(result.preferredByDeviceIds.length).toBe(2);
|
|
602
600
|
});
|
|
603
601
|
it("should work correctly when devices have no connections", () => {
|
|
604
602
|
const device1 = createMockDeviceSync();
|
|
605
603
|
const device2 = createMockDeviceSync();
|
|
606
604
|
// Devices have priority IDs but no actual connections
|
|
607
|
-
jest.spyOn(device1,
|
|
608
|
-
jest.spyOn(device2,
|
|
609
|
-
jest.spyOn(device1,
|
|
610
|
-
preferredDeviceIds: [
|
|
611
|
-
preferredByDeviceIds: [
|
|
612
|
-
priorityDeviceIds: [
|
|
613
|
-
});
|
|
614
|
-
jest.spyOn(device2,
|
|
615
|
-
preferredDeviceIds: [
|
|
616
|
-
preferredByDeviceIds: [
|
|
617
|
-
priorityDeviceIds: [
|
|
605
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([]);
|
|
606
|
+
jest.spyOn(device2, "getConnections").mockReturnValue([]);
|
|
607
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
608
|
+
preferredDeviceIds: ["device1", "device2"],
|
|
609
|
+
preferredByDeviceIds: ["device3"],
|
|
610
|
+
priorityDeviceIds: ["device1", "device2", "device3"],
|
|
611
|
+
});
|
|
612
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
613
|
+
preferredDeviceIds: ["device4"],
|
|
614
|
+
preferredByDeviceIds: ["device5"],
|
|
615
|
+
priorityDeviceIds: ["device4", "device5"],
|
|
618
616
|
});
|
|
619
617
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1, device2]);
|
|
620
618
|
// Should still collect priority IDs even without connections
|
|
621
|
-
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining([
|
|
619
|
+
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining(["device1", "device2", "device4"]));
|
|
622
620
|
expect(result.preferredDeviceIds.length).toBe(3);
|
|
623
|
-
expect(result.preferredByDeviceIds).toEqual(expect.arrayContaining([
|
|
621
|
+
expect(result.preferredByDeviceIds).toEqual(expect.arrayContaining(["device3", "device5"]));
|
|
624
622
|
expect(result.preferredByDeviceIds.length).toBe(2);
|
|
625
623
|
});
|
|
626
624
|
it("should work correctly when connections don't share any groups", () => {
|
|
@@ -630,21 +628,21 @@ describe("getPreferredDeviceIds", () => {
|
|
|
630
628
|
const connection1 = createMockConnection("remote1", 0.1, 100);
|
|
631
629
|
const connection2 = createMockConnection("remote2", 0.2, 200);
|
|
632
630
|
// Mock connections that exist but aren't in any shared groups
|
|
633
|
-
jest.spyOn(device1,
|
|
634
|
-
jest.spyOn(device2,
|
|
635
|
-
jest.spyOn(device1,
|
|
636
|
-
preferredDeviceIds: [
|
|
631
|
+
jest.spyOn(device1, "getConnections").mockReturnValue([connection1]);
|
|
632
|
+
jest.spyOn(device2, "getConnections").mockReturnValue([connection2]);
|
|
633
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
634
|
+
preferredDeviceIds: ["remote1"],
|
|
637
635
|
preferredByDeviceIds: [],
|
|
638
|
-
priorityDeviceIds: [
|
|
636
|
+
priorityDeviceIds: ["remote1"],
|
|
639
637
|
});
|
|
640
|
-
jest.spyOn(device2,
|
|
641
|
-
preferredDeviceIds: [
|
|
638
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
639
|
+
preferredDeviceIds: ["remote2"],
|
|
642
640
|
preferredByDeviceIds: [],
|
|
643
|
-
priorityDeviceIds: [
|
|
641
|
+
priorityDeviceIds: ["remote2"],
|
|
644
642
|
});
|
|
645
643
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1, device2]);
|
|
646
644
|
// Should still return priority IDs regardless of group membership
|
|
647
|
-
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining([
|
|
645
|
+
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining(["remote1", "remote2"]));
|
|
648
646
|
expect(result.preferredDeviceIds.length).toBe(2);
|
|
649
647
|
expect(result.preferredByDeviceIds).toEqual([]);
|
|
650
648
|
});
|
|
@@ -653,26 +651,26 @@ describe("getPreferredDeviceIds", () => {
|
|
|
653
651
|
const device2 = createMockDeviceSync();
|
|
654
652
|
const device3 = createMockDeviceSync();
|
|
655
653
|
// Mix of devices: some with connections in groups, some without
|
|
656
|
-
jest.spyOn(device1,
|
|
657
|
-
preferredDeviceIds: [
|
|
658
|
-
preferredByDeviceIds: [
|
|
659
|
-
priorityDeviceIds: [
|
|
654
|
+
jest.spyOn(device1, "priorityDeviceIds", "get").mockReturnValue({
|
|
655
|
+
preferredDeviceIds: ["deviceA", "deviceB"],
|
|
656
|
+
preferredByDeviceIds: ["deviceC"],
|
|
657
|
+
priorityDeviceIds: ["deviceA", "deviceB", "deviceC"],
|
|
660
658
|
});
|
|
661
|
-
jest.spyOn(device2,
|
|
659
|
+
jest.spyOn(device2, "priorityDeviceIds", "get").mockReturnValue({
|
|
662
660
|
preferredDeviceIds: [],
|
|
663
661
|
preferredByDeviceIds: [],
|
|
664
|
-
priorityDeviceIds: []
|
|
662
|
+
priorityDeviceIds: [],
|
|
665
663
|
});
|
|
666
|
-
jest.spyOn(device3,
|
|
667
|
-
preferredDeviceIds: [
|
|
668
|
-
preferredByDeviceIds: [
|
|
669
|
-
priorityDeviceIds: [
|
|
664
|
+
jest.spyOn(device3, "priorityDeviceIds", "get").mockReturnValue({
|
|
665
|
+
preferredDeviceIds: ["deviceD"],
|
|
666
|
+
preferredByDeviceIds: ["deviceE"],
|
|
667
|
+
priorityDeviceIds: ["deviceD", "deviceE"],
|
|
670
668
|
});
|
|
671
669
|
const result = (0, connection_manager_priorities_1.getConnectionManagerPreferredDeviceIds)([device1, device2, device3]);
|
|
672
670
|
// Should aggregate all priority IDs regardless of connection state
|
|
673
|
-
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining([
|
|
671
|
+
expect(result.preferredDeviceIds).toEqual(expect.arrayContaining(["deviceA", "deviceB", "deviceD"]));
|
|
674
672
|
expect(result.preferredDeviceIds.length).toBe(3);
|
|
675
|
-
expect(result.preferredByDeviceIds).toEqual(expect.arrayContaining([
|
|
673
|
+
expect(result.preferredByDeviceIds).toEqual(expect.arrayContaining(["deviceC", "deviceE"]));
|
|
676
674
|
expect(result.preferredByDeviceIds.length).toBe(2);
|
|
677
675
|
});
|
|
678
676
|
function createMockConnection(deviceId, errorRate = 0, latencyMs = 10, timestampLastApplied = Date.now()) {
|