-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Perf] Call runAsync() once before starting recording (#17993)
- Avoids capturing one-time setup like authorization requests - Adds ServiceClientGetTest for directly testing the core-client features
- Loading branch information
1 parent
adf7cf9
commit 2186357
Showing
6 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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"; | ||
import { getCachedHttpsAgent } from "../src/utils"; | ||
|
||
interface ServiceClientGetOptions { | ||
"first-run-extra-requests": number; | ||
url: string; | ||
} | ||
|
||
export class ServiceClientGetTest extends PerfStressTest<ServiceClientGetOptions> { | ||
client: ServiceClient; | ||
request: PipelineRequest; | ||
firstRun: boolean = true; | ||
|
||
public options: PerfStressOptionDictionary<ServiceClientGetOptions> = { | ||
"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: "URL to retrieve", | ||
shortName: "u", | ||
longName: "url" | ||
} | ||
}; | ||
|
||
constructor() { | ||
super(); | ||
|
||
const url = this.parsedOptions.url.value as string; | ||
const insecure = this.parsedOptions.insecure.value as boolean; | ||
|
||
this.client = this.configureClient(new ServiceClient()); | ||
this.request = createPipelineRequest({ | ||
allowInsecureConnection: true, | ||
streamResponseStatusCodes: new Set([200]), | ||
url: url | ||
}); | ||
|
||
if (insecure && url.toLowerCase().startsWith("https:")) { | ||
this.request.agent = getCachedHttpsAgent(true); | ||
} | ||
} | ||
|
||
async runAsync(): Promise<void> { | ||
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!); | ||
} | ||
} |