-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore assets before unit-tests are run (#32810)
## Issue Fixes #32805 Related PR: #32806 The original issue was that "restoring recordings when the first test is triggered" takes time, leading to flakily failing unit-test pipelines. There is a need to have the recordings pre-loaded before the tests are run in the CI pipeline. #32806 - Earlier attempts of pre-restoring recordings in CI for playback tests with retries and increased timeouts to avoid race conditions did not fully solve the problem. This PR is a follow up of that. ## Description Employs a new approach to restore assets sequentially using the test-proxy tool, which is already downloaded by the CI pipeline. The assets restoration process is applied only to the unit-test pipeline in playback mode. Updates to the `rush-runner` tool: 1. Enhanced `rushRunAllWithDirection` to handle test-proxy restore for packages in CI pipeline. 2. Introduced new helper function: `runTestProxyRestore`. 3. Added a new helper function `spawnNodeWithOutput` to spawn NodeJS programs and return the output. 4. Introduced `--ci` flag to help with debugging in local; calls `--ci` flag in the yml scripts for the unit-test commands. ## Example Output [Pipeline: https://dev.azure.com/azure-sdk/public/_build/results?buildId=4523710&view=logs&j=45d25fdd-5540-5f10-8daf-622e80647be7&t=a7f7761c-0312-5a29-1d0c-9736ead6db1f&l=60](https://dev.azure.com/azure-sdk/public/_build/results?buildId=4529992&view=results)
- Loading branch information
1 parent
060ec66
commit 2d4563b
Showing
7 changed files
with
154 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
// @ts-check | ||
import { join as pathJoin } from "node:path"; | ||
import { execSync } from "node:child_process"; | ||
import { getBaseDir } from "./env.js"; | ||
import { existsSync, readFileSync } from "node:fs"; | ||
import { parse } from "../../../../common/lib/jju/parse.js"; | ||
|
||
/** | ||
* Runs test-proxy restore for the given packages. | ||
* | ||
* @param {string[]} packages - An array of package names to restore. | ||
*/ | ||
export function runTestProxyRestore(packages) { | ||
// Get the path to the proxy executable from the environment variable | ||
const proxyExe = process.env.PROXY_EXE; // Set in the pipeline before this script is run | ||
if (!proxyExe) { | ||
console.error('PROXY_EXE environment variable is not set'); | ||
return; | ||
} | ||
|
||
console.log('Starting test-proxy restore for packages:', packages); | ||
const completedPackages = []; | ||
for (const packageName of packages) { | ||
const rushSpec = readFileJson(pathJoin(getBaseDir(), "rush.json")); | ||
|
||
// Find the target package | ||
const targetPackage = rushSpec.projects.find( | ||
packageSpec => packageSpec.packageName == packageName | ||
); | ||
|
||
// Get the directory of the target package | ||
const targetPackageDir = pathJoin(getBaseDir(), targetPackage.projectFolder); | ||
|
||
// Path to the assets.json file in the target package directory | ||
const assetsJsonPath = pathJoin(targetPackageDir, 'assets.json'); | ||
|
||
// Check if the assets.json file exists | ||
if (existsSync(assetsJsonPath)) { | ||
try { | ||
console.log(`Executing test-proxy restore for ${packageName}`); | ||
execSync(`${proxyExe} restore -a "assets.json"`, { cwd: targetPackageDir, stdio: 'inherit' }); | ||
completedPackages.push(packageName); | ||
} catch (error) { | ||
console.error(`Error executing test-proxy restore: ${error.message}`); | ||
} | ||
} | ||
} | ||
console.log('Completed test-proxy restore for the packages:', completedPackages); | ||
} | ||
|
||
|
||
function readFileJson(filename) { | ||
try { | ||
const fileContents = readFileSync(filename); | ||
const jsonResult = parse(fileContents); | ||
return jsonResult; | ||
} catch (ex) { | ||
console.error(ex); | ||
} | ||
} |