Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.1 KB
Raw Blame
import { RedisConnectionConfig, RedisPoolComponent } from './redis'

const giveUpBeforeErrorLimit = (attempt: number): number | null => (attempt < 5 ? 25 : null)

const unreachableRedis = (overrides: Partial<RedisConnectionConfig>): RedisConnectionConfig => ({
    url: '127.0.0.1',
    options: { port: 1, commandTimeout: 100, retryStrategy: giveUpBeforeErrorLimit },
    name: 'unreachable-test',
    ...overrides,
})

describe('RedisPoolComponent', () => {
    it('fails to start when Redis is unreachable', async () => {
        const component = new RedisPoolComponent({
            connection: unreachableRedis({}),
            poolMinSize: 1,
            poolMaxSize: 1,
            acquireTimeoutMillis: 200,
        })

        await expect(component.start()).rejects.toThrow()
    })

    it('starts a non-fatal pool when Redis is unreachable', async () => {
        const component = new RedisPoolComponent({
            connection: unreachableRedis({ exitOnRepeatedErrors: false }),
            poolMinSize: 1,
            poolMaxSize: 1,
        })

        const started = await component.start()
        await started.stop()
    })
})