( dockerConfigs: RedisServerDockerOptions, serverArguments: Array<string>, )
| 615 | const RUNNING_SENTINELS = new Map<Array<string>, Array<RedisServerDocker>>(); |
| 616 | |
| 617 | export async function spawnRedisSentinel( |
| 618 | dockerConfigs: RedisServerDockerOptions, |
| 619 | serverArguments: Array<string>, |
| 620 | ): Promise<Array<RedisServerDocker>> { |
| 621 | const runningNodes = RUNNING_SENTINELS.get(serverArguments); |
| 622 | if (runningNodes) { |
| 623 | return runningNodes; |
| 624 | } |
| 625 | |
| 626 | const passIndex = serverArguments.indexOf('--requirepass')+1; |
| 627 | let password: string | undefined = undefined; |
| 628 | if (passIndex != 0) { |
| 629 | password = serverArguments[passIndex]; |
| 630 | } |
| 631 | |
| 632 | const master = await spawnRedisServerDocker(dockerConfigs, serverArguments); |
| 633 | const redisNodes: Array<RedisServerDocker> = [master]; |
| 634 | const replicaPromises: Array<Promise<RedisServerDocker>> = []; |
| 635 | |
| 636 | const replicasCount = 2; |
| 637 | for (let i = 0; i < replicasCount; i++) { |
| 638 | replicaPromises.push((async () => { |
| 639 | const replica = await spawnRedisServerDocker(dockerConfigs, serverArguments); |
| 640 | const client = createClient({ |
| 641 | socket: { |
| 642 | port: replica.port |
| 643 | }, |
| 644 | password: password |
| 645 | }); |
| 646 | |
| 647 | await client.connect(); |
| 648 | await client.replicaOf("127.0.0.1", master.port); |
| 649 | await client.close(); |
| 650 | |
| 651 | return replica; |
| 652 | })()); |
| 653 | } |
| 654 | |
| 655 | const replicas = await Promise.all(replicaPromises); |
| 656 | redisNodes.push(...replicas); |
| 657 | RUNNING_NODES.set(serverArguments, redisNodes); |
| 658 | |
| 659 | const sentinelPromises: Array<Promise<RedisServerDocker>> = []; |
| 660 | const sentinelCount = 3; |
| 661 | |
| 662 | const appPrefix = 'sentinel-config-dir'; |
| 663 | const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), appPrefix)); |
| 664 | |
| 665 | for (let i = 0; i < sentinelCount; i++) { |
| 666 | sentinelPromises.push( |
| 667 | spawnSentinelNode( |
| 668 | dockerConfigs, |
| 669 | serverArguments, |
| 670 | master.port, |
| 671 | "mymaster", |
| 672 | path.join(tmpDir, i.toString()), |
| 673 | password, |
| 674 | ), |
no test coverage detected