Skip to content

Commit 2f29297

Browse files
authored
Improve macOS integration test performance (#727)
1 parent 43fdd22 commit 2f29297

File tree

5 files changed

+88
-58
lines changed

5 files changed

+88
-58
lines changed

packages/core/integration-tests/test/cache.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {deserialize} from '@atlaspack/build-cache';
4040
import {hashString} from '@atlaspack/rust';
4141
import {getAllEnvironments} from '@atlaspack/rust';
4242
import type {FeatureFlags} from '@atlaspack/feature-flags';
43+
import os from 'os';
4344

4445
let inputDir: string;
4546
let packageManager = new NodePackageManager(inputFS, '/');
@@ -56,6 +57,7 @@ let packageManager = new NodePackageManager(inputFS, '/');
5657
{
5758
inputFS: overlayFS,
5859
shouldDisableCache: false,
60+
watchBackend: os.platform() === 'darwin' ? 'fs-events' : undefined,
5961
featureFlags: {
6062
...featureFlags,
6163
cachePerformanceImprovements,

packages/core/test-utils/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@
2424
"@atlaspack/fs": "2.15.16",
2525
"@atlaspack/package-manager": "2.14.21",
2626
"@atlaspack/utils": "2.17.3",
27+
"async": "^3.2.6",
2728
"chalk": "^4.1.0",
2829
"expect": "^29.7.0",
2930
"ncp": "^2.0.0",
3031
"nullthrows": "^1.1.1",
3132
"posthtml": "^0.16.5",
3233
"posthtml-parser": "^0.10.1",
3334
"resolve": "^1.12.0",
35+
"rimraf": "^5.0.5",
3436
"ws": "^7.0.0",
37+
"@types/async": "^3.2.6",
3538
"tempy": "^1.0.0",
3639
"why-is-node-running": "^3.2.2"
3740
}

packages/core/test-utils/src/utils.ts

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {LMDBLiteCache} from '@atlaspack/cache';
4040
import tempy from 'tempy';
4141
import {FILE_CONFIG_NO_REPORTERS} from './paths';
4242

43+
import {queue} from 'async';
44+
4345
export let cacheDir: string = tempy.directory();
4446
export let cache: LMDBLiteCache = new LMDBLiteCache(cacheDir);
4547
cache.ensure();
@@ -1328,6 +1330,52 @@ export async function assertNoFilePathInCache(
13281330
fs: FileSystem,
13291331
dir: string,
13301332
projectRoot: string,
1333+
) {
1334+
// For debugging purposes, log all instances of the projectRoot in the cache.
1335+
// Otherwise, fail the test if one is found.
1336+
if (process.env.ATLASPACK_DEBUG_CACHE_FILEPATH != null)
1337+
return assertNoFilePathInCacheDebug(fs, dir, projectRoot);
1338+
1339+
const processFile = async (filePath: string) => {
1340+
let contents = await fs.readFile(filePath);
1341+
if (contents.includes(projectRoot)) {
1342+
throw new Error(
1343+
`Found projectRoot ${projectRoot} in cache file ${filePath}`,
1344+
);
1345+
}
1346+
};
1347+
// This "optimal" concurrency value was determined by using hyperfine locally on a subset of tests
1348+
// that use the cache.
1349+
const q = queue(processFile, 50);
1350+
1351+
const queueDir = async (dir: string) => {
1352+
const files = await fs.readdir(dir);
1353+
for (const file of files) {
1354+
const fullPath = path.join(dir, file);
1355+
const stat = await fs.stat(fullPath);
1356+
if (stat.isFile() && !file.endsWith('.txt')) {
1357+
q.push(fullPath);
1358+
} else if (stat.isDirectory()) {
1359+
await queueDir(fullPath);
1360+
}
1361+
}
1362+
};
1363+
await queueDir(dir);
1364+
1365+
q.error((err: Error) => {
1366+
assert.fail(err);
1367+
});
1368+
if (q.length() > 0) {
1369+
await q.drain();
1370+
}
1371+
}
1372+
1373+
// This function is called from the assertNoFilePathInCache function when the
1374+
// ATLASPACK_DEBUG_CACHE_FILEPATH environment variable is set.
1375+
async function assertNoFilePathInCacheDebug(
1376+
fs: FileSystem,
1377+
dir: string,
1378+
projectRoot: string,
13311379
) {
13321380
let entries = await fs.readdir(dir);
13331381
for (let entry of entries) {
@@ -1343,38 +1391,29 @@ export async function assertNoFilePathInCache(
13431391
} else if (stat.isFile()) {
13441392
let contents = await fs.readFile(fullPath);
13451393

1346-
// For debugging purposes, log all instances of the projectRoot in the cache.
1347-
// Otherwise, fail the test if one is found.
1348-
if (process.env.ATLASPACK_DEBUG_CACHE_FILEPATH != null) {
1349-
if (contents.includes(projectRoot)) {
1350-
let deserialized;
1351-
try {
1352-
deserialized = v8.deserialize(contents);
1353-
} catch (err: any) {
1354-
// rudimentary detection of binary files
1355-
if (!contents.includes(0)) {
1356-
deserialized = contents.toString();
1357-
} else {
1358-
deserialized = contents;
1359-
}
1394+
if (contents.includes(projectRoot)) {
1395+
let deserialized;
1396+
try {
1397+
deserialized = v8.deserialize(contents);
1398+
} catch (err: any) {
1399+
// rudimentary detection of binary files
1400+
if (!contents.includes(0)) {
1401+
deserialized = contents.toString();
1402+
} else {
1403+
deserialized = contents;
13601404
}
1405+
}
13611406

1362-
if (deserialized != null) {
1363-
// eslint-disable-next-line no-console
1364-
console.log(
1365-
`Found projectRoot ${projectRoot} in cache file ${fullPath}`,
1366-
);
1367-
// eslint-disable-next-line no-console
1368-
console.log(
1369-
require('util').inspect(deserialized, {depth: 50, colors: true}),
1370-
);
1371-
}
1407+
if (deserialized != null) {
1408+
// eslint-disable-next-line no-console
1409+
console.log(
1410+
`Found projectRoot ${projectRoot} in cache file ${fullPath}`,
1411+
);
1412+
// eslint-disable-next-line no-console
1413+
console.log(
1414+
require('util').inspect(deserialized, {depth: 50, colors: true}),
1415+
);
13721416
}
1373-
} else {
1374-
assert(
1375-
!contents.includes(projectRoot),
1376-
`Found projectRoot ${projectRoot} in cache file ${fullPath}`,
1377-
);
13781417
}
13791418
}
13801419
}

packages/dev/mocha-profiler/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Profile mocha tests",
55
"license": "(MIT OR Apache-2.0)",
66
"private": true,
7-
"main": "src/index.js",
7+
"main": "./lib/index.js",
8+
"source": "./src/index.ts",
89
"repository": {
910
"type": "git",
1011
"url": "https://github.com/atlassian-labs/atlaspack.git"

yarn.lock

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4047,6 +4047,11 @@
40474047
dependencies:
40484048
tslib "^2.4.0"
40494049

4050+
"@types/async@^3.2.6":
4051+
version "3.2.24"
4052+
resolved "https://registry.yarnpkg.com/@types/async/-/async-3.2.24.tgz#3a96351047575bbcf2340541b2d955a35339608f"
4053+
integrity sha512-8iHVLHsCCOBKjCF2KwFe0p9Z3rfM9mL+sSP8btyR5vTjJRAqpBYD28/ZLgXPf0pjG1VxOvtCV/BgXkQbpSe8Hw==
4054+
40504055
"@types/babel__core@*", "@types/babel__core@^7.12.2":
40514056
version "7.20.5"
40524057
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.20.5.tgz#3df15f27ba85319caa07ba08d0721889bb39c017"
@@ -5364,6 +5369,11 @@ async@^3.2.3:
53645369
resolved "https://registry.yarnpkg.com/async/-/async-3.2.5.tgz#ebd52a8fdaf7a2289a24df399f8d8485c8a46b66"
53655370
integrity sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==
53665371

5372+
async@^3.2.6:
5373+
version "3.2.6"
5374+
resolved "https://registry.yarnpkg.com/async/-/async-3.2.6.tgz#1b0728e14929d51b85b449b7f06e27c1145e38ce"
5375+
integrity sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==
5376+
53675377
asynckit@^0.4.0:
53685378
version "0.4.0"
53695379
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
@@ -16465,7 +16475,7 @@ string-natural-compare@^3.0.1:
1646516475
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
1646616476
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==
1646716477

16468-
"string-width-cjs@npm:string-width@^4.2.0":
16478+
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
1646916479
version "4.2.3"
1647016480
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1647116481
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -16491,15 +16501,6 @@ string-width@^1.0.1, string-width@^1.0.2:
1649116501
is-fullwidth-code-point "^2.0.0"
1649216502
strip-ansi "^4.0.0"
1649316503

16494-
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
16495-
version "4.2.3"
16496-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
16497-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
16498-
dependencies:
16499-
emoji-regex "^8.0.0"
16500-
is-fullwidth-code-point "^3.0.0"
16501-
strip-ansi "^6.0.1"
16502-
1650316504
string-width@^5.0.1, string-width@^5.1.2:
1650416505
version "5.1.2"
1650516506
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
@@ -16587,7 +16588,7 @@ stringify-object@^3.3.0:
1658716588
is-obj "^1.0.1"
1658816589
is-regexp "^1.0.0"
1658916590

16590-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
16591+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1659116592
version "6.0.1"
1659216593
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1659316594
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -16608,13 +16609,6 @@ strip-ansi@^4.0.0:
1660816609
dependencies:
1660916610
ansi-regex "^3.0.0"
1661016611

16611-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
16612-
version "6.0.1"
16613-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
16614-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
16615-
dependencies:
16616-
ansi-regex "^5.0.1"
16617-
1661816612
strip-ansi@^7.0.1, strip-ansi@^7.1.0:
1661916613
version "7.1.0"
1662016614
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -18246,7 +18240,7 @@ [email protected]:
1824618240
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.1.0.tgz#a8e038b4c94569596852de7a8ea4228eefdeb37b"
1824718241
integrity sha512-toV7q9rWNYha963Pl/qyeZ6wG+3nnsyvolaNUS8+R5Wtw6qJPTxIlOP1ZSvcGhEJw+l3HMMmtiNo9Gl61G4GVg==
1824818242

18249-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
18243+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1825018244
version "7.0.0"
1825118245
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1825218246
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -18272,15 +18266,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
1827218266
string-width "^4.1.0"
1827318267
strip-ansi "^6.0.0"
1827418268

18275-
wrap-ansi@^7.0.0:
18276-
version "7.0.0"
18277-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
18278-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
18279-
dependencies:
18280-
ansi-styles "^4.0.0"
18281-
string-width "^4.1.0"
18282-
strip-ansi "^6.0.0"
18283-
1828418269
wrap-ansi@^8.1.0:
1828518270
version "8.1.0"
1828618271
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)