@@ -42,56 +42,16 @@ describe('@web-socket-ratelimiter Shared Rate Limiting Acceptance Tests', functi
4242 registryA = new Registry ( ) ;
4343 registryB = new Registry ( ) ;
4444
45+ // Create Redis stores
46+ const storeA = new RedisRateLimitStore ( redisClient , logger . child ( { service : 'WS-A' } ) , DURATION ) ;
47+ const storeB = new RedisRateLimitStore ( redisClient , logger . child ( { service : 'WS-B' } ) , DURATION ) ;
48+
4549 // Create two IPRateLimiterService instances for WebSocket servers pointing to the same Redis
46- wsServiceA = new IPRateLimiterService ( logger . child ( { service : 'WS-A' } ) , registryA , DURATION ) ;
47- wsServiceB = new IPRateLimiterService ( logger . child ( { service : 'WS-B' } ) , registryB , DURATION ) ;
48-
49- // Wait for Redis connections to establish and verify they're connected
50- let retries = 10 ;
51- while ( retries > 0 ) {
52- const storeA = wsServiceA . rateLimitStore ;
53- const storeB = wsServiceB . rateLimitStore ;
54-
55- // Check if stores are Redis stores before accessing Redis methods
56- if ( storeA instanceof RedisRateLimitStore && storeB instanceof RedisRateLimitStore ) {
57- const connectedA = await storeA . isConnected ( ) ;
58- const connectedB = await storeB . isConnected ( ) ;
59- if ( connectedA && connectedB ) {
60- break ;
61- }
62- } else {
63- // If not Redis stores, just break - LRU stores don't need connection setup
64- break ;
65- }
66- await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
67- retries -- ;
68- }
69-
70- // Verify both WebSocket services are connected to Redis (only if using Redis stores)
71- const storeA = wsServiceA . rateLimitStore ;
72- const storeB = wsServiceB . rateLimitStore ;
73- if ( storeA instanceof RedisRateLimitStore && storeB instanceof RedisRateLimitStore ) {
74- const finalConnectedA = await storeA . isConnected ( ) ;
75- const finalConnectedB = await storeB . isConnected ( ) ;
76- if ( ! finalConnectedA || ! finalConnectedB ) {
77- throw new Error ( `Redis connection failed: wsServiceA=${ finalConnectedA } , wsServiceB=${ finalConnectedB } ` ) ;
78- }
79- }
50+ wsServiceA = new IPRateLimiterService ( storeA , logger . child ( { service : 'WS-A' } ) , registryA ) ;
51+ wsServiceB = new IPRateLimiterService ( storeB , logger . child ( { service : 'WS-B' } ) , registryB ) ;
8052 } ) ;
8153
8254 after ( async function ( ) {
83- // Clean up WebSocket services and Redis connections
84- const storeA = wsServiceA . rateLimitStore ;
85- const storeB = wsServiceB . rateLimitStore ;
86-
87- // Only disconnect if stores are Redis stores
88- if ( storeA instanceof RedisRateLimitStore ) {
89- await storeA . disconnect ( ) ;
90- }
91- if ( storeB instanceof RedisRateLimitStore ) {
92- await storeB . disconnect ( ) ;
93- }
94-
9555 await redisClient . quit ( ) ;
9656
9757 // Clean up environment variables
@@ -108,16 +68,6 @@ describe('@web-socket-ratelimiter Shared Rate Limiting Acceptance Tests', functi
10868
10969 describe ( 'Shared WebSocket Rate Limiting Between Services' , function ( ) {
11070 it ( 'should share rate limit counters between two WebSocket service instances' , async function ( ) {
111- // Verify both WebSocket services are using Redis
112- const storeA = wsServiceA . rateLimitStore ;
113- const storeB = wsServiceB . rateLimitStore ;
114- if ( storeA instanceof RedisRateLimitStore && storeB instanceof RedisRateLimitStore ) {
115- const redisA = await storeA . isConnected ( ) ;
116- const redisB = await storeB . isConnected ( ) ;
117- expect ( redisA ) . to . be . true ;
118- expect ( redisB ) . to . be . true ;
119- }
120-
12171 let rateLimited = false ;
12272
12373 // Make exactly LIMIT requests through wsServiceA to hit the limit
@@ -280,18 +230,6 @@ describe('@web-socket-ratelimiter Shared Rate Limiting Acceptance Tests', functi
280230 } ) ;
281231
282232 describe ( 'WebSocket Service Independence and Failover' , function ( ) {
283- it ( 'should maintain independent Redis connections for WebSocket services' , async function ( ) {
284- // Both WebSocket services should report connected to Redis
285- const storeA = wsServiceA . rateLimitStore ;
286- const storeB = wsServiceB . rateLimitStore ;
287- if ( storeA instanceof RedisRateLimitStore && storeB instanceof RedisRateLimitStore ) {
288- const connectedA = await storeA . isConnected ( ) ;
289- const connectedB = await storeB . isConnected ( ) ;
290- expect ( connectedA ) . to . be . true ;
291- expect ( connectedB ) . to . be . true ;
292- }
293- } ) ;
294-
295233 it ( 'should handle concurrent WebSocket requests from both services' , async function ( ) {
296234 // Send concurrent requests from both WebSocket services
297235 const promises : Promise < boolean > [ ] = [ ] ;
0 commit comments