Skip to content

Commit

Permalink
[Perf] Update keyvault-secrets test to match .NET (#17799)
Browse files Browse the repository at this point in the history
- Move single-secret code from SecretTest to GetSecretTest
- Ensure vault contains 0 secrets before ListSecretsTest
- Delete and purge all created secrets
  • Loading branch information
mikeharder authored Oct 4, 2021
1 parent c2a25c7 commit 223e285
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion sdk/keyvault/perf-tests/keyvault-secrets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 12 additions & 1 deletion sdk/keyvault/perf-tests/keyvault-secrets/test/getSecret.spec.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
await this.secretClient.getSecret(SecretTest.secretName);
await this.secretClient.getSecret(GetSecretTest.secretName);
}

async globalCleanup() {
await this.deleteAndPurgeSecrets(GetSecretTest.secretName);
}
}
26 changes: 16 additions & 10 deletions sdk/keyvault/perf-tests/keyvault-secrets/test/listSecrets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ export class ListSecretsTest extends SecretTest<ListSecretPerfTestOptions> {
};

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);
Expand All @@ -29,18 +40,13 @@ export class ListSecretsTest extends SecretTest<ListSecretPerfTestOptions> {
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<void> {
// eslint-disable-next-line no-empty
for await (const _secret of this.secretClient.listPropertiesOfSecrets()) {
}
}

async globalCleanup() {
await this.deleteAndPurgeSecrets(...ListSecretsTest.secretsToDelete);
}
}
22 changes: 10 additions & 12 deletions sdk/keyvault/perf-tests/keyvault-secrets/test/secretTest.ts
Original file line number Diff line number Diff line change
@@ -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<TOptions = Record<string, unknown>> extends PerfStressTest<
TOptions
> {
secretClient: SecretClient;
static secretName = `s-${uuid()}`;

constructor() {
super();
Expand All @@ -18,15 +16,15 @@ export abstract class SecretTest<TOptions = Record<string, unknown>> 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);
}
})
);
}
}

0 comments on commit 223e285

Please sign in to comment.