Skip to content

Commit 1d1b9c4

Browse files
[Recorder] TEST_PROXY_{HTTP|HTTPS}_PORT (Azure#22145)
* TEST_PROXY_HTTP_PORT * browsers log * TEST_PROXY_HTTPS_PORT
1 parent 7110b07 commit 1d1b9c4

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const log = createPrinter("test-proxy");
1414
const CONTAINER_NAME = "js-azsdk-test-proxy";
1515

1616
export async function startProxyTool(): Promise<void> {
17-
log.info(`Attempting to start test proxy at http://localhost:5000 & https://localhost:5001.\n`);
17+
log.info(`Attempting to start test proxy at http://localhost:${process.env.TEST_PROXY_HTTP_PORT ?? 5000} & https://localhost:${process.env.TEST_PROXY_HTTPS_PORT ?? 5001}.\n`);
1818

1919
const subprocess = spawn(await getDockerRunCommand(), [], {
2020
shell: true,
@@ -59,13 +59,13 @@ async function getDockerRunCommand() {
5959
const testProxyRecordingsLocation = "/srv/testproxy";
6060
const allowLocalhostAccess = "--add-host host.docker.internal:host-gateway";
6161
const imageToLoad = `azsdkengsys.azurecr.io/engsys/testproxy-lin:${await getImageTag()}`;
62-
return `docker run --rm --name ${CONTAINER_NAME} -v ${repoRoot}:${testProxyRecordingsLocation} -p 5001:5001 -p 5000:5000 ${allowLocalhostAccess} ${imageToLoad}`;
62+
return `docker run --rm --name ${CONTAINER_NAME} -v ${repoRoot}:${testProxyRecordingsLocation} -p ${process.env.TEST_PROXY_HTTPS_PORT ?? 5001}:5001 -p ${process.env.TEST_PROXY_HTTP_PORT ?? 5000}:5000 ${allowLocalhostAccess} ${imageToLoad}`;
6363
}
6464

6565
export async function isProxyToolActive(): Promise<boolean> {
6666
try {
67-
await makeRequest("http://localhost:5000/info/available", {});
68-
log.info(`Proxy tool seems to be active at http://localhost:5000\n`);
67+
await makeRequest(`http://localhost:${process.env.TEST_PROXY_HTTP_PORT ?? 5000}/info/available`, {});
68+
log.info(`Proxy tool seems to be active at http://localhost:${process.env.TEST_PROXY_HTTP_PORT ?? 5000}\n`);
6969
return true;
7070
} catch (error: any) {
7171
return false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function shouldRunProxyTool(): Promise<boolean> {
1515
// No need to run a new one if it is already active
1616
// Especially, CI uses this path
1717
log.info(
18-
`Proxy tool seems to be active, not attempting to start the test proxy at http://localhost:5000 & https://localhost:5001.\n`
18+
`Proxy tool seems to be active, not attempting to start the test proxy at http://localhost:${process.env.TEST_PROXY_HTTP_PORT ?? 5000} & https://localhost:${process.env.TEST_PROXY_HTTPS_PORT ?? 5001}.\n`
1919
);
2020
}
2121
return !isActive;

sdk/test-utils/recorder/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
- Add support for session-level sanitization using the `Recorder.addSessionSanitizers` static method. [#21533](https://github.com/Azure/azure-sdk-for-js/pull/21533)
88
- Added logging to help with debugging tests. [#21641](https://github.com/Azure/azure-sdk-for-js/pull/21641)
9+
- Allow mapping the test-proxy tool to ports other than just 5000(for HTTP) using the environment variable `TEST_PROXY_HTTP_PORT`(and `TEST_PROXY_HTTPS_PORT` for 5001(for HTTPS)).
10+
- If `TEST_PROXY_HTTP_PORT` is undefined, we'll try for 5000 as usual.
11+
- For browsers, this variable has to be added as part of the environment variables listed under `envPreprocessor` array in `karma.conf.js` so that the recorder knows the port to hit.
912

1013
### Breaking Changes
1114

sdk/test-utils/recorder/src/recorder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { AdditionalPolicyConfig } from "@azure/core-client";
4040
import { logger } from "./log";
4141
import { setRecordingOptions } from "./options";
4242
import { isNode } from "@azure/core-util";
43+
import { env } from "./utils/env";
4344

4445
/**
4546
* This client manages the recorder life cycle and interacts with the proxy-tool to do the recording,
@@ -53,7 +54,7 @@ import { isNode } from "@azure/core-util";
5354
* Other than configuring your clients, use `start`, `stop`, `addSanitizers` methods to use the recorder.
5455
*/
5556
export class Recorder {
56-
private static url = "http://localhost:5000";
57+
private static url = `http://localhost:${env.TEST_PROXY_HTTP_PORT ?? 5000}`;
5758
public recordingId?: string;
5859
private stateManager = new RecordingStateManager();
5960
private httpClient?: HttpClient;

sdk/test-utils/testing-recorder-new/karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = function (config) {
5959
"AZURE_CLIENT_SECRET",
6060
"AZURE_TENANT_ID",
6161
"RECORDINGS_RELATIVE_PATH",
62+
"TEST_PROXY_HTTP_PORT"
6263
],
6364

6465
// test results reporter to use

0 commit comments

Comments
 (0)