Skip to content

Commit

Permalink
add socketTimeout functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkiesky committed Nov 5, 2024
1 parent 26904a0 commit 7f4ee5e
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/functional/socketTimeout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { expect } from "chai";
import Redis from "../../lib/Redis";

describe("socketTimeout", () => {
const timeoutMs = 500;

it("should ensure correct startup with password (https://github.com/redis/ioredis/issues/1919)", (done) => {
let timeoutObj: NodeJS.Timeout;

const redis = new Redis({
socketTimeout: timeoutMs,
lazyConnect: true,
password: "foobared",
});

redis.on("error", (err) => {
clearTimeout(timeoutObj);
done(err.toString());
});

redis.connect(() => {
timeoutObj = setTimeout(() => {
done();
}, timeoutMs * 2);
});
});

it("should not throw error when socketTimeout is set and no command is sent", (done) => {
let timeoutObj: NodeJS.Timeout;

const redis = new Redis({
socketTimeout: timeoutMs,
lazyConnect: true,
});

redis.on("error", (err) => {
clearTimeout(timeoutObj);
done(err.toString());
});

redis.connect(() => {
timeoutObj = setTimeout(() => {
done();
}, timeoutMs * 2);
});
});

it("should throw if socket timeout is reached", (done) => {
const redis = new Redis({
socketTimeout: timeoutMs,
lazyConnect: true,
});

redis.on("error", (err) => {
expect(err.message).to.include("Socket timeout");
done();
});

redis.connect(() => {
redis.stream.removeAllListeners("data");
redis.ping();
});
});
});

0 comments on commit 7f4ee5e

Please sign in to comment.