You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
Adapt legacy sentinel tests to use the new test utils (#2976)
* modified legacy sentinel tests * Adapt legacy sentinel tests to use the new test utils * modify tmpdir creation * reduced sentinel config timeouts, removed unneeded comment --------- Co-authored-by: H. Temelski <hristo.temelski@redis.com>
This commit is contained in:
@@ -62,7 +62,7 @@ export interface RedisServerDocker {
|
||||
dockerId: string;
|
||||
}
|
||||
|
||||
async function spawnRedisServerDocker(
|
||||
export async function spawnRedisServerDocker(
|
||||
options: RedisServerDockerOptions, serverArguments: Array<string>): Promise<RedisServerDocker> {
|
||||
let port;
|
||||
if (options.mode == "sentinel") {
|
||||
@@ -374,35 +374,16 @@ export async function spawnRedisSentinel(
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), appPrefix));
|
||||
|
||||
for (let i = 0; i < sentinelCount; i++) {
|
||||
sentinelPromises.push((async () => {
|
||||
const port = (await portIterator.next()).value;
|
||||
|
||||
let sentinelConfig = `port ${port}
|
||||
sentinel monitor mymaster 127.0.0.1 ${master.port} 2
|
||||
sentinel down-after-milliseconds mymaster 5000
|
||||
sentinel failover-timeout mymaster 6000
|
||||
`;
|
||||
if (password !== undefined) {
|
||||
sentinelConfig += `requirepass ${password}\n`;
|
||||
sentinelConfig += `sentinel auth-pass mymaster ${password}\n`;
|
||||
}
|
||||
|
||||
const dir = fs.mkdtempSync(path.join(tmpDir, i.toString()));
|
||||
fs.writeFile(`${dir}/redis.conf`, sentinelConfig, err => {
|
||||
if (err) {
|
||||
console.error("failed to create temporary config file", err);
|
||||
}
|
||||
});
|
||||
|
||||
return await spawnRedisServerDocker(
|
||||
{
|
||||
image: dockerConfigs.image,
|
||||
version: dockerConfigs.version,
|
||||
mode: "sentinel",
|
||||
mounts: [`${dir}/redis.conf:/redis/config/node-sentinel-1/redis.conf`],
|
||||
port: port,
|
||||
}, serverArguments);
|
||||
})());
|
||||
sentinelPromises.push(
|
||||
spawnSentinelNode(
|
||||
dockerConfigs,
|
||||
serverArguments,
|
||||
master.port,
|
||||
"mymaster",
|
||||
path.join(tmpDir, i.toString()),
|
||||
password,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
const sentinelNodes = await Promise.all(sentinelPromises);
|
||||
@@ -424,3 +405,43 @@ after(() => {
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
export async function spawnSentinelNode(
|
||||
dockerConfigs: RedisServerDockerOptions,
|
||||
serverArguments: Array<string>,
|
||||
masterPort: number,
|
||||
sentinelName: string,
|
||||
tmpDir: string,
|
||||
password?: string,
|
||||
) {
|
||||
const port = (await portIterator.next()).value;
|
||||
|
||||
let sentinelConfig = `port ${port}
|
||||
sentinel monitor ${sentinelName} 127.0.0.1 ${masterPort} 2
|
||||
sentinel down-after-milliseconds ${sentinelName} 500
|
||||
sentinel failover-timeout ${sentinelName} 1000
|
||||
`;
|
||||
if (password !== undefined) {
|
||||
sentinelConfig += `requirepass ${password}\n`;
|
||||
sentinelConfig += `sentinel auth-pass ${sentinelName} ${password}\n`;
|
||||
}
|
||||
|
||||
const dir = fs.mkdtempSync(tmpDir);
|
||||
fs.writeFile(`${dir}/redis.conf`, sentinelConfig, err => {
|
||||
if (err) {
|
||||
console.error("failed to create temporary config file", err);
|
||||
}
|
||||
});
|
||||
|
||||
return await spawnRedisServerDocker(
|
||||
{
|
||||
image: dockerConfigs.image,
|
||||
version: dockerConfigs.version,
|
||||
mode: "sentinel",
|
||||
mounts: [`${dir}/redis.conf:/redis/config/node-sentinel-1/redis.conf`],
|
||||
port: port,
|
||||
},
|
||||
serverArguments,
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user