Skip to content

Commit

Permalink
test: Make the reconnect test compatible with older redis versions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbachmann committed Jan 31, 2022
1 parent 94bafe5 commit bdf88bd
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions test/functional/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ describe("pipeline", function () {
});

it("should reload scripts on redis restart (reconnect)", async function () {
const redis = new Redis();
const redis = new Redis({ connectionName: "load-script-on-reconnect" });
const redis2 = new Redis();
redis.defineCommand("exeecafterreconnect", {
numberOfKeys: 0,
Expand All @@ -366,13 +366,17 @@ describe("pipeline", function () {
expect(err).to.equal(null);
expect(res).to.equal("OK");

const clientId = await redis.client("id");
await redis2
.pipeline([
["script", "flush"],
["client", "kill", "id", clientId],
])
.exec();
const client = await redis.client("list").then((clients) => {
const myInfo = clients
.split("\n")
.find((client) => client.includes("load-script-on-reconnect"));

const match = / addr=([^ ]+)/.exec(myInfo);
if (match) return match[1];
});

await redis2.script("flush");
await redis2.client("kill", "addr", client);

// Wait for reconnect, at the moment scripts are not loaded
// if the pipeline starts before ioredis reconnects
Expand All @@ -381,6 +385,7 @@ describe("pipeline", function () {
const [[err2, res2]] = await redis
.multi([["exeecafterreconnect"]])
.exec();

expect(err2).to.equal(null);
expect(res2).to.equal("OK");
redis.disconnect();
Expand Down

0 comments on commit bdf88bd

Please sign in to comment.