Skip to content

Commit 6242d00

Browse files
authored
Stop the test proxy container explicitly when tests finish (Azure#19473)
Giving the container a name and then stopping it using docker container stop once tests complete should fix Azure#19363.
1 parent 2736006 commit 6242d00

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

common/tools/dev-tool/src/commands/test-proxy/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export const commandInfo = makeCommandInfo(
1010

1111
export default subCommand(commandInfo, {
1212
start: () => import("./start"),
13+
stop: () => import("./stop"),
1314
"wait-for-proxy-endpoint": () => import("./waitForProxyEndpoint"),
1415
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { leafCommand, makeCommandInfo } from "../../framework/command";
5+
import { stopProxyTool } from "../../util/testProxyUtils";
6+
7+
export const commandInfo = makeCommandInfo(
8+
"test-proxy",
9+
"stops the test proxy that was started with test-proxy start, if it was running",
10+
{}
11+
);
12+
13+
export default leafCommand(commandInfo, async () => {
14+
await stopProxyTool();
15+
return true;
16+
});

common/tools/dev-tool/src/util/testProxyUtils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { createPrinter } from "./printer";
99
import { resolveRoot } from "./resolveProject";
1010

1111
const log = createPrinter("test-proxy");
12+
13+
const CONTAINER_NAME = "js-azsdk-test-proxy";
14+
1215
export async function startProxyTool(): Promise<void> {
1316
log.info(`Attempting to start test proxy at http://localhost:5000 & https://localhost:5001.\n`);
1417

@@ -24,12 +27,19 @@ export async function startProxyTool(): Promise<void> {
2427
log.info(`Check the output file "${outFileName}" for test-proxy logs.`);
2528
}
2629

30+
export async function stopProxyTool(): Promise<void> {
31+
log.info("Attempting to stop the test proxy if it is running");
32+
33+
const stopProcess = spawn(`docker stop ${CONTAINER_NAME}`, [], { shell: true });
34+
return new Promise(resolve => stopProcess.on("close", resolve));
35+
};
36+
2737
async function getDockerRunCommand() {
2838
const repoRoot = await resolveRoot(); // /workspaces/azure-sdk-for-js/
2939
const testProxyRecordingsLocation = "/srv/testproxy";
3040
const allowLocalhostAccess = "--add-host host.docker.internal:host-gateway";
3141
const imageToLoad = `azsdkengsys.azurecr.io/engsys/testproxy-lin:${await getImageTag()}`;
32-
return `docker run -v ${repoRoot}:${testProxyRecordingsLocation} -p 5001:5001 -p 5000:5000 ${allowLocalhostAccess} ${imageToLoad}`;
42+
return `docker run --rm --name ${CONTAINER_NAME} -v ${repoRoot}:${testProxyRecordingsLocation} -p 5001:5001 -p 5000:5000 ${allowLocalhostAccess} ${imageToLoad}`;
3343
}
3444

3545
export async function isProxyToolActive(): Promise<boolean> {

common/tools/dev-tool/src/util/testUtils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ export async function runTestsWithProxyTool(
2828
if (
2929
await shouldRunProxyTool() // Boolean to figure out if we need to run just the mocha command or the test-proxy too
3030
) {
31-
const testProxyCMD = "dev-tool test-proxy start";
31+
const testProxyStartCMD = "dev-tool test-proxy start";
32+
const testProxyStopCMD = "dev-tool test-proxy stop";
3233
const waitForProxyEndpointCMD = "dev-tool test-proxy wait-for-proxy-endpoint";
3334
await concurrently(
3435
[
35-
{ command: testProxyCMD },
36+
{ command: testProxyStartCMD },
3637
{
37-
command: `${waitForProxyEndpointCMD} && ${testCommandObj.command}`, // Waits for the proxy endpoint to be active and then starts running the tests
38+
command: `${waitForProxyEndpointCMD} && ${testCommandObj.command} && ${testProxyStopCMD}`, // Waits for the proxy endpoint to be active and then starts running the tests
3839
name: testCommandObj.name,
3940
},
4041
],

0 commit comments

Comments
 (0)