Skip to content

Commit

Permalink
Replace reattach test code
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Jul 1, 2024
1 parent d9bfc4c commit d0863a3
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions test/integration/document_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,40 +815,51 @@ describe('Document', function () {
status: DocumentStatus.Detached,
});

// 4. When the document is re-attached, it receives an attached event.
await c1.attach(d1, { syncMode: SyncMode.Manual });
await eventCollectorD1.waitAndVerifyNthEvent(3, {
// 4. When other document is attached, it receives an attached event.
const docKey2 = toDocKey(`${task.name}2-${new Date().getTime()}`);
const d3 = new yorkie.Document(docKey2);
const d4 = new yorkie.Document(docKey2);
const eventCollectorD3 = new EventCollector<StatusChangedEvent['value']>();
const eventCollectorD4 = new EventCollector<StatusChangedEvent['value']>();
const unsub3 = d3.subscribe('status', (event) => {
eventCollectorD3.add(event.value);
});
const unsub4 = d4.subscribe('status', (event) => {
eventCollectorD4.add(event.value);
});
await c1.attach(d3, { syncMode: SyncMode.Manual });
await eventCollectorD3.waitAndVerifyNthEvent(1, {
status: DocumentStatus.Attached,
actorID: c1ID,
});

await c2.activate();
c2ID = c2.getID()!;
await c2.attach(d2, { syncMode: SyncMode.Manual });
await eventCollectorD2.waitAndVerifyNthEvent(3, {
await c2.attach(d4, { syncMode: SyncMode.Manual });
await eventCollectorD4.waitAndVerifyNthEvent(1, {
status: DocumentStatus.Attached,
actorID: c2ID,
});

// 5. When c1 removes a document, it receives a removed event.
await c1.remove(d1);
await eventCollectorD1.waitAndVerifyNthEvent(4, {
await c1.remove(d3);
await eventCollectorD3.waitAndVerifyNthEvent(2, {
status: DocumentStatus.Removed,
});

// 6. When c4 syncs, it should also receive a removed event.
// 6. When c2 syncs, it should also receive a removed event.
await c2.sync();
await eventCollectorD2.waitAndVerifyNthEvent(4, {
await eventCollectorD4.waitAndVerifyNthEvent(2, {
status: DocumentStatus.Removed,
});

// 7. If the document is in the removed state, a detached event should not occur when deactivating.
const eventCount1 = eventCollectorD1.getLength();
const eventCount2 = eventCollectorD2.getLength();
const eventCount3 = eventCollectorD3.getLength();
const eventCount4 = eventCollectorD4.getLength();
await c1.deactivate();
await c2.deactivate();
assert.equal(eventCollectorD1.getLength(), eventCount1);
assert.equal(eventCollectorD2.getLength(), eventCount2);
assert.equal(eventCollectorD3.getLength(), eventCount3);
assert.equal(eventCollectorD4.getLength(), eventCount4);

unsub1();
unsub2();
Expand Down

0 comments on commit d0863a3

Please sign in to comment.