Skip to content

Commit

Permalink
fix: add test for reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
yahiro07 committed Mar 24, 2024
1 parent 28ead06 commit 6112528
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/reconnect_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Redis } from "../redis.ts";
import { assertEquals } from "../vendor/https/deno.land/std/assert/mod.ts";
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
it,
} from "../vendor/https/deno.land/std/testing/bdd.ts";
import {
newClient,
nextPort,
startRedis,
stopRedis,
TestServer,
} from "./test_util.ts";

describe("reconnect", () => {
let port!: number;
beforeAll(() => {
port = nextPort();
});

it("auto reconnect", async () => {
let server = await startRedis({ port });
const client = await newClient({ hostname: "127.0.0.1", port });
assertEquals(await client.ping(), "PONG");
await stopRedis(server);
server = await startRedis({ port });
assertEquals(await client.ping(), "PONG");
client.close();
await stopRedis(server);
});

it("auto reconnect, with db spec", async () => {
let server = await startRedis({ port });
const client = await newClient({ hostname: "127.0.0.1", port, db: 1 });
assertEquals(await client.ping(), "PONG");
await stopRedis(server);
server = await startRedis({ port });
assertEquals(await client.ping(), "PONG"); //never resolve
client.close();
await stopRedis(server);
});
});

0 comments on commit 6112528

Please sign in to comment.