Skip to content

Commit

Permalink
chore: allow opt-out of test.concurrent in integ tests (#19402)
Browse files Browse the repository at this point in the history
The `test.concurrent` feature of `jest` immediately executes the test
code in order to obtain a `Promise` that is checked as part of the test
run.

This means that the test handler code runs whether the test is included
or not in the assessment, as controlled by the `-t` flag of jest.

In order to allow integration tests to selectively run only a subset of
the tests, we must hence not use `test.concurrent`, or else all test
handlers run fully, leading to unwanted side effects.

This is needed in order to be able to complete cdklabs/cdk-ops#1922.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
RomainMuller committed Mar 15, 2022
1 parent e63a03d commit 3866213
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/integ/cli/cli.integtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { retry, sleep } from '../helpers/aws';
import { cloneDirectory, MAJOR_VERSION, shell, withDefaultFixture } from '../helpers/cdk';
import { integTest } from '../helpers/test-helpers';

jest.setTimeout(600 * 1000);
jest.setTimeout(600_000);

integTest('VPC Lookup', withDefaultFixture(async (fixture) => {
fixture.log('Making sure we are clean before starting.');
Expand Down
8 changes: 6 additions & 2 deletions packages/aws-cdk/test/integ/helpers/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export function integTest(
) {

// Integ tests can run concurrently, and are responsible for blocking themselves if they cannot.
const runner = shouldSkip(name) ? test.skip : test.concurrent;
// Because `test.concurrent` executes the test code immediately (to obtain a promise), we allow
// setting the `JEST_TEST_CONCURRENT` environment variable to 'false' in order to use `test`
// instead of `test.concurrent` (this is necessary when specifying a test pattern to verify).
const testKind = process.env.JEST_TEST_CONCURRENT === 'false' ? test : test.concurrent;
const runner = shouldSkip(name) ? testKind.skip : testKind;

runner(name, async () => {
const output = new MemoryStream();
Expand Down Expand Up @@ -44,4 +48,4 @@ export function integTest(

function shouldSkip(testName: string) {
return SKIP_TESTS.includes(testName);
}
}
25 changes: 22 additions & 3 deletions packages/aws-cdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,33 @@
"resolveJsonModule": true,
"composite": true,
"incremental": true
},
},
"include": [
"**/*.ts",
"**/*.d.ts",
"lib/init-templates/**/add-project.hook.ts"
],
"exclude": [
"lib/init-templates/**/typescript/**/*.ts"
]
],
"references": [
{
"path": "../@aws-cdk/cloud-assembly-schema"
},
{
"path": "../@aws-cdk/cloudformation-diff"
},
{
"path": "../@aws-cdk/core"
},
{
"path": "../@aws-cdk/cx-api"
},
{
"path": "../@aws-cdk/region-info"
},
{
"path": "../cdk-assets"
},
],
}

0 comments on commit 3866213

Please sign in to comment.