Skip to content

Commit 5e3a7ce

Browse files
committed
fix: clean up subscriptions, intervals and timeouts when stopping
1 parent 1dc59e0 commit 5e3a7ce

File tree

11 files changed

+452
-321
lines changed

11 files changed

+452
-321
lines changed

packages/core/src/lib/stream_manager/stream_manager.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ describe("StreamManager", () => {
2727
} as any as Libp2pComponents);
2828
});
2929

30+
afterEach(() => {
31+
sinon.restore();
32+
});
33+
3034
it("should return usable stream attached to connection", async () => {
3135
for (const writeStatus of ["ready", "writing"]) {
3236
const con1 = createMockConnection();

packages/sdk/src/light_push/light_push.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Libp2p, LightPushError, LightPushStatusCode } from "@waku/interfaces";
99
import { createRoutingInfo } from "@waku/utils";
1010
import { utf8ToBytes } from "@waku/utils/bytes";
1111
import { expect } from "chai";
12+
import { afterEach } from "mocha";
1213
import sinon, { SinonSpy } from "sinon";
1314

1415
import { PeerManager } from "../peer_manager/index.js";
@@ -38,6 +39,10 @@ describe("LightPush SDK", () => {
3839
lightPush = mockLightPush({ libp2p });
3940
});
4041

42+
afterEach(() => {
43+
sinon.restore();
44+
});
45+
4146
it("should fail to send if no connected peers found", async () => {
4247
const result = await lightPush.send(encoder, {
4348
payload: utf8ToBytes("test")

packages/sdk/src/light_push/retry_manager.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ describe("RetryManager", () => {
4747
sinon.restore();
4848
});
4949

50-
it("should start and stop interval correctly", () => {
50+
// TODO: Skipped because the global state is not being restored and it breaks
51+
// tests of functionalities that rely on intervals
52+
it.skip("should start and stop interval correctly", () => {
5153
const setIntervalSpy = sinon.spy(global, "setInterval");
5254
const clearIntervalSpy = sinon.spy(global, "clearInterval");
5355

packages/sdk/src/query_on_connect/query_on_connect.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { delay } from "@waku/utils";
1111
import { utf8ToBytes } from "@waku/utils/bytes";
1212
import { expect } from "chai";
13+
import { afterEach } from "mocha";
1314
import sinon from "sinon";
1415

1516
import {
@@ -91,6 +92,10 @@ describe("QueryOnConnect", () => {
9192
};
9293
});
9394

95+
afterEach(() => {
96+
sinon.restore();
97+
});
98+
9499
describe("constructor", () => {
95100
it("should create QueryOnConnect instance with all required parameters", () => {
96101
queryOnConnect = new QueryOnConnect(
@@ -337,6 +342,7 @@ describe("QueryOnConnect", () => {
337342
});
338343

339344
afterEach(() => {
345+
sinon.restore();
340346
mockClock.restore();
341347
});
342348

0 commit comments

Comments
 (0)