js-waku/packages/tests/tests/store/page_size.node.spec.ts
Danish Arora f8e02ab19e
fix(tests): append p2p with the multiaddrs from ENR (#1817)
* append `p2p` with the multiaddrs from ENR

* fix(tests): add p2p checks for ENR multiaddrs

* fix(tests): type getter

* chore(ci): remove debug flag from nwaku_master and go-waku tests
2024-02-07 01:57:41 +05:30

104 lines
2.6 KiB
TypeScript

import { DefaultPubsubTopic } from "@waku/interfaces";
import type { LightNode } from "@waku/interfaces";
import { expect } from "chai";
import {
makeLogFileName,
ServiceNode,
tearDownNodes
} from "../../src/index.js";
import {
sendMessages,
startAndConnectLightNode,
TestContentTopic,
TestDecoder
} from "./utils.js";
describe("Waku Store, page size", function () {
this.timeout(15000);
let waku: LightNode;
let nwaku: ServiceNode;
beforeEach(async function () {
this.timeout(15000);
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions();
});
afterEach(async function () {
this.timeout(15000);
await tearDownNodes(nwaku, waku);
});
[
[0, 110],
[1, 4],
[3, 20],
[10, 10],
[11, 10],
[19, 20],
[110, 120]
].forEach(([pageSize, messageCount]) => {
it(`Passing page size ${pageSize} when there are ${messageCount} messages`, async function () {
await sendMessages(
nwaku,
messageCount,
TestContentTopic,
DefaultPubsubTopic
);
// Determine effectivePageSize for test expectations
let effectivePageSize = pageSize;
if (pageSize === 0) {
effectivePageSize = 20;
} else if (pageSize > 100) {
if (nwaku.type == "go-waku") {
effectivePageSize = 20;
} else {
effectivePageSize = 100;
}
}
waku = await startAndConnectLightNode(nwaku);
let messagesRetrieved = 0;
for await (const query of waku.store.queryGenerator([TestDecoder], {
pageSize: pageSize
})) {
// Calculate expected page size
const expectedPageSize = Math.min(
effectivePageSize,
messageCount - messagesRetrieved
);
expect(query.length).eq(expectedPageSize);
for await (const msg of query) {
if (msg) {
messagesRetrieved++;
}
}
}
expect(messagesRetrieved).eq(messageCount);
});
});
// Possible issue here because pageSize differs across implementations
it("Default pageSize", async function () {
await sendMessages(nwaku, 20, TestContentTopic, DefaultPubsubTopic);
waku = await startAndConnectLightNode(nwaku);
let messagesRetrieved = 0;
for await (const query of waku.store.queryGenerator([TestDecoder])) {
expect(query.length).eq(10);
for await (const msg of query) {
if (msg) {
messagesRetrieved++;
}
}
}
expect(messagesRetrieved).eq(20);
});
});