Skip to content

Commit 70e6107

Browse files
committed
refactor: Simplify Redis integration tests by removing unnecessary connection checks and streamlining sendCommandCluster implementation
1 parent ae43273 commit 70e6107

File tree

1 file changed

+6
-67
lines changed

1 file changed

+6
-67
lines changed

test/redis-integration-test.ts

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,14 @@ describe('Redis Integration Tests', () => {
2525
port,
2626
lazyConnect: true,
2727
})
28-
await client.connect().catch(() => {
29-
console.warn('Skipping Redis tests - connection failed')
30-
})
28+
await client.connect()
3129
})
3230

3331
afterAll(async () => {
3432
await client?.quit()
3533
})
3634

3735
it('should work with sendCommand', async () => {
38-
if (client.status !== 'ready') {
39-
console.warn('Redis not ready, skipping test')
40-
return
41-
}
42-
4336
store = new RedisStore({
4437
async sendCommand(...args: string[]) {
4538
const result = await client.call(args[0], ...args.slice(1))
@@ -63,8 +56,6 @@ describe('Redis Integration Tests', () => {
6356
})
6457

6558
it('should work with decrement', async () => {
66-
if (client.status !== 'ready') return
67-
6859
const key = 'test-single-decr'
6960
await store.resetKey(key)
7061

@@ -77,8 +68,6 @@ describe('Redis Integration Tests', () => {
7768
})
7869

7970
it('should work with get', async () => {
80-
if (client.status !== 'ready') return
81-
8271
const key = 'test-single-get'
8372
await store.resetKey(key)
8473

@@ -90,8 +79,6 @@ describe('Redis Integration Tests', () => {
9079
})
9180

9281
it('should handle TTL correctly', async () => {
93-
if (client.status !== 'ready') return
94-
9582
const key = 'test-single-ttl'
9683
// Initialize with short window
9784
const shortStore = new RedisStore({
@@ -128,43 +115,17 @@ describe('Redis Integration Tests', () => {
128115
clusterRetryStrategy: () => null,
129116
lazyConnect: true,
130117
})
131-
try {
132-
await client.connect()
133-
} catch {
134-
console.warn('Skipping Redis Cluster tests - connection failed')
135-
}
118+
await client.connect()
136119
})
137120

138121
afterAll(async () => {
139122
await client?.quit()
140123
})
141124

142125
it('should work with sendCommandCluster', async () => {
143-
if (client.status !== 'ready') {
144-
console.warn('Redis Cluster not ready, skipping test')
145-
return
146-
}
147-
148126
store = new RedisStore({
149-
async sendCommandCluster(details: SendCommandClusterDetails) {
150-
const { command } = details
151-
152-
// If SCRIPT LOAD, send to all master nodes
153-
if (command[0] === 'SCRIPT' && command[1] === 'LOAD') {
154-
const nodes = client.nodes('master')
155-
await Promise.all(
156-
nodes.map(async (node) =>
157-
node.call(command[0], ...command.slice(1)),
158-
),
159-
)
160-
// Return the result from one of them (they should be identical)
161-
const result = await client.call(command[0], ...command.slice(1))
162-
return result as RedisReply
163-
}
164-
165-
const result = await client.call(command[0], ...command.slice(1))
166-
return result as RedisReply
167-
},
127+
sendCommandCluster: async (details: SendCommandClusterDetails) =>
128+
client.call(details.command[0], ...details.command.slice(1)),
168129
} as RedisOptions)
169130
store.init({ windowMs: 1000 } as RateLimitOptions)
170131

@@ -183,8 +144,6 @@ describe('Redis Integration Tests', () => {
183144
})
184145

185146
it('should work with decrement', async () => {
186-
if (client.status !== 'ready') return
187-
188147
const key = 'test-cluster-decr'
189148
await store.resetKey(key)
190149

@@ -197,8 +156,6 @@ describe('Redis Integration Tests', () => {
197156
})
198157

199158
it('should work with get', async () => {
200-
if (client.status !== 'ready') return
201-
202159
const key = 'test-cluster-get'
203160
await store.resetKey(key)
204161

@@ -210,29 +167,11 @@ describe('Redis Integration Tests', () => {
210167
})
211168

212169
it('should handle TTL correctly', async () => {
213-
if (client.status !== 'ready') return
214-
215170
const key = 'test-cluster-ttl'
216171
// Initialize with short window
217172
const shortStore = new RedisStore({
218-
async sendCommandCluster(details: SendCommandClusterDetails) {
219-
const { command } = details
220-
221-
// If SCRIPT LOAD, send to all master nodes
222-
if (command[0] === 'SCRIPT' && command[1] === 'LOAD') {
223-
const nodes = client.nodes('master')
224-
await Promise.all(
225-
nodes.map(async (node) =>
226-
node.call(command[0], ...command.slice(1)),
227-
),
228-
)
229-
const result = await client.call(command[0], ...command.slice(1))
230-
return result as RedisReply
231-
}
232-
233-
const result = await client.call(command[0], ...command.slice(1))
234-
return result as RedisReply
235-
},
173+
sendCommandCluster: async (details: SendCommandClusterDetails) =>
174+
client.call(details.command[0], ...details.command.slice(1)),
236175
} as RedisOptions)
237176
shortStore.init({ windowMs: 1000 } as RateLimitOptions)
238177

0 commit comments

Comments
 (0)