From 223e2853b7d8dd435a5659bb6a32e22d94102187 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 4 Oct 2021 14:51:15 -0700 Subject: [PATCH] [Perf] Update keyvault-secrets test to match .NET (#17799) - Move single-secret code from SecretTest to GetSecretTest - Ensure vault contains 0 secrets before ListSecretsTest - Delete and purge all created secrets --- .../perf-tests/keyvault-secrets/package.json | 2 +- .../keyvault-secrets/test/getSecret.spec.ts | 13 +++++++++- .../keyvault-secrets/test/listSecrets.spec.ts | 26 ++++++++++++------- .../keyvault-secrets/test/secretTest.ts | 22 +++++++--------- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/sdk/keyvault/perf-tests/keyvault-secrets/package.json b/sdk/keyvault/perf-tests/keyvault-secrets/package.json index e71eaff955d0..68982d0abd4b 100644 --- a/sdk/keyvault/perf-tests/keyvault-secrets/package.json +++ b/sdk/keyvault/perf-tests/keyvault-secrets/package.json @@ -12,7 +12,7 @@ "dotenv": "^8.2.0", "@azure/identity": "2.0.0-beta.5", "uuid": "^8.3.0", - "@azure/keyvault-secrets": "^4.2.0" + "@azure/keyvault-secrets": "4.4.0-beta.2" }, "devDependencies": { "@types/node": "^12.0.0", diff --git a/sdk/keyvault/perf-tests/keyvault-secrets/test/getSecret.spec.ts b/sdk/keyvault/perf-tests/keyvault-secrets/test/getSecret.spec.ts index 19da3e3cd489..66930cd201f6 100644 --- a/sdk/keyvault/perf-tests/keyvault-secrets/test/getSecret.spec.ts +++ b/sdk/keyvault/perf-tests/keyvault-secrets/test/getSecret.spec.ts @@ -1,9 +1,20 @@ import { SecretTest } from "./secretTest"; +import { v4 as uuid } from "uuid"; export class GetSecretTest extends SecretTest { + static secretName = `s-${uuid()}`; + public options = {}; + async globalSetup() { + await this.secretClient.setSecret(GetSecretTest.secretName, "value"); + } + async runAsync(): Promise { - await this.secretClient.getSecret(SecretTest.secretName); + await this.secretClient.getSecret(GetSecretTest.secretName); + } + + async globalCleanup() { + await this.deleteAndPurgeSecrets(GetSecretTest.secretName); } } diff --git a/sdk/keyvault/perf-tests/keyvault-secrets/test/listSecrets.spec.ts b/sdk/keyvault/perf-tests/keyvault-secrets/test/listSecrets.spec.ts index 7eb25feca3a5..12786c95ad6c 100644 --- a/sdk/keyvault/perf-tests/keyvault-secrets/test/listSecrets.spec.ts +++ b/sdk/keyvault/perf-tests/keyvault-secrets/test/listSecrets.spec.ts @@ -19,7 +19,18 @@ export class ListSecretsTest extends SecretTest { }; async globalSetup() { - await super.globalSetup(); + // Validate that vault contains 0 secrets (including soft-deleted secrets), since additional secrets + // (including soft-deleted) impact performance. + if ( + !(await this.secretClient.listPropertiesOfSecrets().next()).done || + !(await this.secretClient.listDeletedSecrets().next()).done + ) { + throw new Error( + `KeyVault ${this.secretClient.vaultUrl} must contain 0 ` + + "secrets (including soft-deleted) before starting perf test" + ); + } + const secretToCreate = Array.from({ length: this.parsedOptions.count.value! }, (_x, i) => { const name = `s${i}-${uuid()}`; ListSecretsTest.secretsToDelete.push(name); @@ -29,18 +40,13 @@ export class ListSecretsTest extends SecretTest { await Promise.all(secretToCreate); } - async globalCleanup() { - await super.globalCleanup(); - - const startDeletePromises = ListSecretsTest.secretsToDelete.map((name) => - this.secretClient.beginDeleteSecret(name) - ); - await Promise.all(startDeletePromises); - } - async runAsync(): Promise { // eslint-disable-next-line no-empty for await (const _secret of this.secretClient.listPropertiesOfSecrets()) { } } + + async globalCleanup() { + await this.deleteAndPurgeSecrets(...ListSecretsTest.secretsToDelete); + } } diff --git a/sdk/keyvault/perf-tests/keyvault-secrets/test/secretTest.ts b/sdk/keyvault/perf-tests/keyvault-secrets/test/secretTest.ts index 119d80b2bd10..b2b2123a130b 100644 --- a/sdk/keyvault/perf-tests/keyvault-secrets/test/secretTest.ts +++ b/sdk/keyvault/perf-tests/keyvault-secrets/test/secretTest.ts @@ -1,13 +1,11 @@ import { SecretClient } from "@azure/keyvault-secrets"; import { PerfStressTest } from "@azure/test-utils-perfstress"; import { keyVaultUri, credential } from "./utils"; -import { v4 as uuid } from "uuid"; export abstract class SecretTest> extends PerfStressTest< TOptions > { secretClient: SecretClient; - static secretName = `s-${uuid()}`; constructor() { super(); @@ -18,15 +16,15 @@ export abstract class SecretTest> extends Per ); } - async globalSetup() { - await this.secretClient.setSecret(SecretTest.secretName, "value"); - } - - async globalCleanup() { - const poller = await this.secretClient.beginDeleteSecret(SecretTest.secretName); - const deletedSecret = await poller.pollUntilDone(); - if (deletedSecret.recoveryId) { - await this.secretClient.purgeDeletedSecret(SecretTest.secretName); - } + async deleteAndPurgeSecrets(...names: string[]) { + await Promise.all( + names.map(async (name) => { + const poller = await this.secretClient.beginDeleteSecret(name); + const deletedSecret = await poller.pollUntilDone(); + if (deletedSecret.recoveryId) { + await this.secretClient.purgeDeletedSecret(name); + } + }) + ); } }