File tree Expand file tree Collapse file tree 4 files changed +32
-4
lines changed
common/tools/dev-tool/src Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -10,5 +10,6 @@ export const commandInfo = makeCommandInfo(
1010
1111export default subCommand ( commandInfo , {
1212 start : ( ) => import ( "./start" ) ,
13+ stop : ( ) => import ( "./stop" ) ,
1314 "wait-for-proxy-endpoint" : ( ) => import ( "./waitForProxyEndpoint" ) ,
1415} ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ import { createPrinter } from "./printer";
99import { resolveRoot } from "./resolveProject" ;
1010
1111const log = createPrinter ( "test-proxy" ) ;
12+
13+ const CONTAINER_NAME = "js-azsdk-test-proxy" ;
14+
1215export 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+
2737async 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
3545export async function isProxyToolActive ( ) : Promise < boolean > {
Original file line number Diff line number Diff 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 ] ,
You can’t perform that action at this time.
0 commit comments