diff --git a/utils/TestUtils.ts b/utils/TestUtils.ts index 2f6280c642..1e1bd2927b 100644 --- a/utils/TestUtils.ts +++ b/utils/TestUtils.ts @@ -51,36 +51,29 @@ export class RedisCluster { } private static async detectVersion(): Promise { - return new Promise((resolve, reject) => { - // Helper function to execute a command and parse the version - const getVersion = (command: string): Promise => { - return new Promise((resolve, reject) => { - exec(command, (error, stdout) => { - if (error) { - reject(error); + const getVersion = (command: string): Promise => { + return new Promise((resolve, reject) => { + exec(command, (error, stdout) => { + if (error) { + reject(error); + } else { + const versionMatch = stdout.match(/v=([^\s]+)/); + + if (versionMatch) { + resolve(versionMatch[1]); } else { - const versionMatch = stdout.match(/v=([^\s]+)/); - - if (versionMatch) { - resolve(versionMatch[1]); - } else { - reject( - new Error("Version not found in output") - ); - } + reject(new Error("Version not found in output")); } - }); - }); - }; - - // Attempt to get the version from valkey-server first - getVersion("valkey-server -v") - .then(resolve) - .catch(() => { - // If valkey-server fails, attempt to get the version from redis-server - getVersion("redis-server -v").then(resolve).catch(reject); + } }); - }); + }); + }; + + try { + return await getVersion("valkey-server -v"); + } catch { + return await getVersion("redis-server -v"); + } } public static createCluster(