@fluidframework/test-utils 2.0.0-internal.3.0.1 → 2.0.0-internal.3.1.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/.eslintrc.js +8 -10
- package/README.md +41 -11
- package/api-extractor.json +2 -2
- package/dist/DriverWrappers.d.ts.map +1 -1
- package/dist/DriverWrappers.js.map +1 -1
- package/dist/TestConfigs.d.ts.map +1 -1
- package/dist/TestConfigs.js +3 -2
- package/dist/TestConfigs.js.map +1 -1
- package/dist/TestSummaryUtils.d.ts +1 -1
- package/dist/TestSummaryUtils.d.ts.map +1 -1
- package/dist/TestSummaryUtils.js +8 -6
- package/dist/TestSummaryUtils.js.map +1 -1
- package/dist/containerUtils.d.ts.map +1 -1
- package/dist/containerUtils.js +3 -1
- package/dist/containerUtils.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/loaderContainerTracker.d.ts.map +1 -1
- package/dist/loaderContainerTracker.js +37 -27
- package/dist/loaderContainerTracker.js.map +1 -1
- package/dist/localCodeLoader.d.ts.map +1 -1
- package/dist/localCodeLoader.js.map +1 -1
- package/dist/localLoader.d.ts.map +1 -1
- package/dist/localLoader.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/retry.d.ts.map +1 -1
- package/dist/retry.js.map +1 -1
- package/dist/testContainerRuntimeFactory.d.ts.map +1 -1
- package/dist/testContainerRuntimeFactory.js +2 -1
- package/dist/testContainerRuntimeFactory.js.map +1 -1
- package/dist/testFluidObject.d.ts.map +1 -1
- package/dist/testFluidObject.js +7 -3
- package/dist/testFluidObject.js.map +1 -1
- package/dist/testObjectProvider.d.ts +4 -1
- package/dist/testObjectProvider.d.ts.map +1 -1
- package/dist/testObjectProvider.js +28 -11
- package/dist/testObjectProvider.js.map +1 -1
- package/dist/timeoutUtils.d.ts.map +1 -1
- package/dist/timeoutUtils.js +4 -3
- package/dist/timeoutUtils.js.map +1 -1
- package/package.json +121 -119
- package/prettier.config.cjs +1 -1
- package/src/DriverWrappers.ts +40 -37
- package/src/TestConfigs.ts +9 -7
- package/src/TestSummaryUtils.ts +120 -115
- package/src/containerUtils.ts +18 -16
- package/src/index.ts +27 -23
- package/src/interfaces.ts +10 -7
- package/src/loaderContainerTracker.ts +627 -565
- package/src/localCodeLoader.ts +85 -77
- package/src/localLoader.ts +24 -24
- package/src/packageVersion.ts +1 -1
- package/src/retry.ts +31 -25
- package/src/testContainerRuntimeFactory.ts +59 -56
- package/src/testFluidObject.ts +168 -152
- package/src/testObjectProvider.ts +445 -384
- package/src/timeoutUtils.ts +174 -154
- package/tsconfig.json +9 -16
|
@@ -6,7 +6,11 @@ import { assert } from "@fluidframework/common-utils";
|
|
|
6
6
|
import { IContainer, IDeltaQueue, IHostLoader } from "@fluidframework/container-definitions";
|
|
7
7
|
import { Container } from "@fluidframework/container-loader";
|
|
8
8
|
import { canBeCoalescedByService } from "@fluidframework/driver-utils";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
IDocumentMessage,
|
|
11
|
+
ISequencedDocumentMessage,
|
|
12
|
+
MessageType,
|
|
13
|
+
} from "@fluidframework/protocol-definitions";
|
|
10
14
|
import { debug } from "./debug";
|
|
11
15
|
import { IOpProcessingController } from "./testObjectProvider";
|
|
12
16
|
import { timeoutAwait, timeoutPromise } from "./timeoutUtils";
|
|
@@ -15,574 +19,632 @@ const debugOp = debug.extend("ops");
|
|
|
15
19
|
const debugWait = debug.extend("wait");
|
|
16
20
|
|
|
17
21
|
interface ContainerRecord {
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
// A short number for debug output
|
|
23
|
+
index: number;
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
// LoaderContainerTracker paused state
|
|
26
|
+
paused: boolean;
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
// Tracking trailing no-op that may or may be acked by the server so we can discount them
|
|
29
|
+
// See issue #5629
|
|
30
|
+
startTrailingNoOps: number;
|
|
31
|
+
trailingNoOps: number;
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
// Track last proposal to ensure no unresolved proposal
|
|
34
|
+
lastProposal: number;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export class LoaderContainerTracker implements IOpProcessingController {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
38
|
+
private readonly containers = new Map<IContainer, ContainerRecord>();
|
|
39
|
+
private lastProposalSeqNum: number = 0;
|
|
40
|
+
|
|
41
|
+
constructor(private readonly syncSummarizerClients: boolean = false) {}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Add a loader to start to track any container created from them
|
|
45
|
+
* @param loader - loader to start tracking any container created.
|
|
46
|
+
*/
|
|
47
|
+
public add<LoaderType extends IHostLoader>(loader: LoaderType) {
|
|
48
|
+
// TODO: Expose Loader API to able to intercept container creation (See issue #5114)
|
|
49
|
+
const patch = <T, C extends IContainer>(fn: (...args) => Promise<C>) => {
|
|
50
|
+
const boundFn = fn.bind(loader);
|
|
51
|
+
return async (...args: T[]) => {
|
|
52
|
+
const container = await boundFn(...args);
|
|
53
|
+
this.addContainer(container);
|
|
54
|
+
return container;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
58
|
+
loader.resolve = patch(loader.resolve);
|
|
59
|
+
loader.createDetachedContainer = patch(loader.createDetachedContainer);
|
|
60
|
+
loader.rehydrateDetachedContainerFromSnapshot = patch(
|
|
61
|
+
loader.rehydrateDetachedContainerFromSnapshot,
|
|
62
|
+
);
|
|
63
|
+
/* eslint-enable @typescript-eslint/unbound-method */
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Utility function to add container to be tracked.
|
|
68
|
+
*
|
|
69
|
+
* @param container - container to add
|
|
70
|
+
*/
|
|
71
|
+
private addContainer(container: IContainer) {
|
|
72
|
+
// ignore summarizer
|
|
73
|
+
if (
|
|
74
|
+
!container.deltaManager.clientDetails.capabilities.interactive &&
|
|
75
|
+
!this.syncSummarizerClients
|
|
76
|
+
) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// don't add container that is already tracked
|
|
81
|
+
if (this.containers.has(container)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const record = {
|
|
86
|
+
index: this.containers.size,
|
|
87
|
+
paused: false,
|
|
88
|
+
startTrailingNoOps: 0,
|
|
89
|
+
trailingNoOps: 0,
|
|
90
|
+
lastProposal: 0,
|
|
91
|
+
};
|
|
92
|
+
this.containers.set(container, record);
|
|
93
|
+
this.trackTrailingNoOps(container, record);
|
|
94
|
+
this.trackLastProposal(container);
|
|
95
|
+
this.setupTrace(container, record.index);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Keep track of the trailing NoOp that was sent so we can discount them in the clientSequenceNumber tracking.
|
|
100
|
+
* The server might coalesce them with other ops, or a single NoOp, or delay it if it don't think it is necessary.
|
|
101
|
+
*
|
|
102
|
+
* @param container - the container to track
|
|
103
|
+
* @param record - the record to update the trailing op information
|
|
104
|
+
*/
|
|
105
|
+
private trackTrailingNoOps(container: IContainer, record: ContainerRecord) {
|
|
106
|
+
container.deltaManager.outbound.on("op", (messages) => {
|
|
107
|
+
for (const msg of messages) {
|
|
108
|
+
if (canBeCoalescedByService(msg)) {
|
|
109
|
+
// Track the NoOp that was sent.
|
|
110
|
+
if (record.trailingNoOps === 0) {
|
|
111
|
+
// record the starting sequence number of the trailing no ops if we haven't been tracking yet.
|
|
112
|
+
record.startTrailingNoOps = msg.clientSequenceNumber;
|
|
113
|
+
}
|
|
114
|
+
record.trailingNoOps++;
|
|
115
|
+
} else {
|
|
116
|
+
// Other ops has been sent. We would like to see those ack'ed, so no more need to track NoOps
|
|
117
|
+
record.trailingNoOps = 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
container.deltaManager.inbound.on("push", (message) => {
|
|
123
|
+
// Received the no op back, update the record if we are tracking
|
|
124
|
+
if (
|
|
125
|
+
canBeCoalescedByService(message) &&
|
|
126
|
+
message.clientId === (container as Container).clientId &&
|
|
127
|
+
record.trailingNoOps !== 0 &&
|
|
128
|
+
record.startTrailingNoOps <= message.clientSequenceNumber
|
|
129
|
+
) {
|
|
130
|
+
// NoOp might have coalesced and skipped ahead some sequence number
|
|
131
|
+
// update the record and skip ahead as well
|
|
132
|
+
const oldStartTrailingNoOps = record.startTrailingNoOps;
|
|
133
|
+
record.startTrailingNoOps = message.clientSequenceNumber + 1;
|
|
134
|
+
record.trailingNoOps -= record.startTrailingNoOps - oldStartTrailingNoOps;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
container.on("disconnected", () => {
|
|
139
|
+
// reset on disconnect.
|
|
140
|
+
record.trailingNoOps = 0;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private trackLastProposal(container: IContainer) {
|
|
145
|
+
container.on("codeDetailsProposed", (value, proposal) => {
|
|
146
|
+
if (proposal.sequenceNumber > this.lastProposalSeqNum) {
|
|
147
|
+
this.lastProposalSeqNum = proposal.sequenceNumber;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Reset the tracker, closing all containers and stop tracking them.
|
|
154
|
+
*/
|
|
155
|
+
public reset() {
|
|
156
|
+
this.lastProposalSeqNum = 0;
|
|
157
|
+
for (const container of this.containers.keys()) {
|
|
158
|
+
container.close();
|
|
159
|
+
}
|
|
160
|
+
this.containers.clear();
|
|
161
|
+
|
|
162
|
+
// REVIEW: do we need to unpatch the loaders?
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Ensure all tracked containers are synchronized
|
|
167
|
+
*/
|
|
168
|
+
public async ensureSynchronized(...containers: IContainer[]): Promise<void> {
|
|
169
|
+
await this.processSynchronized(undefined, ...containers);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Ensure all tracked containers are synchronized with a time limit
|
|
174
|
+
*/
|
|
175
|
+
public async ensureSynchronizedWithTimeout?(
|
|
176
|
+
timeoutDuration: number | undefined,
|
|
177
|
+
...containers: IContainer[]
|
|
178
|
+
) {
|
|
179
|
+
await this.processSynchronized(timeoutDuration, ...containers);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Make sure all the tracked containers are synchronized.
|
|
184
|
+
*
|
|
185
|
+
* No isDirty (non-readonly) containers
|
|
186
|
+
*
|
|
187
|
+
* No extra clientId in quorum of any container that is not tracked and still opened.
|
|
188
|
+
*
|
|
189
|
+
* - i.e. no pending Join/Leave message.
|
|
190
|
+
*
|
|
191
|
+
* No unresolved proposal (minSeqNum \>= lastProposalSeqNum)
|
|
192
|
+
*
|
|
193
|
+
* lastSequenceNumber of all container is the same
|
|
194
|
+
*
|
|
195
|
+
* clientSequenceNumberObserved is the same as clientSequenceNumber sent
|
|
196
|
+
*
|
|
197
|
+
* - this overlaps with !isDirty, but include task scheduler ops.
|
|
198
|
+
*
|
|
199
|
+
* - Trailing NoOp is tracked and don't count as pending ops.
|
|
200
|
+
*/
|
|
201
|
+
private async processSynchronized(
|
|
202
|
+
timeoutDuration: number | undefined,
|
|
203
|
+
...containers: IContainer[]
|
|
204
|
+
) {
|
|
205
|
+
const resumed = this.resumeProcessing(...containers);
|
|
206
|
+
|
|
207
|
+
let waitingSequenceNumberSynchronized = false;
|
|
208
|
+
// eslint-disable-next-line no-constant-condition
|
|
209
|
+
while (true) {
|
|
210
|
+
const containersToApply = this.getContainers(containers);
|
|
211
|
+
if (containersToApply.length === 0) {
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Ignore readonly dirty containers, because it can't sent up and nothing can be done about it being dirty
|
|
216
|
+
const dirtyContainers = containersToApply.filter((c) => {
|
|
217
|
+
const { deltaManager, isDirty } = c;
|
|
218
|
+
return deltaManager.readOnlyInfo.readonly !== true && isDirty;
|
|
219
|
+
});
|
|
220
|
+
if (dirtyContainers.length === 0) {
|
|
221
|
+
// Wait for all the leave messages
|
|
222
|
+
const pendingClients = this.getPendingClients(containersToApply);
|
|
223
|
+
if (pendingClients.length === 0) {
|
|
224
|
+
if (this.isSequenceNumberSynchronized(containersToApply)) {
|
|
225
|
+
// done, we are in sync
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
if (!waitingSequenceNumberSynchronized) {
|
|
229
|
+
// Only write it out once
|
|
230
|
+
waitingSequenceNumberSynchronized = true;
|
|
231
|
+
debugWait("Waiting for sequence number synchronized");
|
|
232
|
+
await timeoutAwait(this.waitForAnyInboundOps(containersToApply), {
|
|
233
|
+
errorMsg: "Timeout on waiting for sequence number synchronized",
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
waitingSequenceNumberSynchronized = false;
|
|
238
|
+
await timeoutAwait(this.waitForPendingClients(pendingClients), {
|
|
239
|
+
errorMsg: "Timeout on waiting for pending join or leave op",
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
// Wait for all the containers to be saved
|
|
244
|
+
debugWait(
|
|
245
|
+
`Waiting container to be saved ${dirtyContainers.map(
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
247
|
+
(c) => this.containers.get(c)!.index,
|
|
248
|
+
)}`,
|
|
249
|
+
);
|
|
250
|
+
waitingSequenceNumberSynchronized = false;
|
|
251
|
+
await Promise.all(
|
|
252
|
+
dirtyContainers.map(async (c) =>
|
|
253
|
+
Promise.race([
|
|
254
|
+
timeoutPromise((resolve) => c.once("saved", () => resolve()), {
|
|
255
|
+
errorMsg: "Timeout on waiting a container to be saved",
|
|
256
|
+
}),
|
|
257
|
+
new Promise((resolve) => c.once("closed", resolve)),
|
|
258
|
+
]),
|
|
259
|
+
),
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// yield a turn to allow side effect of the ops we just processed execute before we check again
|
|
264
|
+
await new Promise<void>((resolve) => {
|
|
265
|
+
setTimeout(resolve, 0);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Pause all container that was resumed
|
|
270
|
+
// don't call pause if resumed is empty and pause everything, which is not what we want
|
|
271
|
+
if (resumed.length !== 0) {
|
|
272
|
+
await timeoutAwait(this.pauseProcessing(...resumed), {
|
|
273
|
+
errorMsg: "Timeout on waiting for pausing all resumed containers",
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
debugWait("Synchronized");
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Utility to calculate the set of clientId per container in quorum that is NOT associated with
|
|
282
|
+
* any container we tracked, indicating there is a pending join or leave op that we need to wait.
|
|
283
|
+
*
|
|
284
|
+
* @param containersToApply - the set of containers to check
|
|
285
|
+
*/
|
|
286
|
+
private getPendingClients(containersToApply: IContainer[]) {
|
|
287
|
+
// All the clientId we track should be a superset of the quorum, otherwise, we are missing
|
|
288
|
+
// leave messages
|
|
289
|
+
const openedDocuments = Array.from(this.containers.keys()).filter((c) => !c.closed);
|
|
290
|
+
const openedClientId = openedDocuments.map(
|
|
291
|
+
(container) => (container as Container).clientId,
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const pendingClients: [IContainer, Set<string>][] = [];
|
|
295
|
+
containersToApply.forEach((container) => {
|
|
296
|
+
const pendingClientId = new Set<string>();
|
|
297
|
+
const quorum = container.getQuorum();
|
|
298
|
+
quorum.getMembers().forEach((client, clientId) => {
|
|
299
|
+
// ignore summarizer
|
|
300
|
+
if (
|
|
301
|
+
!client.client.details.capabilities.interactive &&
|
|
302
|
+
!this.syncSummarizerClients
|
|
303
|
+
) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (!openedClientId.includes(clientId)) {
|
|
307
|
+
pendingClientId.add(clientId);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
if (pendingClientId.size !== 0) {
|
|
312
|
+
pendingClients.push([container, pendingClientId]);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
return pendingClients;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Utility to check synchronization based on sequence number
|
|
320
|
+
* See ensureSynchronized for more detail
|
|
321
|
+
*
|
|
322
|
+
* @param containersToApply - the set of containers to check
|
|
323
|
+
*/
|
|
324
|
+
private isSequenceNumberSynchronized(containersToApply: IContainer[]) {
|
|
325
|
+
// clientSequenceNumber check detects ops in flight, both on the wire and in the outbound queue
|
|
326
|
+
// We need both client sequence number and isDirty check because:
|
|
327
|
+
// - Currently isDirty flag ignores ops for task scheduler, so we need the client sequence number check
|
|
328
|
+
// - But isDirty flags include ops during forceReadonly and disconnected, because we don't submit
|
|
329
|
+
// the ops in the first place, clientSequenceNumber is not assigned
|
|
330
|
+
|
|
331
|
+
const isClientSequenceNumberSynchronized = containersToApply.every((container) => {
|
|
332
|
+
if (container.deltaManager.readOnlyInfo.readonly === true) {
|
|
333
|
+
// Ignore readonly container. the clientSeqNum and clientSeqNumObserved might be out of sync
|
|
334
|
+
// because we transition to readonly when outbound is not empty or the in transit op got lost
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
// Note that in read only mode, the op won't be submitted
|
|
338
|
+
let deltaManager = container.deltaManager as any;
|
|
339
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
340
|
+
const { trailingNoOps } = this.containers.get(container)!;
|
|
341
|
+
// Back-compat: clientSequenceNumber & clientSequenceNumberObserved moved to ConnectionManager in 0.53
|
|
342
|
+
if (!("clientSequenceNumber" in deltaManager)) {
|
|
343
|
+
deltaManager = deltaManager.connectionManager;
|
|
344
|
+
}
|
|
345
|
+
assert("clientSequenceNumber" in deltaManager, "no clientSequenceNumber");
|
|
346
|
+
assert("clientSequenceNumberObserved" in deltaManager, "no clientSequenceNumber");
|
|
347
|
+
return (
|
|
348
|
+
deltaManager.clientSequenceNumber ===
|
|
349
|
+
(deltaManager.clientSequenceNumberObserved as number) + trailingNoOps
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
if (!isClientSequenceNumberSynchronized) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const minSeqNum = containersToApply[0].deltaManager.minimumSequenceNumber;
|
|
358
|
+
if (minSeqNum < this.lastProposalSeqNum) {
|
|
359
|
+
// There is an unresolved proposal
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Check to see if all the container has process the same number of ops.
|
|
364
|
+
const seqNum = containersToApply[0].deltaManager.lastSequenceNumber;
|
|
365
|
+
return containersToApply.every((c) => c.deltaManager.lastSequenceNumber === seqNum);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Utility to wait for any clientId in quorum that is NOT associated with any container we
|
|
370
|
+
* tracked, indicating there is a pending join or leave op that we need to wait.
|
|
371
|
+
*
|
|
372
|
+
* Note that this function doesn't account for container that got added after we started waiting
|
|
373
|
+
*
|
|
374
|
+
* @param containersToApply - the set of containers to wait for any inbound ops for
|
|
375
|
+
*/
|
|
376
|
+
private async waitForPendingClients(pendingClients: [IContainer, Set<string>][]) {
|
|
377
|
+
const unconnectedClients = Array.from(this.containers.keys()).filter(
|
|
378
|
+
(c) => !c.closed && !(c as Container).connected,
|
|
379
|
+
);
|
|
380
|
+
return Promise.all(
|
|
381
|
+
pendingClients.map(async ([container, pendingClientId]) => {
|
|
382
|
+
return new Promise<void>((resolve) => {
|
|
383
|
+
const cleanup = () => {
|
|
384
|
+
unconnectedClients.forEach((c) => c.off("connected", handler));
|
|
385
|
+
container.getQuorum().off("removeMember", handler);
|
|
386
|
+
};
|
|
387
|
+
const handler = (clientId: string) => {
|
|
388
|
+
pendingClientId.delete(clientId);
|
|
389
|
+
if (pendingClientId.size === 0) {
|
|
390
|
+
cleanup();
|
|
391
|
+
resolve();
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
395
|
+
const index = this.containers.get(container)!.index;
|
|
396
|
+
debugWait(
|
|
397
|
+
`${index}: Waiting for pending clients ${Array.from(
|
|
398
|
+
pendingClientId.keys(),
|
|
399
|
+
)}`,
|
|
400
|
+
);
|
|
401
|
+
unconnectedClients.forEach((c) => c.on("connected", handler));
|
|
402
|
+
container.getQuorum().on("removeMember", handler);
|
|
403
|
+
container.on("closed", () => {
|
|
404
|
+
cleanup();
|
|
405
|
+
resolve();
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
}),
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Utility to wait for any inbound ops from a set of containers
|
|
414
|
+
* @param containersToApply - the set of containers to wait for any inbound ops for
|
|
415
|
+
*/
|
|
416
|
+
private async waitForAnyInboundOps(containersToApply: IContainer[]) {
|
|
417
|
+
return new Promise<void>((resolve) => {
|
|
418
|
+
const handler = () => {
|
|
419
|
+
containersToApply.map((c) => {
|
|
420
|
+
c.deltaManager.inbound.off("push", handler);
|
|
421
|
+
});
|
|
422
|
+
resolve();
|
|
423
|
+
};
|
|
424
|
+
containersToApply.map((c) => {
|
|
425
|
+
c.deltaManager.inbound.on("push", handler);
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Resume all queue activities on all paused tracked containers and return them
|
|
432
|
+
*/
|
|
433
|
+
public resumeProcessing(...containers: IContainer[]) {
|
|
434
|
+
const resumed: IContainer[] = [];
|
|
435
|
+
const containersToApply = this.getContainers(containers);
|
|
436
|
+
for (const container of containersToApply) {
|
|
437
|
+
const record = this.containers.get(container);
|
|
438
|
+
if (record?.paused === true) {
|
|
439
|
+
debugWait(`${record.index}: container resumed`);
|
|
440
|
+
container.deltaManager.inbound.resume();
|
|
441
|
+
container.deltaManager.outbound.resume();
|
|
442
|
+
resumed.push(container);
|
|
443
|
+
record.paused = false;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return resumed;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Pause all queue activities on the containers given, or all tracked containers
|
|
451
|
+
* Any containers given that is not tracked will be ignored.
|
|
452
|
+
*/
|
|
453
|
+
public async pauseProcessing(...containers: IContainer[]) {
|
|
454
|
+
const pauseP: Promise<void>[] = [];
|
|
455
|
+
const containersToApply = this.getContainers(containers);
|
|
456
|
+
for (const container of containersToApply) {
|
|
457
|
+
const record = this.containers.get(container);
|
|
458
|
+
if (record !== undefined && !record.paused) {
|
|
459
|
+
debugWait(`${record.index}: container paused`);
|
|
460
|
+
pauseP.push(container.deltaManager.inbound.pause());
|
|
461
|
+
pauseP.push(container.deltaManager.outbound.pause());
|
|
462
|
+
record.paused = true;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
await Promise.all(pauseP);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Pause all queue activities on all tracked containers, and resume only
|
|
470
|
+
* inbound to process ops until it is idle. All queues are left in the paused state
|
|
471
|
+
* after the function
|
|
472
|
+
*/
|
|
473
|
+
public async processIncoming(...containers: IContainer[]) {
|
|
474
|
+
return this.processQueue(containers, (container) => container.deltaManager.inbound);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Pause all queue activities on all tracked containers, and resume only
|
|
479
|
+
* outbound to process ops until it is idle. All queues are left in the paused state
|
|
480
|
+
* after the function
|
|
481
|
+
*/
|
|
482
|
+
public async processOutgoing(...containers: IContainer[]) {
|
|
483
|
+
return this.processQueue(containers, (container) => container.deltaManager.outbound);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Implementation of processIncoming and processOutgoing
|
|
488
|
+
*/
|
|
489
|
+
private async processQueue<U>(
|
|
490
|
+
containers: IContainer[],
|
|
491
|
+
getQueue: (container: IContainer) => IDeltaQueue<U>,
|
|
492
|
+
) {
|
|
493
|
+
await this.pauseProcessing(...containers);
|
|
494
|
+
const resumed: IDeltaQueue<U>[] = [];
|
|
495
|
+
|
|
496
|
+
const containersToApply = this.getContainers(containers);
|
|
497
|
+
const inflightTracker = new Map<IContainer, number>();
|
|
498
|
+
const cleanup: (() => void)[] = [];
|
|
499
|
+
for (const container of containersToApply) {
|
|
500
|
+
const queue = getQueue(container);
|
|
501
|
+
|
|
502
|
+
// track the outgoing ops (if any) to make sure they make the round trip to at least to the same client
|
|
503
|
+
// to make sure they are sequenced.
|
|
504
|
+
cleanup.push(this.setupInOutTracker(container, inflightTracker));
|
|
505
|
+
queue.resume();
|
|
506
|
+
resumed.push(queue);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
while (resumed.some((queue) => !queue.idle)) {
|
|
510
|
+
debugWait("Wait until queue is idle");
|
|
511
|
+
await new Promise<void>((resolve) => {
|
|
512
|
+
setTimeout(resolve, 0);
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// Make sure all the op that we sent out are acked first
|
|
517
|
+
// This is no op if we are processing incoming
|
|
518
|
+
if (inflightTracker.size) {
|
|
519
|
+
debugWait("Wait for inflight ops");
|
|
520
|
+
do {
|
|
521
|
+
await this.waitForAnyInboundOps(containersToApply);
|
|
522
|
+
} while (inflightTracker.size);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// remove the handlers
|
|
526
|
+
cleanup.forEach((clean) => clean());
|
|
527
|
+
|
|
528
|
+
await Promise.all(resumed.map(async (queue) => queue.pause()));
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Utility to set up listener to track the outbound ops until it round trip back
|
|
533
|
+
* Returns a function to remove the handler after it is done.
|
|
534
|
+
*
|
|
535
|
+
* @param container - the container to setup
|
|
536
|
+
* @param inflightTracker - a map to track the clientSequenceNumber per container it expect to get ops back
|
|
537
|
+
*/
|
|
538
|
+
private setupInOutTracker(container: IContainer, inflightTracker: Map<IContainer, number>) {
|
|
539
|
+
const outHandler = (messages: IDocumentMessage[]) => {
|
|
540
|
+
for (const message of messages) {
|
|
541
|
+
if (!canBeCoalescedByService(message)) {
|
|
542
|
+
inflightTracker.set(container, message.clientSequenceNumber);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
const inHandler = (message: ISequencedDocumentMessage) => {
|
|
547
|
+
if (
|
|
548
|
+
!canBeCoalescedByService(message) &&
|
|
549
|
+
message.clientId === (container as Container).clientId &&
|
|
550
|
+
inflightTracker.get(container) === message.clientSequenceNumber
|
|
551
|
+
) {
|
|
552
|
+
inflightTracker.delete(container);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
container.deltaManager.outbound.on("op", outHandler);
|
|
557
|
+
container.deltaManager.inbound.on("push", inHandler);
|
|
558
|
+
|
|
559
|
+
return () => {
|
|
560
|
+
container.deltaManager.outbound.off("op", outHandler);
|
|
561
|
+
container.deltaManager.inbound.off("push", inHandler);
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Setup debug traces for connection and ops
|
|
567
|
+
*/
|
|
568
|
+
private setupTrace(container: IContainer, index: number) {
|
|
569
|
+
if (debugOp.enabled) {
|
|
570
|
+
const getContentsString = (type: string, msgContents: any) => {
|
|
571
|
+
try {
|
|
572
|
+
if (type !== MessageType.Operation) {
|
|
573
|
+
if (typeof msgContents === "string") {
|
|
574
|
+
return msgContents;
|
|
575
|
+
}
|
|
576
|
+
return JSON.stringify(msgContents);
|
|
577
|
+
}
|
|
578
|
+
let address = "";
|
|
579
|
+
|
|
580
|
+
// contents comes in the wire as JSON string ("push" event)
|
|
581
|
+
// But already parsed when apply ("op" event)
|
|
582
|
+
let contents =
|
|
583
|
+
typeof msgContents === "string" ? JSON.parse(msgContents) : msgContents;
|
|
584
|
+
while (contents !== undefined && contents !== null) {
|
|
585
|
+
if (contents.contents?.address !== undefined) {
|
|
586
|
+
address += `/${contents.contents.address}`;
|
|
587
|
+
contents = contents.contents.contents;
|
|
588
|
+
} else if (contents.content?.address !== undefined) {
|
|
589
|
+
address += `/${contents.content.address}`;
|
|
590
|
+
contents = contents.content.contents;
|
|
591
|
+
} else {
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
if (address) {
|
|
596
|
+
return `${address} ${JSON.stringify(contents)}`;
|
|
597
|
+
}
|
|
598
|
+
return JSON.stringify(contents);
|
|
599
|
+
} catch (e: any) {
|
|
600
|
+
return `${e.message}: ${e.stack}`;
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
debugOp(`${index}: ADD: clientId: ${(container as Container).clientId}`);
|
|
604
|
+
container.deltaManager.outbound.on("op", (messages) => {
|
|
605
|
+
for (const msg of messages) {
|
|
606
|
+
debugOp(
|
|
607
|
+
`${index}: OUT: ` +
|
|
608
|
+
`cli: ${msg.clientSequenceNumber.toString().padStart(3)} ` +
|
|
609
|
+
`rsq: ${msg.referenceSequenceNumber.toString().padStart(3)} ` +
|
|
610
|
+
`${msg.type} ${getContentsString(msg.type, msg.contents)}`,
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
const getInboundHandler = (type: string) => {
|
|
615
|
+
return (msg: ISequencedDocumentMessage) => {
|
|
616
|
+
const clientSeq =
|
|
617
|
+
msg.clientId === (container as Container).clientId
|
|
618
|
+
? `cli: ${msg.clientSequenceNumber.toString().padStart(3)}`
|
|
619
|
+
: " ";
|
|
620
|
+
debugOp(
|
|
621
|
+
`${index}: ${type}: seq: ${msg.sequenceNumber.toString().padStart(3)} ` +
|
|
622
|
+
`${clientSeq} min: ${msg.minimumSequenceNumber
|
|
623
|
+
.toString()
|
|
624
|
+
.padStart(3)} ` +
|
|
625
|
+
`${msg.type} ${getContentsString(msg.type, msg.contents)}`,
|
|
626
|
+
);
|
|
627
|
+
};
|
|
628
|
+
};
|
|
629
|
+
container.deltaManager.inbound.on("push", getInboundHandler("IN "));
|
|
630
|
+
container.deltaManager.inbound.on("op", getInboundHandler("OP "));
|
|
631
|
+
container.deltaManager.on("connect", (details) => {
|
|
632
|
+
debugOp(`${index}: CON: clientId: ${details.clientId}`);
|
|
633
|
+
});
|
|
634
|
+
container.deltaManager.on("disconnect", (reason) => {
|
|
635
|
+
debugOp(`${index}: DIS: ${reason}`);
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Filter out the opened containers based on param.
|
|
642
|
+
* @param containers - The container to filter to. If the array is empty, it means don't filter and return
|
|
643
|
+
* all open containers.
|
|
644
|
+
*/
|
|
645
|
+
private getContainers(containers: IContainer[]) {
|
|
646
|
+
const containersToApply =
|
|
647
|
+
containers.length === 0 ? Array.from(this.containers.keys()) : containers;
|
|
648
|
+
return containersToApply.filter((container) => !container.closed);
|
|
649
|
+
}
|
|
588
650
|
}
|