cojson 0.13.27 → 0.13.28
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/coValueCore/coValueCore.d.ts +4 -3
- package/dist/coValueCore/coValueCore.d.ts.map +1 -1
- package/dist/coValueCore/coValueCore.js +82 -66
- package/dist/coValueCore/coValueCore.js.map +1 -1
- package/dist/sync.d.ts +6 -6
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +100 -66
- package/dist/sync.js.map +1 -1
- package/dist/tests/SyncStateManager.test.js +1 -1
- package/dist/tests/SyncStateManager.test.js.map +1 -1
- package/dist/tests/sync.mesh.test.js +47 -3
- package/dist/tests/sync.mesh.test.js.map +1 -1
- package/dist/tests/sync.peerReconciliation.test.js +71 -2
- package/dist/tests/sync.peerReconciliation.test.js.map +1 -1
- package/dist/tests/testUtils.d.ts.map +1 -1
- package/dist/tests/testUtils.js +1 -0
- package/dist/tests/testUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/coValueCore/coValueCore.ts +111 -80
- package/src/sync.ts +117 -71
- package/src/tests/SyncStateManager.test.ts +1 -1
- package/src/tests/sync.mesh.test.ts +60 -2
- package/src/tests/sync.peerReconciliation.test.ts +90 -2
- package/src/tests/testUtils.ts +1 -0
package/src/sync.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { RawCoID, SessionID } from "./ids.js";
|
|
|
11
11
|
import { LocalNode } from "./localNode.js";
|
|
12
12
|
import { logger } from "./logger.js";
|
|
13
13
|
import { CoValuePriority } from "./priority.js";
|
|
14
|
+
import { accountOrAgentIDfromSessionID } from "./typeUtils/accountOrAgentIDfromSessionID.js";
|
|
15
|
+
import { isAccountID } from "./typeUtils/isAccountID.js";
|
|
14
16
|
|
|
15
17
|
export type CoValueKnownState = {
|
|
16
18
|
id: RawCoID;
|
|
@@ -211,9 +213,9 @@ export class SyncManager {
|
|
|
211
213
|
return;
|
|
212
214
|
}
|
|
213
215
|
|
|
214
|
-
coValue
|
|
215
|
-
.
|
|
216
|
-
|
|
216
|
+
for (const dependency of coValue.getDependedOnCoValues()) {
|
|
217
|
+
this.sendNewContentIncludingDependencies(dependency, peer);
|
|
218
|
+
}
|
|
217
219
|
|
|
218
220
|
const newContentPieces = coValue.verified.newContentSince(
|
|
219
221
|
peer.optimisticKnownStates.get(id),
|
|
@@ -298,7 +300,7 @@ export class SyncManager {
|
|
|
298
300
|
}
|
|
299
301
|
}
|
|
300
302
|
|
|
301
|
-
|
|
303
|
+
addPeer(peer: Peer) {
|
|
302
304
|
const prevPeer = this.peers[peer.id];
|
|
303
305
|
|
|
304
306
|
if (prevPeer && !prevPeer.closed) {
|
|
@@ -379,65 +381,17 @@ export class SyncManager {
|
|
|
379
381
|
peer.setKnownState(msg.id, knownStateIn(msg));
|
|
380
382
|
const coValue = this.local.getCoValue(msg.id);
|
|
381
383
|
|
|
382
|
-
if (
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
) {
|
|
386
|
-
const eligiblePeers = this.getServerAndStoragePeers(peer.id);
|
|
387
|
-
|
|
388
|
-
if (eligiblePeers.length === 0) {
|
|
389
|
-
// We don't have any eligible peers to load the coValue from
|
|
390
|
-
// so we send a known state back to the sender to let it know
|
|
391
|
-
// that the coValue is unavailable
|
|
392
|
-
peer.trackToldKnownState(msg.id);
|
|
393
|
-
this.trySendToPeer(peer, {
|
|
394
|
-
action: "known",
|
|
395
|
-
id: msg.id,
|
|
396
|
-
header: false,
|
|
397
|
-
sessions: {},
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
return;
|
|
401
|
-
} else {
|
|
402
|
-
// Syncronously updates the state loading is possible
|
|
403
|
-
coValue
|
|
404
|
-
.loadFromPeers(this.getServerAndStoragePeers(peer.id))
|
|
405
|
-
.catch((e) => {
|
|
406
|
-
logger.error("Error loading coValue in handleLoad", { err: e });
|
|
407
|
-
});
|
|
408
|
-
}
|
|
384
|
+
if (coValue.isAvailable()) {
|
|
385
|
+
this.sendNewContentIncludingDependencies(msg.id, peer);
|
|
386
|
+
return;
|
|
409
387
|
}
|
|
410
388
|
|
|
411
|
-
|
|
412
|
-
// We need to return from handleLoad immediately and wait for the CoValue to be loaded
|
|
413
|
-
// in a new task, otherwise we might block further incoming content messages that would
|
|
414
|
-
// resolve the CoValue as available. This can happen when we receive fresh
|
|
415
|
-
// content from a client, but we are a server with our own upstream server(s)
|
|
416
|
-
coValue
|
|
417
|
-
.waitForAvailableOrUnavailable()
|
|
418
|
-
.then(async (value) => {
|
|
419
|
-
if (!value.isAvailable()) {
|
|
420
|
-
peer.trackToldKnownState(msg.id);
|
|
421
|
-
this.trySendToPeer(peer, {
|
|
422
|
-
action: "known",
|
|
423
|
-
id: msg.id,
|
|
424
|
-
header: false,
|
|
425
|
-
sessions: {},
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
389
|
+
const eligiblePeers = this.getServerAndStoragePeers(peer.id);
|
|
430
390
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
err: e,
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
} else if (coValue.isAvailable()) {
|
|
439
|
-
this.sendNewContentIncludingDependencies(msg.id, peer);
|
|
440
|
-
} else {
|
|
391
|
+
if (eligiblePeers.length === 0) {
|
|
392
|
+
// We don't have any eligible peers to load the coValue from
|
|
393
|
+
// so we send a known state back to the sender to let it know
|
|
394
|
+
// that the coValue is unavailable
|
|
441
395
|
peer.trackToldKnownState(msg.id);
|
|
442
396
|
this.trySendToPeer(peer, {
|
|
443
397
|
action: "known",
|
|
@@ -445,9 +399,41 @@ export class SyncManager {
|
|
|
445
399
|
header: false,
|
|
446
400
|
sessions: {},
|
|
447
401
|
});
|
|
402
|
+
|
|
403
|
+
return;
|
|
448
404
|
}
|
|
449
|
-
}
|
|
450
405
|
|
|
406
|
+
coValue.loadFromPeers(eligiblePeers).catch((e) => {
|
|
407
|
+
logger.error("Error loading coValue in handleLoad", { err: e });
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// We need to return from handleLoad immediately and wait for the CoValue to be loaded
|
|
411
|
+
// in a new task, otherwise we might block further incoming content messages that would
|
|
412
|
+
// resolve the CoValue as available. This can happen when we receive fresh
|
|
413
|
+
// content from a client, but we are a server with our own upstream server(s)
|
|
414
|
+
coValue
|
|
415
|
+
.waitForAvailableOrUnavailable()
|
|
416
|
+
.then((value) => {
|
|
417
|
+
if (!value.isAvailable()) {
|
|
418
|
+
peer.trackToldKnownState(msg.id);
|
|
419
|
+
this.trySendToPeer(peer, {
|
|
420
|
+
action: "known",
|
|
421
|
+
id: msg.id,
|
|
422
|
+
header: false,
|
|
423
|
+
sessions: {},
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
this.sendNewContentIncludingDependencies(msg.id, peer);
|
|
430
|
+
})
|
|
431
|
+
.catch((e) => {
|
|
432
|
+
logger.error("Error loading coValue in handleLoad loading state", {
|
|
433
|
+
err: e,
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
}
|
|
451
437
|
handleKnownState(msg: KnownStateMessage, peer: PeerState) {
|
|
452
438
|
const coValue = this.local.getCoValue(msg.id);
|
|
453
439
|
|
|
@@ -494,6 +480,52 @@ export class SyncManager {
|
|
|
494
480
|
return;
|
|
495
481
|
}
|
|
496
482
|
|
|
483
|
+
let dependencyMissing = false;
|
|
484
|
+
const sessionIDs = Object.keys(msg.new) as SessionID[];
|
|
485
|
+
for (const dependency of coValue.getDependedOnCoValuesFromHeaderAndSessions(
|
|
486
|
+
msg.header,
|
|
487
|
+
sessionIDs,
|
|
488
|
+
)) {
|
|
489
|
+
const dependencyCoValue = this.local.getCoValue(dependency);
|
|
490
|
+
|
|
491
|
+
if (!dependencyCoValue.isAvailable()) {
|
|
492
|
+
if (peer.role !== "storage") {
|
|
493
|
+
this.trySendToPeer(peer, {
|
|
494
|
+
action: "load",
|
|
495
|
+
id: dependency,
|
|
496
|
+
header: false,
|
|
497
|
+
sessions: {},
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
dependencyMissing = true;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
if (dependencyMissing) {
|
|
506
|
+
if (peer.role !== "storage") {
|
|
507
|
+
/**
|
|
508
|
+
* If we have missing dependencies, we send a known state message to the peer
|
|
509
|
+
* to let it know that we need a correction update.
|
|
510
|
+
*
|
|
511
|
+
* Sync-wise is sub-optimal, but it gives us correctness until
|
|
512
|
+
* https://github.com/garden-co/jazz/issues/1917 is implemented.
|
|
513
|
+
*/
|
|
514
|
+
this.trySendToPeer(peer, {
|
|
515
|
+
action: "known",
|
|
516
|
+
isCorrection: true,
|
|
517
|
+
id: msg.id,
|
|
518
|
+
header: false,
|
|
519
|
+
sessions: {},
|
|
520
|
+
});
|
|
521
|
+
} else {
|
|
522
|
+
/** Cases of broken deps from storage are recovered by falling back to the server peers */
|
|
523
|
+
coValue.loadFromPeers(this.getServerAndStoragePeers(peer.id));
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
|
|
497
529
|
peer.updateHeader(msg.id, true);
|
|
498
530
|
coValue.markAvailable(msg.header, peer.id);
|
|
499
531
|
}
|
|
@@ -528,6 +560,18 @@ export class SyncManager {
|
|
|
528
560
|
continue;
|
|
529
561
|
}
|
|
530
562
|
|
|
563
|
+
const accountId = accountOrAgentIDfromSessionID(sessionID);
|
|
564
|
+
|
|
565
|
+
if (isAccountID(accountId)) {
|
|
566
|
+
const account = this.local.getCoValue(accountId);
|
|
567
|
+
|
|
568
|
+
if (!account.isAvailable()) {
|
|
569
|
+
account.loadFromPeers([peer]);
|
|
570
|
+
invalidStateAssumed = true;
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
531
575
|
const result = coValue.tryAddTransactions(
|
|
532
576
|
sessionID,
|
|
533
577
|
newTransactions,
|
|
@@ -607,6 +651,8 @@ export class SyncManager {
|
|
|
607
651
|
// Check if there is a inflight load operation and we
|
|
608
652
|
// are waiting for other peers to send the load request
|
|
609
653
|
if (state === "unknown" || state === undefined) {
|
|
654
|
+
// Sending a load message to the peer to get to know how much content is missing
|
|
655
|
+
// before sending the new content
|
|
610
656
|
this.trySendToPeer(peer, {
|
|
611
657
|
action: "load",
|
|
612
658
|
...coValue.knownState(),
|
|
@@ -645,7 +691,7 @@ export class SyncManager {
|
|
|
645
691
|
this.requestedSyncs.add(coValue.id);
|
|
646
692
|
}
|
|
647
693
|
|
|
648
|
-
|
|
694
|
+
syncCoValue(coValue: CoValueCore) {
|
|
649
695
|
this.requestedSyncs.delete(coValue.id);
|
|
650
696
|
|
|
651
697
|
for (const peer of this.peersInPriorityOrder()) {
|
|
@@ -668,21 +714,21 @@ export class SyncManager {
|
|
|
668
714
|
}
|
|
669
715
|
}
|
|
670
716
|
|
|
671
|
-
|
|
717
|
+
waitForSyncWithPeer(peerId: PeerID, id: RawCoID, timeout: number) {
|
|
672
718
|
const { syncState } = this;
|
|
673
719
|
const currentSyncState = syncState.getCurrentSyncState(peerId, id);
|
|
674
720
|
|
|
675
721
|
const isTheConditionAlreadyMet = currentSyncState.uploaded;
|
|
676
722
|
|
|
677
723
|
if (isTheConditionAlreadyMet) {
|
|
678
|
-
return
|
|
724
|
+
return;
|
|
679
725
|
}
|
|
680
726
|
|
|
681
727
|
const peerState = this.peers[peerId];
|
|
682
728
|
|
|
683
729
|
// The peer has been closed, so it isn't possible to sync
|
|
684
730
|
if (!peerState || peerState.closed) {
|
|
685
|
-
return
|
|
731
|
+
return;
|
|
686
732
|
}
|
|
687
733
|
|
|
688
734
|
// The client isn't subscribed to the coValue, so we won't sync it
|
|
@@ -690,7 +736,7 @@ export class SyncManager {
|
|
|
690
736
|
peerState.role === "client" &&
|
|
691
737
|
!peerState.optimisticKnownStates.has(id)
|
|
692
738
|
) {
|
|
693
|
-
return
|
|
739
|
+
return;
|
|
694
740
|
}
|
|
695
741
|
|
|
696
742
|
return new Promise((resolve, reject) => {
|
|
@@ -712,25 +758,25 @@ export class SyncManager {
|
|
|
712
758
|
});
|
|
713
759
|
}
|
|
714
760
|
|
|
715
|
-
|
|
761
|
+
waitForStorageSync(id: RawCoID, timeout = 30_000) {
|
|
716
762
|
const peers = this.getPeers();
|
|
717
763
|
|
|
718
|
-
|
|
764
|
+
return Promise.all(
|
|
719
765
|
peers
|
|
720
766
|
.filter((peer) => peer.role === "storage")
|
|
721
767
|
.map((peer) => this.waitForSyncWithPeer(peer.id, id, timeout)),
|
|
722
768
|
);
|
|
723
769
|
}
|
|
724
770
|
|
|
725
|
-
|
|
771
|
+
waitForSync(id: RawCoID, timeout = 30_000) {
|
|
726
772
|
const peers = this.getPeers();
|
|
727
773
|
|
|
728
|
-
|
|
774
|
+
return Promise.all(
|
|
729
775
|
peers.map((peer) => this.waitForSyncWithPeer(peer.id, id, timeout)),
|
|
730
776
|
);
|
|
731
777
|
}
|
|
732
778
|
|
|
733
|
-
|
|
779
|
+
waitForAllCoValuesSync(timeout = 60_000) {
|
|
734
780
|
const coValues = this.local.allCoValues();
|
|
735
781
|
const validCoValues = Array.from(coValues).filter(
|
|
736
782
|
(coValue) =>
|
|
@@ -257,7 +257,7 @@ describe("SyncStateManager", () => {
|
|
|
257
257
|
const group = client.node.createGroup();
|
|
258
258
|
const map = group.createMap();
|
|
259
259
|
|
|
260
|
-
await
|
|
260
|
+
await map.core.waitForSync();
|
|
261
261
|
});
|
|
262
262
|
|
|
263
263
|
test("should skip client peers that are not subscribed to the coValue", async () => {
|
|
@@ -4,6 +4,7 @@ import { expectMap } from "../coValue";
|
|
|
4
4
|
import {
|
|
5
5
|
SyncMessagesLog,
|
|
6
6
|
blockMessageTypeOnOutgoingPeer,
|
|
7
|
+
connectedPeersWithMessagesTracking,
|
|
7
8
|
loadCoValueOrFail,
|
|
8
9
|
setupTestNode,
|
|
9
10
|
waitFor,
|
|
@@ -76,8 +77,8 @@ describe("multiple clients syncing with the a cloud-like server mesh", () => {
|
|
|
76
77
|
"core -> storage | CONTENT Group header: true new: After: 0 New: 3",
|
|
77
78
|
"storage -> core | KNOWN Group sessions: header/3",
|
|
78
79
|
"core -> storage | CONTENT Map header: true new: After: 0 New: 1",
|
|
79
|
-
"storage -> core | KNOWN Map sessions: header/1",
|
|
80
80
|
"client -> edge-italy | LOAD Map sessions: empty",
|
|
81
|
+
"storage -> core | KNOWN Map sessions: header/1",
|
|
81
82
|
"edge-italy -> core | LOAD Map sessions: empty",
|
|
82
83
|
"core -> edge-italy | CONTENT Group header: true new: After: 0 New: 3",
|
|
83
84
|
"edge-italy -> core | KNOWN Group sessions: header/3",
|
|
@@ -138,8 +139,8 @@ describe("multiple clients syncing with the a cloud-like server mesh", () => {
|
|
|
138
139
|
"core -> storage | CONTENT Group header: true new: After: 0 New: 5",
|
|
139
140
|
"storage -> core | KNOWN Group sessions: header/5",
|
|
140
141
|
"core -> storage | CONTENT Map header: true new: After: 0 New: 1",
|
|
141
|
-
"storage -> core | KNOWN Map sessions: header/1",
|
|
142
142
|
"client -> edge-italy | LOAD Map sessions: empty",
|
|
143
|
+
"storage -> core | KNOWN Map sessions: header/1",
|
|
143
144
|
"edge-italy -> core | LOAD Map sessions: empty",
|
|
144
145
|
"core -> edge-italy | CONTENT ParentGroup header: true new: After: 0 New: 6",
|
|
145
146
|
"edge-italy -> core | KNOWN ParentGroup sessions: header/6",
|
|
@@ -355,6 +356,7 @@ describe("multiple clients syncing with the a cloud-like server mesh", () => {
|
|
|
355
356
|
syncServer: storage.node,
|
|
356
357
|
});
|
|
357
358
|
|
|
359
|
+
storagePeer.role = "storage";
|
|
358
360
|
storagePeer.priority = 100;
|
|
359
361
|
|
|
360
362
|
const group = coreServer.node.createGroup();
|
|
@@ -402,4 +404,60 @@ describe("multiple clients syncing with the a cloud-like server mesh", () => {
|
|
|
402
404
|
|
|
403
405
|
expect(mapOnClient.get("hello")).toEqual("world");
|
|
404
406
|
});
|
|
407
|
+
|
|
408
|
+
test("a stuck server peer should not block the load from other server peers", async () => {
|
|
409
|
+
const client = setupTestNode();
|
|
410
|
+
const coreServer = setupTestNode({
|
|
411
|
+
isSyncServer: true,
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
const anotherServer = setupTestNode({});
|
|
415
|
+
|
|
416
|
+
const { peer: peerToCoreServer } = client.connectToSyncServer({
|
|
417
|
+
syncServerName: "core",
|
|
418
|
+
syncServer: coreServer.node,
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
const { peer1, peer2 } = connectedPeersWithMessagesTracking({
|
|
422
|
+
peer1: {
|
|
423
|
+
id: anotherServer.node.getCurrentAgent().id,
|
|
424
|
+
role: "server",
|
|
425
|
+
name: "another-server",
|
|
426
|
+
},
|
|
427
|
+
peer2: {
|
|
428
|
+
id: client.node.getCurrentAgent().id,
|
|
429
|
+
role: "client",
|
|
430
|
+
name: "client",
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
blockMessageTypeOnOutgoingPeer(peerToCoreServer, "load");
|
|
435
|
+
|
|
436
|
+
client.node.syncManager.addPeer(peer1);
|
|
437
|
+
anotherServer.node.syncManager.addPeer(peer2);
|
|
438
|
+
|
|
439
|
+
const group = anotherServer.node.createGroup();
|
|
440
|
+
const map = group.createMap();
|
|
441
|
+
|
|
442
|
+
map.set("hello", "world", "trusting");
|
|
443
|
+
|
|
444
|
+
const mapOnClient = await loadCoValueOrFail(client.node, map.id);
|
|
445
|
+
|
|
446
|
+
expect(
|
|
447
|
+
SyncMessagesLog.getMessages({
|
|
448
|
+
Group: group.core,
|
|
449
|
+
Map: map.core,
|
|
450
|
+
}),
|
|
451
|
+
).toMatchInlineSnapshot(`
|
|
452
|
+
[
|
|
453
|
+
"client -> another-server | LOAD Map sessions: empty",
|
|
454
|
+
"another-server -> client | CONTENT Group header: true new: After: 0 New: 3",
|
|
455
|
+
"client -> another-server | KNOWN Group sessions: header/3",
|
|
456
|
+
"another-server -> client | CONTENT Map header: true new: After: 0 New: 1",
|
|
457
|
+
"client -> another-server | KNOWN Map sessions: header/1",
|
|
458
|
+
]
|
|
459
|
+
`);
|
|
460
|
+
|
|
461
|
+
expect(mapOnClient.get("hello")).toEqual("world");
|
|
462
|
+
});
|
|
405
463
|
});
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { assert, beforeEach, describe, expect, test } from "vitest";
|
|
2
2
|
import { expectMap } from "../coValue";
|
|
3
3
|
import { WasmCrypto } from "../crypto/WasmCrypto";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
SyncMessagesLog,
|
|
6
|
+
loadCoValueOrFail,
|
|
7
|
+
setupTestAccount,
|
|
8
|
+
setupTestNode,
|
|
9
|
+
waitFor,
|
|
10
|
+
} from "./testUtils";
|
|
5
11
|
|
|
6
12
|
let jazzCloud = setupTestNode({ isSyncServer: true });
|
|
7
13
|
|
|
@@ -146,7 +152,9 @@ describe("peer reconciliation", () => {
|
|
|
146
152
|
});
|
|
147
153
|
|
|
148
154
|
test("correctly handle server restarts in the middle of a sync", async () => {
|
|
149
|
-
const client = setupTestNode(
|
|
155
|
+
const client = setupTestNode({
|
|
156
|
+
connected: true,
|
|
157
|
+
});
|
|
150
158
|
|
|
151
159
|
const group = client.node.createGroup();
|
|
152
160
|
const map = group.createMap();
|
|
@@ -182,10 +190,90 @@ describe("peer reconciliation", () => {
|
|
|
182
190
|
"server -> client | KNOWN Group sessions: empty",
|
|
183
191
|
"client -> server | LOAD Map sessions: header/2",
|
|
184
192
|
"server -> client | KNOWN Map sessions: empty",
|
|
193
|
+
"client -> server | CONTENT Map header: false new: After: 1 New: 1",
|
|
194
|
+
"server -> client | KNOWN CORRECTION Map sessions: empty",
|
|
195
|
+
"client -> server | CONTENT Map header: true new: After: 0 New: 2",
|
|
196
|
+
"server -> client | LOAD Group sessions: empty",
|
|
185
197
|
"client -> server | CONTENT Group header: true new: After: 0 New: 3",
|
|
198
|
+
"server -> client | KNOWN CORRECTION Map sessions: empty",
|
|
199
|
+
"client -> server | CONTENT Map header: true new: After: 0 New: 2",
|
|
200
|
+
"server -> client | KNOWN Group sessions: header/3",
|
|
201
|
+
"server -> client | KNOWN Map sessions: header/2",
|
|
202
|
+
"client -> server | LOAD Group sessions: header/3",
|
|
186
203
|
"server -> client | KNOWN Group sessions: header/3",
|
|
204
|
+
"client -> server | LOAD Map sessions: header/2",
|
|
205
|
+
"server -> client | KNOWN Map sessions: header/2",
|
|
206
|
+
]
|
|
207
|
+
`);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("correctly handle server restarts in the middle of a sync (2 - account)", async () => {
|
|
211
|
+
const client = await setupTestAccount({
|
|
212
|
+
connected: true,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const group = client.node.createGroup();
|
|
216
|
+
const map = group.createMap();
|
|
217
|
+
|
|
218
|
+
map.set("hello", "world", "trusting");
|
|
219
|
+
|
|
220
|
+
await map.core.waitForSync();
|
|
221
|
+
|
|
222
|
+
jazzCloud.restart();
|
|
223
|
+
SyncMessagesLog.clear();
|
|
224
|
+
client.connectToSyncServer();
|
|
225
|
+
|
|
226
|
+
map.set("hello", "updated", "trusting");
|
|
227
|
+
|
|
228
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
229
|
+
|
|
230
|
+
client.connectToSyncServer();
|
|
231
|
+
|
|
232
|
+
await waitFor(() => {
|
|
233
|
+
const mapOnSyncServer = jazzCloud.node.getCoValue(map.id);
|
|
234
|
+
|
|
235
|
+
expect(mapOnSyncServer.loadingState).toBe("available");
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
expect(
|
|
239
|
+
SyncMessagesLog.getMessages({
|
|
240
|
+
Account: client.node.expectCurrentAccount("client account").core,
|
|
241
|
+
Profile: client.node.expectProfileLoaded(client.accountID).core,
|
|
242
|
+
ProfileGroup: client.node.expectProfileLoaded(client.accountID).group
|
|
243
|
+
.core,
|
|
244
|
+
Group: group.core,
|
|
245
|
+
Map: map.core,
|
|
246
|
+
}),
|
|
247
|
+
).toMatchInlineSnapshot(`
|
|
248
|
+
[
|
|
249
|
+
"client -> server | LOAD Account sessions: header/4",
|
|
250
|
+
"server -> client | KNOWN Account sessions: empty",
|
|
251
|
+
"client -> server | LOAD ProfileGroup sessions: header/5",
|
|
252
|
+
"server -> client | KNOWN ProfileGroup sessions: empty",
|
|
253
|
+
"client -> server | LOAD Profile sessions: header/1",
|
|
254
|
+
"server -> client | KNOWN Profile sessions: empty",
|
|
255
|
+
"client -> server | LOAD Group sessions: header/3",
|
|
256
|
+
"server -> client | KNOWN Group sessions: empty",
|
|
257
|
+
"client -> server | LOAD Map sessions: header/2",
|
|
258
|
+
"server -> client | KNOWN Map sessions: empty",
|
|
259
|
+
"client -> server | CONTENT Map header: false new: After: 1 New: 1",
|
|
260
|
+
"server -> client | KNOWN CORRECTION Map sessions: empty",
|
|
187
261
|
"client -> server | CONTENT Map header: true new: After: 0 New: 2",
|
|
262
|
+
"server -> client | LOAD Account sessions: empty",
|
|
263
|
+
"client -> server | CONTENT Account header: true new: After: 0 New: 4",
|
|
264
|
+
"server -> client | LOAD Group sessions: empty",
|
|
265
|
+
"client -> server | CONTENT Group header: true new: After: 0 New: 3",
|
|
266
|
+
"server -> client | KNOWN CORRECTION Map sessions: empty",
|
|
267
|
+
"client -> server | CONTENT Map header: true new: After: 0 New: 2",
|
|
268
|
+
"server -> client | KNOWN Account sessions: header/4",
|
|
269
|
+
"server -> client | KNOWN Group sessions: header/3",
|
|
188
270
|
"server -> client | KNOWN Map sessions: header/2",
|
|
271
|
+
"client -> server | LOAD Account sessions: header/4",
|
|
272
|
+
"server -> client | KNOWN Account sessions: header/4",
|
|
273
|
+
"client -> server | LOAD ProfileGroup sessions: header/5",
|
|
274
|
+
"server -> client | KNOWN ProfileGroup sessions: empty",
|
|
275
|
+
"client -> server | LOAD Profile sessions: header/1",
|
|
276
|
+
"server -> client | KNOWN Profile sessions: empty",
|
|
189
277
|
"client -> server | LOAD Group sessions: header/3",
|
|
190
278
|
"server -> client | KNOWN Group sessions: header/3",
|
|
191
279
|
"client -> server | LOAD Map sessions: header/2",
|