Skip to content

Commit

Permalink
[dev-tool] pre-restore recordings in CI for playback tests (#32668)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremymeng authored Jan 24, 2025
1 parent 0b0c82e commit b4739af
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
8 changes: 8 additions & 0 deletions common/tools/dev-tool/src/commands/run/testVitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { leafCommand, makeCommandInfo } from "../../framework/command";
import { runTestsWithProxyTool } from "../../util/testUtils";
import { createPrinter } from "../../util/printer";
import { shouldStartRelay, startRelayServer } from "../../util/browserRelayServer";
import { runTestProxyCommand } from "../../util/testProxyUtils";

const log = createPrinter("test:vitest");

Expand Down Expand Up @@ -90,6 +91,13 @@ export default leafCommand(commandInfo, async (options) => {
try {
if (options["test-proxy"]) {
if (options["test-proxy-debug"]) process.env["Logging__LogLevel__Default"] = "Debug";

// restore recordings first in CI to avoid impacting the first playback test
if (process.env["BUILD_BUILDNUMBER"]) {
log.info(`restoring recordings before testing`);
await runTestProxyCommand(["restore", "-a", "assets.json"]);
}

return await runTestsWithProxyTool(command);
}

Expand Down
2 changes: 1 addition & 1 deletion common/tools/dev-tool/src/util/checkWithTimeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function checkWithTimeout(
return false;
}

async function delay(timeInMs: number) {
export async function delay(timeInMs: number) {
return new Promise((resolve) => {
log.info(`waiting for ${timeInMs}ms`);
setTimeout(resolve, timeInMs);
Expand Down
7 changes: 4 additions & 3 deletions common/tools/dev-tool/src/util/testProxyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import envPaths from "env-paths";
import { promisify } from "node:util";
import { PassThrough } from "node:stream";
import { pipeline } from "node:stream/promises";
import { delay } from "./checkWithTimeout";

const log = createPrinter("test-proxy");
const downloadLocation = path.join(envPaths("azsdk-dev-tool").cache, "test-proxy");
Expand Down Expand Up @@ -183,15 +184,15 @@ function runCommand(executable: string, argv: string[], options: SpawnOptions =
}

export async function runTestProxyCommand(argv: string[]): Promise<void> {
const result = runCommand(await getTestProxyExecutable(), argv, {
const executable = await getTestProxyExecutable();
await delay(1000);
await runCommand(executable, argv, {
stdio: "inherit",
env: { ...process.env },
}).result;
if (await fs.pathExists("assets.json")) {
await linkRecordingsDirectory();
}

return result;
}

export function createAssetsJson(project: ProjectInfo): Promise<void> {
Expand Down
1 change: 0 additions & 1 deletion sdk/ai/ai-inference-rest/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default mergeConfig(
defineConfig({
test: {
testTimeout: 50000,
hookTimeout: 50000,
},
}),
);
1 change: 0 additions & 1 deletion sdk/ai/ai-projects/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default mergeConfig(
defineConfig({
test: {
testTimeout: 100000,
hookTimeout: 50000,
},
})
);

0 comments on commit b4739af

Please sign in to comment.