chore: add a test that uses ping to check filter subscription (#1656)

* add a test that uses ping to check filter subscription

* remove comment
This commit is contained in:
Danish Arora 2023-10-13 16:53:15 +05:30 committed by GitHub
parent 347cbfa08a
commit d39d4507ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 0 deletions

View File

@ -59,4 +59,40 @@ describe("Waku Filter V2: Ping", function () {
// Ping imediately after unsubscribe
await validatePingError(subscription);
});
it("Reopen subscription with peer with lost subscription", async function () {
const openSubscription = async (): Promise<void> => {
await subscription.subscribe([TestDecoder], messageCollector.callback);
};
const unsubscribe = async (): Promise<void> => {
await subscription.unsubscribe([TestContentTopic]);
};
const pingAndReinitiateSubscription = async (): Promise<void> => {
try {
await subscription.ping();
} catch (error) {
if (
error instanceof Error &&
error.message.includes("peer has no subscriptions")
) {
await openSubscription();
} else {
throw error;
}
}
};
// open subscription & ping -> should pass
await openSubscription();
await pingAndReinitiateSubscription();
// unsubscribe & ping -> should fail and reinitiate subscription
await unsubscribe();
await pingAndReinitiateSubscription();
// ping -> should pass as subscription is reinitiated
await pingAndReinitiateSubscription();
});
});