mirror of
https://github.com/logos-messaging/logos-delivery-js.git
synced 2026-03-09 11:13:17 +00:00
* sharding tests refactor * small fixes * adjust clusterID based on version * fix typo * fix dispatchEvent test * sharding unit tests * port adjustment * update unit tests * fix 1902 * adjust content topic tests * adjust metdata tests * small adjustments * fix * update resolveAutoshardingCluster version * skip autosharding tests for nwaku < 0.27.0 * skip autosharding tests for nwaku < 0.27.0
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { Logger } from "@waku/utils";
|
|
|
|
import { DOCKER_IMAGE_NAME } from "../lib/service_node";
|
|
|
|
const log = new Logger("test:utils");
|
|
|
|
// Utility to add test conditions based on nwaku/go-waku versions
|
|
export function isNwakuAtLeast(requiredVersion: string): boolean {
|
|
const versionRegex = /(?:v)?(\d+\.\d+(?:\.\d+)?)/;
|
|
const match = DOCKER_IMAGE_NAME.match(versionRegex);
|
|
|
|
if (match) {
|
|
const version = match[0].substring(1); // Remove the 'v' prefix
|
|
return (
|
|
version.localeCompare(requiredVersion, undefined, { numeric: true }) >= 0
|
|
);
|
|
} else {
|
|
// If there is no match we assume that it's a version close to master so we return True
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// Utility to resolve autosharding cluster ID
|
|
export function resolveAutoshardingCluster(clusterId: number): number {
|
|
if (isNwakuAtLeast("0.27.0")) {
|
|
log.info(`Using clusterID ${clusterId} for autosharding`);
|
|
return clusterId;
|
|
} else {
|
|
// for versions older than 0.27.0 the autosharding cluster was hardcoded to 1
|
|
// https://github.com/waku-org/nwaku/pull/2505
|
|
log.warn("Falling back to clusterID 1 for autosharding");
|
|
return 1;
|
|
}
|
|
}
|