Skip to content

Commit 339e26e

Browse files
committed
test: ensure sync status cleanup
1 parent 0e5e912 commit 339e26e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/sdk/src/reliable_channel/sync_status.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ describe("Sync Status", () => {
3333
syncStatus = new SyncStatus();
3434
});
3535

36+
afterEach(() => {
37+
syncStatus.cleanUp();
38+
});
39+
3640
it("Emits 'synced' when new message received", async () => {
3741
await testSyncStatus(
3842
syncStatus,

packages/sdk/src/reliable_channel/sync_status.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class SyncStatus extends TypedEventEmitter<StatusEvents> {
6666
private readonly missingMessages: Set<MessageId>;
6767
private readonly lostMessages: Set<MessageId>;
6868
private sendScheduled = false;
69+
private cleaned = false;
6970

7071
public constructor() {
7172
super();
@@ -79,6 +80,8 @@ export class SyncStatus extends TypedEventEmitter<StatusEvents> {
7980
* Cleanup all tracked message IDs. Should be called when stopping the channel.
8081
*/
8182
public cleanUp(): void {
83+
// Mark as cleaned to prevent any pending microtasks from firing
84+
this.cleaned = true;
8285
this.receivedMessages.clear();
8386
this.missingMessages.clear();
8487
this.lostMessages.clear();
@@ -134,6 +137,11 @@ export class SyncStatus extends TypedEventEmitter<StatusEvents> {
134137
}
135138

136139
private safeSend(): void {
140+
// Don't send events if cleanup was already called
141+
if (this.cleaned) {
142+
return;
143+
}
144+
137145
const statusEvent =
138146
this.missingMessages.size === 0
139147
? StatusEvent.Synced

0 commit comments

Comments
 (0)