Skip to content

Commit eb99ba0

Browse files
committed
test(db/postgres): verify the error handler logs and does not rethrow
Invoke the registered listener with a representative idle-client error and assert it logs via console.error and does not throw, confirming a backend hiccup is swallowed rather than propagated as an uncaught exception.
1 parent edd63c3 commit eb99ba0

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

test/db/postgres/helper.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,24 @@ describe('PostgreSQL - helper', async () => {
117117
});
118118

119119
describe('pool error handling', () => {
120-
it('registers an idle-client error listener on the pool', async () => {
120+
it('registers an idle-client error listener that logs without crashing', async () => {
121121
getDatabaseMock.mockReturnValue({
122122
type: 'postgres',
123123
enabled: true,
124124
connectionString: 'postgresql://localhost/x',
125125
});
126+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined);
126127

127128
await connect();
128129

129130
const errorRegistration = mockPoolOn.mock.calls.find((call) => call[0] === 'error');
130131
expect(errorRegistration).toBeDefined();
132+
133+
const handler = errorRegistration![1] as (err: Error) => void;
134+
expect(() => handler(new Error('connection terminated unexpectedly'))).not.toThrow();
135+
expect(errorSpy).toHaveBeenCalled();
136+
137+
errorSpy.mockRestore();
131138
});
132139
});
133140

0 commit comments

Comments
 (0)