Unverified Commit e2dce63f authored by dan's avatar dan Committed by GitHub

[test] Unflake more tests (#96081)

- `detectContentType` test was too aggressive about asserting completion
in 1ms, let's give it several tries.
- We weren't correctly setting up pnpm overrides in tests, which breaks
things whenever canary comes out.
parent f2ce9d4b
...@@ -110,6 +110,36 @@ async function applyInstallSecuritySettings(installDir, isolationRoot) { ...@@ -110,6 +110,36 @@ async function applyInstallSecuritySettings(installDir, isolationRoot) {
} }
} }
/**
* pnpm only honors overrides at the workspace root, so they go into the
* `pnpm-workspace.yaml` that governs the install.
*
* @param {string} installDir
* @param {string} isolationRoot
* @param {Record<string, string>} overrides
* @returns {Promise<void>}
*/
async function applyWorkspaceOverrides(installDir, isolationRoot, overrides) {
const workspaceFile = await findConfigFile(
'pnpm-workspace.yaml',
installDir,
isolationRoot
)
if (workspaceFile === null) {
return
}
const workspaceConfig =
/** @type {Record<string, any>} */ (
yaml.load(await fs.readFile(workspaceFile, 'utf8'))
) ?? {}
workspaceConfig.overrides = {
...overrides,
...(workspaceConfig.overrides || {}),
}
await fs.writeFile(workspaceFile, yaml.dump(workspaceConfig))
}
/** /**
* *
* @param {object} param0 * @param {object} param0
...@@ -276,13 +306,6 @@ async function createNextInstall({ ...@@ -276,13 +306,6 @@ async function createNextInstall({
...workspacePkgOverrides, ...workspacePkgOverrides,
...(packageJson.overrides || {}), ...(packageJson.overrides || {}),
}, },
pnpm: {
...(packageJson.pnpm || {}),
overrides: {
...workspacePkgOverrides,
...(packageJson.pnpm?.overrides || {}),
},
},
resolutions: { resolutions: {
...workspacePkgOverrides, ...workspacePkgOverrides,
...(resolutions || {}), ...(resolutions || {}),
...@@ -311,6 +334,10 @@ async function createNextInstall({ ...@@ -311,6 +334,10 @@ async function createNextInstall({
: null : null
await applyInstallSecuritySettings(installDir, isolationRoot) await applyInstallSecuritySettings(installDir, isolationRoot)
await applyWorkspaceOverrides(installDir, isolationRoot, {
...workspacePkgOverrides,
...(resolutions || {}),
})
if (installString !== null) { if (installString !== null) {
console.log('running install command', installString) console.log('running install command', installString)
...@@ -324,6 +351,23 @@ async function createNextInstall({ ...@@ -324,6 +351,23 @@ async function createNextInstall({
await rootSpan await rootSpan
.traceChild('run generic install command', combinedDependencies) .traceChild('run generic install command', combinedDependencies)
.traceAsyncFn(() => installDependencies(installDir, tmpDir)) .traceAsyncFn(() => installDependencies(installDir, tmpDir))
// `@next/env` is a dependency of `next`, so it only resolves to the
// local tarball if the overrides were applied.
if (!combinedDependencies['@next/env']) {
const envDir = await fs.realpath(
path.join(
await fs.realpath(path.join(installDir, 'node_modules/next')),
'../@next/env'
)
)
if (!envDir.includes('@next+env@file')) {
throw new Error(
`@next/env resolved from the npm registry instead of the local tarball (${envDir}), ` +
'the workspace overrides were not applied to the install'
)
}
}
} }
if (useRspack) { if (useRspack) {
......
...@@ -92,18 +92,10 @@ describe('ci-missing-typescript-deps', () => { ...@@ -92,18 +92,10 @@ describe('ci-missing-typescript-deps', () => {
'@types/react': 'npm:types-react@beta', '@types/react': 'npm:types-react@beta',
'@types/react-dom': 'npm:types-react-dom@beta', '@types/react-dom': 'npm:types-react-dom@beta',
}, },
packageJson: { resolutions: {
overrides: {
'@types/react': 'npm:types-react@beta', '@types/react': 'npm:types-react@beta',
'@types/react-dom': 'npm:types-react-dom@beta', '@types/react-dom': 'npm:types-react-dom@beta',
}, },
pnpm: {
overrides: {
'@types/react': 'npm:types-react@beta',
'@types/react-dom': 'npm:types-react-dom@beta',
},
},
},
}) })
it('should not throw an error if beta version of @types/react and @types/react-dom is installed', async () => { it('should not throw an error if beta version of @types/react and @types/react-dom is installed', async () => {
......
...@@ -5,7 +5,7 @@ import { join } from 'path' ...@@ -5,7 +5,7 @@ import { join } from 'path'
const getImage = (filepath: string) => readFile(join(__dirname, filepath)) const getImage = (filepath: string) => readFile(join(__dirname, filepath))
const detectContentType = async (buffer: Buffer, isRetry = false) => { const detectContentType = async (buffer: Buffer, attempt = 0) => {
let maxBlockedMs = 0 let maxBlockedMs = 0
let lastTick = performance.now() let lastTick = performance.now()
let running = true let running = true
...@@ -25,13 +25,14 @@ const detectContentType = async (buffer: Buffer, isRetry = false) => { ...@@ -25,13 +25,14 @@ const detectContentType = async (buffer: Buffer, isRetry = false) => {
maxBlockedMs = Math.max(maxBlockedMs, performance.now() - lastTick) maxBlockedMs = Math.max(maxBlockedMs, performance.now() - lastTick)
if (maxBlockedMs > 1) { if (maxBlockedMs > 1) {
if (isRetry) { // The sampled gaps also include JIT warmup and scheduler noise; a real
// regression (GHSA-q8wf-6r8g-63ch) fails every attempt.
if (attempt >= 4) {
throw new Error( throw new Error(
`detectContentType blocked the event loop for ${maxBlockedMs.toFixed(1)}ms` `detectContentType blocked the event loop for ${maxBlockedMs.toFixed(1)}ms`
) )
} else { } else {
// try again because the first run after compile can be slow due to JIT optimizations return await detectContentType(buffer, attempt + 1)
return await detectContentType(buffer, true)
} }
} }
return result return result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment