mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
bun run prettier
This commit is contained in:
committed by
github-actions[bot]
parent
346e964050
commit
8ab2d6b0cd
@@ -1,4 +1,3 @@
|
||||
import { RedisClient } from "bun";
|
||||
import { beforeEach, describe, expect, test } from "bun:test";
|
||||
import { ConnectionType, createClient, ctx, isEnabled, testKey } from "./test-utils";
|
||||
|
||||
@@ -15,7 +14,7 @@ describe.skipIf(!isEnabled)("Redis Reconnection", () => {
|
||||
|
||||
test("should reconnect after manual close when new command is issued", async () => {
|
||||
const redis = ctx.redis;
|
||||
|
||||
|
||||
// 1. Verify initial connection works
|
||||
await redis.set(testKey("reconnect-test"), "initial-value");
|
||||
const initialValue = await redis.get(testKey("reconnect-test"));
|
||||
@@ -23,7 +22,7 @@ describe.skipIf(!isEnabled)("Redis Reconnection", () => {
|
||||
|
||||
// 2. Manually close the connection
|
||||
redis.close();
|
||||
|
||||
|
||||
// Wait for connection to be closed
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
|
||||
@@ -39,16 +38,16 @@ describe.skipIf(!isEnabled)("Redis Reconnection", () => {
|
||||
|
||||
test("should handle multiple commands after reconnection", async () => {
|
||||
const redis = ctx.redis;
|
||||
|
||||
|
||||
// Set initial data
|
||||
await redis.set(testKey("multi1"), "value1");
|
||||
await redis.set(testKey("multi2"), "value2");
|
||||
await redis.set(testKey("multi3"), "value3");
|
||||
|
||||
|
||||
// Close connection
|
||||
redis.close();
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
|
||||
|
||||
// Issue multiple commands rapidly after reconnection
|
||||
const promises = [
|
||||
redis.set(testKey("multi1"), "new1"),
|
||||
@@ -61,7 +60,7 @@ describe.skipIf(!isEnabled)("Redis Reconnection", () => {
|
||||
];
|
||||
|
||||
const results = await Promise.all(promises);
|
||||
|
||||
|
||||
// Verify results
|
||||
expect(results[0]).toBe("OK"); // SET multi1
|
||||
expect(results[1]).toBe("OK"); // SET multi2
|
||||
@@ -70,40 +69,40 @@ describe.skipIf(!isEnabled)("Redis Reconnection", () => {
|
||||
expect(results[4]).toBe("new1"); // GET multi1
|
||||
expect(results[5]).toBe("new2"); // GET multi2
|
||||
expect(results[6]).toBe("new4"); // GET multi4
|
||||
|
||||
|
||||
expect(redis.connected).toBe(true);
|
||||
});
|
||||
|
||||
test("should handle repeated reconnections", async () => {
|
||||
const redis = ctx.redis;
|
||||
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
// Set value
|
||||
await redis.set(testKey(`repeat${i}`), `value${i}`);
|
||||
|
||||
|
||||
// Verify
|
||||
const value = await redis.get(testKey(`repeat${i}`));
|
||||
expect(value).toBe(`value${i}`);
|
||||
|
||||
|
||||
// Close and reconnect
|
||||
redis.close();
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
|
||||
|
||||
// Next command should trigger reconnection
|
||||
await redis.set(testKey(`repeat${i}_after`), `after${i}`);
|
||||
const afterValue = await redis.get(testKey(`repeat${i}_after`));
|
||||
expect(afterValue).toBe(`after${i}`);
|
||||
}
|
||||
|
||||
|
||||
expect(redis.connected).toBe(true);
|
||||
});
|
||||
|
||||
test("should handle different Redis commands after reconnection", async () => {
|
||||
const redis = ctx.redis;
|
||||
|
||||
|
||||
// Test various Redis commands after reconnection
|
||||
await redis.set(testKey("counter"), "10");
|
||||
|
||||
|
||||
redis.close();
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
|
||||
@@ -111,7 +110,7 @@ describe.skipIf(!isEnabled)("Redis Reconnection", () => {
|
||||
const incrResult = await redis.incr(testKey("counter"));
|
||||
expect(incrResult).toBe(11);
|
||||
|
||||
const decrResult = await redis.decr(testKey("counter"));
|
||||
const decrResult = await redis.decr(testKey("counter"));
|
||||
expect(decrResult).toBe(10);
|
||||
|
||||
const existsResult = await redis.exists(testKey("counter"));
|
||||
@@ -123,13 +122,13 @@ describe.skipIf(!isEnabled)("Redis Reconnection", () => {
|
||||
const ttlResult = await redis.ttl(testKey("counter"));
|
||||
expect(ttlResult).toBeGreaterThan(0);
|
||||
expect(ttlResult).toBeLessThanOrEqual(60);
|
||||
|
||||
|
||||
expect(redis.connected).toBe(true);
|
||||
});
|
||||
|
||||
test("should handle large data reconnection", async () => {
|
||||
const redis = ctx.redis;
|
||||
|
||||
|
||||
// Create large data
|
||||
const largeValue = "x".repeat(10000); // 10KB string
|
||||
await redis.set(testKey("large"), largeValue);
|
||||
@@ -141,13 +140,13 @@ describe.skipIf(!isEnabled)("Redis Reconnection", () => {
|
||||
const retrieved = await redis.get(testKey("large"));
|
||||
expect(retrieved).toBe(largeValue);
|
||||
expect(retrieved?.length).toBe(10000);
|
||||
|
||||
|
||||
expect(redis.connected).toBe(true);
|
||||
});
|
||||
|
||||
test("should maintain connection state correctly", async () => {
|
||||
const redis = ctx.redis;
|
||||
|
||||
|
||||
// Force initial connection with a command
|
||||
await redis.set(testKey("state"), "initial");
|
||||
expect(redis.connected).toBe(true);
|
||||
@@ -168,18 +167,18 @@ describe.skipIf(!isEnabled)("Redis Reconnection", () => {
|
||||
|
||||
test("should handle quick successive reconnections", async () => {
|
||||
const redis = ctx.redis;
|
||||
|
||||
|
||||
// Quick successive close/command cycles
|
||||
for (let i = 0; i < 3; i++) {
|
||||
await redis.set(testKey(`quick${i}`), `value${i}`);
|
||||
redis.close();
|
||||
// Don't wait - immediately issue next command
|
||||
await redis.set(testKey(`quick${i}_immediate`), `immediate${i}`);
|
||||
|
||||
|
||||
const value = await redis.get(testKey(`quick${i}_immediate`));
|
||||
expect(value).toBe(`immediate${i}`);
|
||||
}
|
||||
|
||||
|
||||
expect(redis.connected).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user