• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-client-gateway / 12595573134

03 Jan 2025 09:26AM UTC coverage: 89.902% (-0.2%) from 90.126%
12595573134

Pull #2232

github

web-flow
Merge c1013c948 into 48e5bc4de
Pull Request #2232: Add Timeout to Redis Queries and Handle Client Unavailability Gracefully

2856 of 3561 branches covered (80.2%)

Branch coverage included in aggregate %.

39 of 70 new or added lines in 6 files covered. (55.71%)

12 existing lines in 2 files now uncovered.

9679 of 10382 relevant lines covered (93.23%)

436.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/src/datasources/cache/cache.module.ts
1
import { Global, Module } from '@nestjs/common';
118✔
2
import { createClient } from 'redis';
118✔
3
import { IConfigurationService } from '@/config/configuration.service.interface';
118✔
4
import { CacheService } from '@/datasources/cache/cache.service.interface';
118✔
5
import { RedisCacheService } from '@/datasources/cache/redis.cache.service';
118✔
6
import { CacheReadiness } from '@/domain/interfaces/cache-readiness.interface';
118✔
7
import { ILoggingService, LoggingService } from '@/logging/logging.interface';
118✔
8
import { CacheKeyPrefix } from '@/datasources/cache/constants';
118✔
9
import {
118✔
10
  PromiseTimeoutError,
11
  promiseWithTimeout,
12
} from '@/domain/common/utils/promise';
13

14
export type RedisClientType = ReturnType<typeof createClient>;
15

16
async function redisClientFactory(
17
  configurationService: IConfigurationService,
18
  loggingService: ILoggingService,
19
): Promise<RedisClientType> {
20
  const redisHost = configurationService.getOrThrow<string>('redis.host');
20✔
21
  const redisPort = configurationService.getOrThrow<string>('redis.port');
20✔
22
  const redisTimeout = configurationService.getOrThrow<number>('redis.timeout');
20✔
23
  const client: RedisClientType = createClient({
20✔
24
    url: `redis://${redisHost}:${redisPort}`,
25
  });
26
  client.on('error', (err) =>
20✔
27
    loggingService.error(`Redis client error: ${err}`),
×
28
  );
29
  client.on('end', () => {
20✔
30
    loggingService.error('Redis client terminated!');
20✔
31
  });
32
  try {
20✔
33
    await promiseWithTimeout(client.connect(), redisTimeout);
20✔
34
  } catch (error) {
NEW
UNCOV
35
    if (error instanceof PromiseTimeoutError) {
×
NEW
36
      loggingService.error('Redis connect timed out!');
×
37
    }
38
  }
39
  return client;
20✔
40
}
41

42
@Global()
43
@Module({
44
  providers: [
45
    {
46
      provide: 'RedisClient',
47
      useFactory: redisClientFactory,
48
      inject: [IConfigurationService, LoggingService],
49
    },
50
    { provide: CacheService, useClass: RedisCacheService },
51
    { provide: CacheReadiness, useExisting: CacheService },
52
    { provide: CacheKeyPrefix, useValue: '' },
53
  ],
54
  exports: [CacheService, CacheReadiness],
55
})
56
export class CacheModule {}
118✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc