|
| 1 | +import { promiseError } from '@kwsites/promise-result'; |
| 2 | +import { |
| 3 | + assertGitError, |
| 4 | + createAbortController, |
| 5 | + createTestContext, |
| 6 | + newSimpleGit, |
| 7 | + SimpleGitTestContext, |
| 8 | + wait, |
| 9 | +} from '@simple-git/test-utils'; |
| 10 | + |
| 11 | +import { GitPluginError } from '../..'; |
| 12 | + |
| 13 | +describe('timeout', () => { |
| 14 | + let context: SimpleGitTestContext; |
| 15 | + |
| 16 | + beforeEach(async () => (context = await createTestContext())); |
| 17 | + |
| 18 | + it('kills processes on abort signal', async () => { |
| 19 | + const { controller, abort } = createAbortController(); |
| 20 | + |
| 21 | + const threw = promiseError(newSimpleGit(context.root, { abort }).init()); |
| 22 | + |
| 23 | + await wait(0); |
| 24 | + controller.abort(); |
| 25 | + |
| 26 | + assertGitError(await threw, 'Abort signal received', GitPluginError); |
| 27 | + }); |
| 28 | + |
| 29 | + it('share AbortController across many instances', async () => { |
| 30 | + const { controller, abort } = createAbortController(); |
| 31 | + const upstream = await newSimpleGit(__dirname).revparse('--git-dir'); |
| 32 | + |
| 33 | + const repos = await Promise.all('abcdef'.split('').map((p) => context.dir(p))); |
| 34 | + |
| 35 | + await Promise.all( |
| 36 | + repos.map((baseDir) => { |
| 37 | + const git = newSimpleGit({ baseDir, abort }); |
| 38 | + if (baseDir.endsWith('a')) { |
| 39 | + return promiseError(git.init().then(() => controller.abort())); |
| 40 | + } |
| 41 | + |
| 42 | + return promiseError(git.clone(upstream, baseDir)); |
| 43 | + }) |
| 44 | + ); |
| 45 | + |
| 46 | + const results = await Promise.all( |
| 47 | + repos.map((baseDir) => newSimpleGit(baseDir).checkIsRepo()) |
| 48 | + ); |
| 49 | + |
| 50 | + expect(results).toContain(false); |
| 51 | + expect(results).toContain(true); |
| 52 | + }); |
| 53 | +}); |
0 commit comments