Skip to content

Commit

Permalink
Add more GC tests to reflect current server modifications (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins authored Oct 27, 2023
1 parent 7c8313a commit b023bda
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/integration/gc_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestDoc>(docKey);
const doc2 = new yorkie.Document<TestDoc>(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();
});
});

0 comments on commit b023bda

Please sign in to comment.