-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor performance tests artifacts handling #48684
Changes from all commits
dff85c2
2c67257
9d2ecae
880bc3e
e23254e
d8f7333
68adfa4
64e887c
79dc881
2593a77
b3ab0ee
335621a
ef428f4
f2e31bd
27c4c02
f33b7aa
23ea28f
7f0a37b
5861137
ad0e335
a844c86
315ec21
c8b652d
4538099
7b1b36c
8ac8690
7fd97d8
7c86fa4
5751774
23b445c
a53065b
1d2cc88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ const { | |
} = require( '../lib/utils' ); | ||
const config = require( '../config' ); | ||
|
||
const ARTIFACTS_PATH = | ||
process.env.WP_ARTIFACTS_PATH || path.join( process.cwd(), 'artifacts' ); | ||
|
||
/** | ||
* @typedef WPPerformanceCommandOptions | ||
* | ||
|
@@ -193,38 +196,22 @@ function curateResults( testSuite, results ) { | |
* @return {Promise<WPPerformanceResults>} Performance results for the branch. | ||
*/ | ||
async function runTestSuite( testSuite, performanceTestDirectory, runKey ) { | ||
try { | ||
await runShellScript( | ||
`npm run test:performance -- packages/e2e-tests/specs/performance/${ testSuite }.test.js`, | ||
performanceTestDirectory | ||
); | ||
} catch ( error ) { | ||
fs.mkdirSync( './__test-results/artifacts', { recursive: true } ); | ||
const artifactsFolder = path.join( | ||
performanceTestDirectory, | ||
'artifacts/' | ||
); | ||
await runShellScript( | ||
'cp -Rv ' + artifactsFolder + ' ' + './__test-results/artifacts/' | ||
); | ||
|
||
throw error; | ||
} | ||
const resultsFilename = `${ runKey }.performance-results.json`; | ||
|
||
const resultsFile = path.join( | ||
await runShellScript( | ||
`npm run test:performance -- ${ testSuite }`, | ||
performanceTestDirectory, | ||
`packages/e2e-tests/specs/performance/${ testSuite }.test.results.json` | ||
); | ||
fs.mkdirSync( './__test-results', { recursive: true } ); | ||
fs.copyFileSync( resultsFile, `./__test-results/${ runKey }.results.json` ); | ||
const rawResults = await readJSONFile( | ||
path.join( | ||
performanceTestDirectory, | ||
`packages/e2e-tests/specs/performance/${ testSuite }.test.results.json` | ||
) | ||
{ | ||
...process.env, | ||
WP_ARTIFACTS_PATH: ARTIFACTS_PATH, | ||
RESULTS_FILENAME: resultsFilename, | ||
} | ||
); | ||
|
||
return curateResults( testSuite, rawResults ); | ||
return curateResults( | ||
testSuite, | ||
await readJSONFile( path.join( ARTIFACTS_PATH, resultsFilename ) ) | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -339,15 +326,41 @@ async function runPerformanceTests( branches, options ) { | |
buildPath | ||
); | ||
|
||
await runShellScript( | ||
'cp ' + | ||
path.resolve( | ||
performanceTestDirectory, | ||
'bin/plugin/utils/.wp-env.performance.json' | ||
) + | ||
' ' + | ||
environmentDirectory + | ||
'/.wp-env.json' | ||
// Create the config file for the current env. | ||
fs.writeFileSync( | ||
path.join( environmentDirectory, '.wp-env.json' ), | ||
JSON.stringify( | ||
{ | ||
core: 'WordPress/WordPress', | ||
plugins: [ path.join( environmentDirectory, 'plugin' ) ], | ||
themes: [ | ||
path.join( | ||
performanceTestDirectory, | ||
'test/emptytheme' | ||
), | ||
'https://downloads.wordpress.org/theme/twentytwentyone.1.7.zip', | ||
'https://downloads.wordpress.org/theme/twentytwentythree.1.0.zip', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these things we want to hard-code here in this seemingly independent function? I could easily imagine someone wanting to update the themes and then overlooking these lines… There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only carried over from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if you meant "I would not consider this a blocker" then that sounds good. if not, then I'm confused 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good catch! Missed the important 'not' there 😅 |
||
], | ||
env: { | ||
tests: { | ||
mappings: { | ||
'wp-content/mu-plugins': path.join( | ||
performanceTestDirectory, | ||
'packages/e2e-tests/mu-plugins' | ||
), | ||
'wp-content/plugins/gutenberg-test-plugins': | ||
path.join( | ||
performanceTestDirectory, | ||
'packages/e2e-tests/plugins' | ||
), | ||
}, | ||
}, | ||
}, | ||
}, | ||
null, | ||
2 | ||
), | ||
'utf8' | ||
); | ||
|
||
if ( options.wpVersion ) { | ||
|
@@ -404,33 +417,39 @@ async function runPerformanceTests( branches, options ) { | |
|
||
/** @type {Record<string,Record<string, WPPerformanceResults>>} */ | ||
const results = {}; | ||
const wpEnvPath = path.join( | ||
performanceTestDirectory, | ||
'node_modules/.bin/wp-env' | ||
); | ||
|
||
for ( const testSuite of testSuites ) { | ||
results[ testSuite ] = {}; | ||
/** @type {Array<Record<string, WPPerformanceResults>>} */ | ||
const rawResults = []; | ||
// Alternate three times between branches. | ||
for ( let i = 0; i < TEST_ROUNDS; i++ ) { | ||
const roundInfo = `round ${ i + 1 } of ${ TEST_ROUNDS }`; | ||
log( ` >> Suite: ${ testSuite } (${ roundInfo })` ); | ||
rawResults[ i ] = {}; | ||
for ( const branch of branches ) { | ||
const sanitizedBranch = sanitizeBranchName( branch ); | ||
const runKey = `${ sanitizedBranch }_${ testSuite }_run-${ i }`; | ||
const runKey = `${ testSuite }_${ sanitizedBranch }_run-${ i }`; | ||
// @ts-ignore | ||
const environmentDirectory = branchDirectories[ branch ]; | ||
log( ` >> Branch: ${ branch }, Suite: ${ testSuite }` ); | ||
log( ' >> Starting the environment.' ); | ||
log( ` >> Branch: ${ branch }` ); | ||
log( ' >> Starting the environment.' ); | ||
await runShellScript( | ||
'../../tests/node_modules/.bin/wp-env start', | ||
`${ wpEnvPath } start`, | ||
environmentDirectory | ||
); | ||
log( ' >> Running the test.' ); | ||
log( ' >> Running the test.' ); | ||
rawResults[ i ][ branch ] = await runTestSuite( | ||
testSuite, | ||
performanceTestDirectory, | ||
runKey | ||
); | ||
log( ' >> Stopping the environment' ); | ||
log( ' >> Stopping the environment' ); | ||
await runShellScript( | ||
'../../tests/node_modules/.bin/wp-env stop', | ||
`${ wpEnvPath } stop`, | ||
environmentDirectory | ||
); | ||
} | ||
|
@@ -493,9 +512,9 @@ async function runPerformanceTests( branches, options ) { | |
); | ||
console.table( invertedResult ); | ||
|
||
const resultsFilename = testSuite + '-performance-results.json'; | ||
const resultsFilename = testSuite + '.performance-results.json'; | ||
fs.writeFileSync( | ||
path.resolve( __dirname, '../../../', resultsFilename ), | ||
path.join( ARTIFACTS_PATH, resultsFilename ), | ||
JSON.stringify( results[ testSuite ], null, 2 ) | ||
); | ||
} | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar question here about removing
performance
from the name. when I download these files they lose some inherent linkage to the performance CI job that created them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was the same before - we were copying the
.wp-env.performance.json
and renaming it to.wp-env.json
, so in this regard nothing has changed. I assumed the default.wp-env.json
name is used for thewp-env start
script to pick it up without any extra arguments.