diff --git a/test/integration/gc_test.ts b/test/integration/gc_test.ts index 3ea460201..358a34bf6 100644 --- a/test/integration/gc_test.ts +++ b/test/integration/gc_test.ts @@ -609,4 +609,50 @@ describe('Garbage Collection', function () { assert.equal(doc.getGarbageLen(), 6); assert.equal(doc.getGarbageLenFromClone(), 6); }); + + it('Can purges removed elements after peers can not access them', async function ({ + task, + }) { + type TestDoc = { point: { x: number; y: number } }; + const docKey = toDocKey(`${task.name}-${new Date().getTime()}`); + const doc1 = new yorkie.Document(docKey); + const doc2 = new yorkie.Document(docKey); + + const client1 = new yorkie.Client(testRPCAddr); + const client2 = new yorkie.Client(testRPCAddr); + + await client1.activate(); + await client2.activate(); + + await client1.attach(doc1, { isRealtimeSync: false }); + doc1.update((root) => (root.point = { x: 0, y: 0 })); + doc1.update((root) => (root.point.x = 1)); + assert.equal(doc1.getGarbageLen(), 1); + await client1.sync(); + + await client2.attach(doc2, { isRealtimeSync: false }); + assert.equal(doc2.getGarbageLen(), 1); + doc2.update((root) => (root.point.x = 2)); + assert.equal(doc2.getGarbageLen(), 2); + + doc1.update((root) => (root.point = { x: 3, y: 3 })); + assert.equal(doc1.getGarbageLen(), 4); + await client1.sync(); + assert.equal(doc1.getGarbageLen(), 4); + + await client1.sync(); + assert.equal(doc1.getGarbageLen(), 4); + + await client2.sync(); + assert.equal(doc1.getGarbageLen(), 4); + await client1.sync(); + assert.equal(doc1.getGarbageLen(), 5); + await client2.sync(); + assert.equal(doc1.getGarbageLen(), 5); + await client1.sync(); + assert.equal(doc1.getGarbageLen(), 0); + + await client1.deactivate(); + await client2.deactivate(); + }); });