Skip to content

Commit

Permalink
use semaphore to fix test time outs
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Mar 5, 2024
1 parent 085e4f5 commit 777a457
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -63,6 +63,7 @@
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@shopify/semaphore": "^3.0.2",
"@sindresorhus/is": "^6.2.0",
"@sindresorhus/tsconfig": "^5.0.0",
"@types/common-tags": "^1.8.4",
Expand Down Expand Up @@ -116,6 +117,7 @@
"--import=tsimp"
],
"environmentVariables": {
"concurrency": "20",
"TSIMP_DIAG": "ignore"
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/_utils.ts
@@ -1,6 +1,8 @@
/* eslint-disable ava/no-ignored-test-files */
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import {Semaphore} from '@shopify/semaphore';
import {
execa,
type ExecaChildProcess,
Expand Down Expand Up @@ -60,8 +62,12 @@ type VerifyCliMacroArguments = [{
};
}, 'expected' | 'error'>];

const semaphore = new Semaphore(Number(process.env['concurrency']) || 5);

export const _verifyCli = (baseFixture = defaultFixture) => test.macro<VerifyCliMacroArguments>(
async (t, {fixture = baseFixture, args, execaOptions, expected, error}) => {
const permit = await semaphore.acquire();

const assertions = await t.try(async tt => {
const arguments_ = args ? args.split(' ') : [];
const {all: output, exitCode} = await spawnFixture(fixture, arguments_, {reject: false, all: true, ...execaOptions}) as ExecaReturnValue & {all: string};
Expand Down Expand Up @@ -91,5 +97,6 @@ export const _verifyCli = (baseFixture = defaultFixture) => test.macro<VerifyCli
});

assertions.commit({retainLogs: !assertions.passed});
await permit.release();
},
);

0 comments on commit 777a457

Please sign in to comment.