|
| 1 | +import { DEFAULT_REQUEST_TIMEOUT } from '@segment/actions-core' |
1 | 2 | import { normalizeSSHKey, testSFTPConnection, uploadSFTP } from '../client' |
2 | 3 | import { SFTP_DEFAULT_PORT } from '../constants' |
3 | 4 | import { Settings } from '../generated-types' |
@@ -309,6 +310,7 @@ MIIEpAIBAAKCAQEA1234567890 |
309 | 310 |
|
310 | 311 | describe('testSFTPConnection', () => { |
311 | 312 | beforeEach(() => { |
| 313 | + jest.useRealTimers() |
312 | 314 | jest.clearAllMocks() |
313 | 315 | jest.clearAllTimers() |
314 | 316 | }) |
|
440 | 442 | expect(Client.prototype.end).toHaveBeenCalled() |
441 | 443 | }) |
442 | 444 |
|
443 | | - // This test is skipped because it can slow down the CI |
444 | | - it.skip('should throw timeout error when operation takes too long', async () => { |
| 445 | + it('should throw timeout error when operation takes too long', async () => { |
| 446 | + jest.useFakeTimers() |
445 | 447 | Client.prototype.connect = jest.fn().mockImplementation(() => new Promise((r) => setTimeout(r, 11500))) |
446 | 448 | Client.prototype.list = jest.fn().mockResolvedValue([]) |
447 | 449 | Client.prototype.end = jest.fn().mockResolvedValue(undefined) |
448 | 450 |
|
449 | | - await expect(testSFTPConnection(passwordSettings)).rejects.toThrow( |
450 | | - 'Request timed out before receiving a response' |
451 | | - ) |
452 | | - }, 12000) |
| 451 | + // Start the async operation |
| 452 | + const promise = testSFTPConnection(passwordSettings) |
| 453 | + |
| 454 | + // Advance timers to trigger the timeout |
| 455 | + jest.advanceTimersByTime(DEFAULT_REQUEST_TIMEOUT) |
| 456 | + |
| 457 | + await expect(promise).rejects.toThrow('SFTP connection timed out') |
| 458 | + }) |
453 | 459 |
|
454 | 460 | it('should handle connection errors with cleanup', async () => { |
455 | 461 | const connectionError = new Error('Connection refused') |
|
0 commit comments