From 4858de30f8ec9a9cee6fa6535cb1faccd8c8791d Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 30 Sep 2021 16:14:59 -0700 Subject: [PATCH 01/12] Add ServiceClientGetTest --- sdk/test-utils/perfstress/package.json | 1 + sdk/test-utils/perfstress/test/index.spec.ts | 4 +- .../perfstress/test/serviceClientGet.spec.ts | 37 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 sdk/test-utils/perfstress/test/serviceClientGet.spec.ts diff --git a/sdk/test-utils/perfstress/package.json b/sdk/test-utils/perfstress/package.json index e544f3c811f4..1dbbbeadb76f 100644 --- a/sdk/test-utils/perfstress/package.json +++ b/sdk/test-utils/perfstress/package.json @@ -60,6 +60,7 @@ "private": true, "dependencies": { "@azure/abort-controller": "^1.0.0", + "@azure/core-client":"^1.3.1", "@azure/core-http": "^2.0.0", "@azure/core-rest-pipeline": "^1.1.0", "tslib": "^2.2.0", diff --git a/sdk/test-utils/perfstress/test/index.spec.ts b/sdk/test-utils/perfstress/test/index.spec.ts index cc4e90aab257..d9bfd7df2840 100644 --- a/sdk/test-utils/perfstress/test/index.spec.ts +++ b/sdk/test-utils/perfstress/test/index.spec.ts @@ -12,6 +12,7 @@ import { Exception } from "./exception.spec"; import { PerfStressPolicyTest } from "./perfStressPolicy.spec"; import { SleepTest } from "./sleep.spec"; import { NodeFetchTest } from "./nodeFetch.spec"; +import { ServiceClientGetTest } from "./serviceClientGet.spec"; console.log("=== Starting the perfStress test ==="); @@ -24,7 +25,8 @@ const perfStressProgram = new PerfStressProgram( Exception, PerfStressPolicyTest, SleepTest, - NodeFetchTest + NodeFetchTest, + ServiceClientGetTest ]) ); diff --git a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts new file mode 100644 index 000000000000..edb516e610c8 --- /dev/null +++ b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { createPipelineRequest, PipelineRequest } from "@azure/core-rest-pipeline"; +import { ServiceClient } from "@azure/core-client"; +import { PerfStressTest, PerfStressOptionDictionary, drainStream } from "../src"; + +interface ServiceClientGetOptions { + url: string; +} + +export class ServiceClientGetTest extends PerfStressTest { + client: ServiceClient; + request: PipelineRequest; + + public options: PerfStressOptionDictionary = { + url: { + required: true, + description: "Required option", + shortName: "u", + longName: "url" + } + }; + + constructor() { + super(); + this.client = this.configureClient(new ServiceClient()); + this.request = createPipelineRequest({ + url: this.options.url.value as string + }); + } + + async runAsync(): Promise { + const response = await this.client.sendRequest(this.request); + await drainStream(response.readableStreamBody!); + } +} \ No newline at end of file From 4a3872c18715665849aff4330b8fa5fc4259b101 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 30 Sep 2021 16:54:21 -0700 Subject: [PATCH 02/12] Improve nodeFetch test - Change default URL to example.org since bing.com redirects to HTTPS - Remove unnecessary field --- sdk/test-utils/perfstress/test/nodeFetch.spec.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/sdk/test-utils/perfstress/test/nodeFetch.spec.ts b/sdk/test-utils/perfstress/test/nodeFetch.spec.ts index 34df4ae4b7a1..966413654b15 100644 --- a/sdk/test-utils/perfstress/test/nodeFetch.spec.ts +++ b/sdk/test-utils/perfstress/test/nodeFetch.spec.ts @@ -15,25 +15,19 @@ export class NodeFetchTest extends PerfStressTest { agent: new http.Agent({ keepAlive: true }) }; - private url: string = ""; - public options: PerfStressOptionDictionary = { url: { required: true, description: "Required option", shortName: "u", longName: "url", - defaultValue: "http://bing.com", - value: "http://bing.com" + defaultValue: "http://www.example.org", + value: "http://www.example.org" } }; - public setup() { - this.url = this.options.url.value as string; - } - async runAsync(): Promise { - const response = await fetch(this.url, NodeFetchTest.fetchOptions); + const response = await fetch(this.parsedOptions.url.value as string, NodeFetchTest.fetchOptions); await response.text(); } } From 04f7bd3c723539954486afb87bd7997f9ee71b8e Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 30 Sep 2021 17:06:24 -0700 Subject: [PATCH 03/12] Allow insecure connection, stream response --- sdk/test-utils/perfstress/test/serviceClientGet.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts index edb516e610c8..91b9d9e4c5e9 100644 --- a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts +++ b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts @@ -26,7 +26,9 @@ export class ServiceClientGetTest extends PerfStressTest Date: Thu, 30 Sep 2021 17:28:33 -0700 Subject: [PATCH 04/12] Allow untrusted SSL certs --- sdk/test-utils/perfstress/test/serviceClientGet.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts index 91b9d9e4c5e9..31bc5ad896db 100644 --- a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts +++ b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts @@ -4,6 +4,7 @@ import { createPipelineRequest, PipelineRequest } from "@azure/core-rest-pipeline"; import { ServiceClient } from "@azure/core-client"; import { PerfStressTest, PerfStressOptionDictionary, drainStream } from "../src"; +import { getCachedHttpsAgent } from "../src/utils"; interface ServiceClientGetOptions { url: string; @@ -30,6 +31,7 @@ export class ServiceClientGetTest extends PerfStressTest { From 5fd73f60ad5fa32d9bf5a3d0d7bc024021506cb8 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 30 Sep 2021 17:45:25 -0700 Subject: [PATCH 05/12] Only use insecure HTTPS agent when required --- .../perfstress/test/serviceClientGet.spec.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts index 31bc5ad896db..687003ad2c9f 100644 --- a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts +++ b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts @@ -25,13 +25,20 @@ export class ServiceClientGetTest extends PerfStressTest { From 859c5d1543b78981bb9da4b26644319d941d4175 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 1 Oct 2021 14:22:37 -0700 Subject: [PATCH 06/12] Add first-run-extra-requests --- .../perfstress/test/serviceClientGet.spec.ts | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts index 687003ad2c9f..09c1c6cc49c7 100644 --- a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts +++ b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts @@ -7,17 +7,24 @@ import { PerfStressTest, PerfStressOptionDictionary, drainStream } from "../src" import { getCachedHttpsAgent } from "../src/utils"; interface ServiceClientGetOptions { - url: string; + "first-run-extra-requests": number; + url: string; } export class ServiceClientGetTest extends PerfStressTest { client: ServiceClient; request: PipelineRequest; + firstRun: boolean = true; public options: PerfStressOptionDictionary = { + "first-run-extra-requests": { + description: "Extra requests to send on first run. " + + "Simulates SDKs which require extra requests (like authentication) on first API call.", + defaultValue: 0, + }, url: { required: true, - description: "Required option", + description: "URL to retrieve", shortName: "u", longName: "url" } @@ -42,7 +49,18 @@ export class ServiceClientGetTest extends PerfStressTest { - const response = await this.client.sendRequest(this.request); + var response; + + if (this.firstRun) { + const extraRequests = this.parsedOptions["first-run-extra-requests"].value as number; + for (var i = 0; i < extraRequests; i++) { + response = await this.client.sendRequest(this.request); + await drainStream(response.readableStreamBody!); + } + this.firstRun = false; + } + + response = await this.client.sendRequest(this.request); await drainStream(response.readableStreamBody!); } } \ No newline at end of file From 3eda3083a7557e9e9b8c2369a9e3920297dce1a0 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 1 Oct 2021 14:23:16 -0700 Subject: [PATCH 07/12] Call Run() once before starting recording - Avoids capturing one-time setup like authorization requests --- sdk/test-utils/perfstress/src/program.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/test-utils/perfstress/src/program.ts b/sdk/test-utils/perfstress/src/program.ts index 418a242917bb..36492c6546b2 100644 --- a/sdk/test-utils/perfstress/src/program.ts +++ b/sdk/test-utils/perfstress/src/program.ts @@ -366,6 +366,9 @@ export class PerfStressProgram { ); } + // Call Run() once before starting recording, to avoid capturing one-time setup like authorization requests. + await test.runAsync!(); + await recorder.startRecording(); recorder._mode = "record"; await test.runAsync!(); From 37795fe8f98e45e284e782b583ffd17bafca283c Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 1 Oct 2021 14:25:41 -0700 Subject: [PATCH 08/12] Move @azure/core-client to devDependency - Only used by sample test, not framework itself --- sdk/test-utils/perfstress/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/test-utils/perfstress/package.json b/sdk/test-utils/perfstress/package.json index 1dbbbeadb76f..7c2c50b2b8bb 100644 --- a/sdk/test-utils/perfstress/package.json +++ b/sdk/test-utils/perfstress/package.json @@ -60,7 +60,6 @@ "private": true, "dependencies": { "@azure/abort-controller": "^1.0.0", - "@azure/core-client":"^1.3.1", "@azure/core-http": "^2.0.0", "@azure/core-rest-pipeline": "^1.1.0", "tslib": "^2.2.0", @@ -69,6 +68,7 @@ "@types/minimist": "~1.2.0" }, "devDependencies": { + "@azure/core-client":"^1.3.1", "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@types/node": "^12.0.0", "@types/node-fetch": "^2.5.0", From 7727a08b90c0a3c85f7f1aab6b1c8c4fb2ccff01 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 1 Oct 2021 14:26:47 -0700 Subject: [PATCH 09/12] Revert most changes to nodeFetch test --- sdk/test-utils/perfstress/test/nodeFetch.spec.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sdk/test-utils/perfstress/test/nodeFetch.spec.ts b/sdk/test-utils/perfstress/test/nodeFetch.spec.ts index 966413654b15..55fd91a57437 100644 --- a/sdk/test-utils/perfstress/test/nodeFetch.spec.ts +++ b/sdk/test-utils/perfstress/test/nodeFetch.spec.ts @@ -15,6 +15,8 @@ export class NodeFetchTest extends PerfStressTest { agent: new http.Agent({ keepAlive: true }) }; + private url: string = ""; + public options: PerfStressOptionDictionary = { url: { required: true, @@ -26,8 +28,12 @@ export class NodeFetchTest extends PerfStressTest { } }; + public setup() { + this.url = this.options.url.value as string; + } + async runAsync(): Promise { - const response = await fetch(this.parsedOptions.url.value as string, NodeFetchTest.fetchOptions); + const response = await fetch(this.url, NodeFetchTest.fetchOptions); await response.text(); } } From 2a1564e80397115440a2cf792564948a630f3ab4 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 1 Oct 2021 14:27:13 -0700 Subject: [PATCH 10/12] Add trailing newline --- sdk/test-utils/perfstress/test/serviceClientGet.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts index 09c1c6cc49c7..ac13110c18a3 100644 --- a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts +++ b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts @@ -63,4 +63,4 @@ export class ServiceClientGetTest extends PerfStressTest Date: Fri, 1 Oct 2021 15:51:46 -0700 Subject: [PATCH 11/12] rushx format --- sdk/test-utils/perfstress/package.json | 2 +- sdk/test-utils/perfstress/test/serviceClientGet.spec.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/test-utils/perfstress/package.json b/sdk/test-utils/perfstress/package.json index 7c2c50b2b8bb..df62c99409a5 100644 --- a/sdk/test-utils/perfstress/package.json +++ b/sdk/test-utils/perfstress/package.json @@ -68,7 +68,7 @@ "@types/minimist": "~1.2.0" }, "devDependencies": { - "@azure/core-client":"^1.3.1", + "@azure/core-client": "^1.3.1", "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@types/node": "^12.0.0", "@types/node-fetch": "^2.5.0", diff --git a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts index ac13110c18a3..6dab2cb656a8 100644 --- a/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts +++ b/sdk/test-utils/perfstress/test/serviceClientGet.spec.ts @@ -18,9 +18,10 @@ export class ServiceClientGetTest extends PerfStressTest = { "first-run-extra-requests": { - description: "Extra requests to send on first run. " + + description: + "Extra requests to send on first run. " + "Simulates SDKs which require extra requests (like authentication) on first API call.", - defaultValue: 0, + defaultValue: 0 }, url: { required: true, From a097a487f06663b6ce5d5dc066b858a752631e70 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 1 Oct 2021 15:54:33 -0700 Subject: [PATCH 12/12] Update changelog --- sdk/test-utils/perfstress/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdk/test-utils/perfstress/CHANGELOG.md b/sdk/test-utils/perfstress/CHANGELOG.md index e84991cca087..53b38c0cd57e 100644 --- a/sdk/test-utils/perfstress/CHANGELOG.md +++ b/sdk/test-utils/perfstress/CHANGELOG.md @@ -2,6 +2,11 @@ ## 1.0.0 (Unreleased) +### 2021-10-01 + +- Calls runAsync() once before starting recording, to avoid capturing one-time setup like authorization requests. + [#17993](https://github.com/Azure/azure-sdk-for-js/pull/17993) + ### 2021-09-29 - Allows connecting to the proxy-tool with https with the "insecure" boolean option.