From 61125282d3b2c82026de251422be4b2defb17b66 Mon Sep 17 00:00:00 2001 From: yahiro Date: Sat, 23 Mar 2024 01:38:56 +0900 Subject: [PATCH] fix: add test for reconnect --- tests/reconnect_test.ts | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/reconnect_test.ts diff --git a/tests/reconnect_test.ts b/tests/reconnect_test.ts new file mode 100644 index 00000000..a70133db --- /dev/null +++ b/tests/reconnect_test.ts @@ -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); + }); +});