Skip to content

Commit

Permalink
chore: add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Jul 9, 2024
1 parent cdf863b commit 1267f5d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/interfaces/src/filter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PeerId } from "@libp2p/interface";

import type { IDecodedMessage, IDecoder } from "./message.js";
import type { ContentTopic, PubsubTopic, ThisOrThat } from "./misc.js";
import type {
Expand Down Expand Up @@ -27,7 +29,7 @@ export interface ISubscriptionSDK {

unsubscribe(contentTopics: ContentTopic[]): Promise<SDKProtocolResult>;

ping(): Promise<SDKProtocolResult>;
ping(peerId?: PeerId): Promise<SDKProtocolResult>;

unsubscribeAll(): Promise<SDKProtocolResult>;
}
Expand Down
29 changes: 29 additions & 0 deletions packages/tests/tests/filter/peer_management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,35 @@ describe.only("Waku Filter: Peer Management: E2E", function () {
).to.eq(false);
});

it("Tracks peer failures correctly", async function () {
const maxPingFailures = 3;
await subscription.subscribe([decoder], () => {}, {
pingsBeforePeerRenewed: maxPingFailures
});

const targetPeer = waku.filter.connectedPeers[0];
await waku.connectionManager.dropConnection(targetPeer.id);

for (let i = 0; i < maxPingFailures; i++) {
await subscription.ping(targetPeer.id);
}

// At this point, the peer should not be renewed yet
expect(
waku.filter.connectedPeers.some((peer) => peer.id.equals(targetPeer.id))
).to.be.true;

// One more failure should trigger renewal
await subscription.ping(targetPeer.id);

expect(
waku.filter.connectedPeers.some((peer) => peer.id.equals(targetPeer.id))
).to.be.false;
expect(waku.filter.connectedPeers.length).to.equal(
waku.filter.numPeersToUse
);
});

it("Maintains correct number of peers after multiple subscribe/unsubscribe cycles", async function () {
for (let i = 0; i < 3; i++) {
await subscription.subscribe([decoder], () => {});
Expand Down

0 comments on commit 1267f5d

Please sign in to comment.