Skip to content

Commit

Permalink
[Key Vault Certificates] Happy path to avoid unstable live tests (#9879)
Browse files Browse the repository at this point in the history
* [Key Vault Certificates] Happy path to avoid variable behavior in live tests

* forgot these .only

* added timeout on the package.json somewhere I missed before
  • Loading branch information
sadasant authored Jul 6, 2020
1 parent 95d62b4 commit 0caf060
Show file tree
Hide file tree
Showing 30 changed files with 18,560 additions and 7,718 deletions.
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-certificates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"test:node": "npm run clean && npm run build:test && npm run unit-test:node",
"test": "npm run clean && npm run build:test && npm run unit-test",
"unit-test:browser": "karma start --single-run",
"unit-test:node": "mocha --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --no-timeouts --full-trace dist-test/index.node.js",
"unit-test:node": "mocha --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace dist-test/index.node.js",
"unit-test:node:no-timeout": "mocha --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --no-timeouts --full-trace dist-test/index.node.js",
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
},
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions sdk/keyvault/keyvault-certificates/test/public/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ describe("Certificates client - list certificates in various ways", () => {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateNames = [`${certificateName}0`, `${certificateName}1`];
for (const name of certificateNames) {
await client.beginCreateCertificate(name, basicCertificatePolicy, testPollerProperties);
const createPoller = await client.beginCreateCertificate(name, basicCertificatePolicy, testPollerProperties);
await createPoller.pollUntilDone();
}

let found = 0;
Expand All @@ -91,7 +92,8 @@ describe("Certificates client - list certificates in various ways", () => {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateNames = [`${certificateName}0`, `${certificateName}1`];
for (const name of certificateNames) {
await client.beginCreateCertificate(name, basicCertificatePolicy, testPollerProperties);
const createPoller = await client.beginCreateCertificate(name, basicCertificatePolicy, testPollerProperties);
await createPoller.pollUntilDone();
}
for (const name of certificateNames) {
const deletePoller = await client.beginDeleteCertificate(name, testPollerProperties);
Expand All @@ -116,7 +118,8 @@ describe("Certificates client - list certificates in various ways", () => {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateNames = [`${certificateName}0`, `${certificateName}1`];
for (const name of certificateNames) {
await client.beginCreateCertificate(name, basicCertificatePolicy, testPollerProperties);
const createPoller = await client.beginCreateCertificate(name, basicCertificatePolicy, testPollerProperties);
await createPoller.pollUntilDone();
}
let found = 0;
for await (const page of client
Expand Down Expand Up @@ -148,7 +151,8 @@ describe("Certificates client - list certificates in various ways", () => {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateNames = [`${certificateName}0`, `${certificateName}1`];
for (const name of certificateNames) {
await client.beginCreateCertificate(name, basicCertificatePolicy, testPollerProperties);
const createPoller = await client.beginCreateCertificate(name, basicCertificatePolicy, testPollerProperties);
await createPoller.pollUntilDone();
}
for (const name of certificateNames) {
const deletePoller = await client.beginDeleteCertificate(name, testPollerProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ describe("Certificates client - lro - delete", () => {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
await client.beginCreateCertificate(
const createPoller = await client.beginCreateCertificate(
certificateName,
DefaultCertificatePolicy,
testPollerProperties
);
await createPoller.pollUntilDone();
const poller = await client.beginDeleteCertificate(certificateName, testPollerProperties);
assert.ok(poller.getOperationState().isStarted);

Expand All @@ -64,11 +65,12 @@ describe("Certificates client - lro - delete", () => {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
await client.beginCreateCertificate(
const createPoller = await client.beginCreateCertificate(
certificateName,
DefaultCertificatePolicy,
testPollerProperties
);
await createPoller.pollUntilDone();
const poller = await client.beginDeleteCertificate(certificateName, testPollerProperties);
assert.ok(poller.getOperationState().isStarted);

Expand Down Expand Up @@ -100,4 +102,5 @@ describe("Certificates client - lro - delete", () => {

await testClient.purgeCertificate(certificateName);
});

});
39 changes: 21 additions & 18 deletions sdk/keyvault/keyvault-certificates/test/public/lro.recover.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,31 @@ describe("Certificates client - LRO - recoverDelete", () => {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
await client.beginCreateCertificate(
const createPoller = await client.beginCreateCertificate(
certificateName,
DefaultCertificatePolicy,
testPollerProperties
);
await createPoller.pollUntilDone();

const deletePoller = await client.beginDeleteCertificate(certificateName, testPollerProperties);
await deletePoller.pollUntilDone();

const poller = await client.beginRecoverDeletedCertificate(
const recoverPoller = await client.beginRecoverDeletedCertificate(
certificateName,
testPollerProperties
);
assert.ok(poller.getOperationState().isStarted);
assert.ok(recoverPoller.getOperationState().isStarted);

// The pending certificate can be obtained this way:
assert.equal(poller.getOperationState().result!.name, certificateName);
assert.equal(recoverPoller.getOperationState().result!.name, certificateName);

const deletedCertificate: DeletedCertificate = await poller.pollUntilDone();
const deletedCertificate: DeletedCertificate = await recoverPoller.pollUntilDone();
assert.equal(deletedCertificate.name, certificateName);
assert.ok(poller.getOperationState().isCompleted);
assert.ok(recoverPoller.getOperationState().isCompleted);

// The final certificate can also be obtained this way:
assert.equal(poller.getOperationState().result!.name, certificateName);
assert.equal(recoverPoller.getOperationState().result!.name, certificateName);

await testClient.flushCertificate(certificateName);
});
Expand All @@ -68,40 +69,41 @@ describe("Certificates client - LRO - recoverDelete", () => {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
await client.beginCreateCertificate(
const createPoller = await client.beginCreateCertificate(
certificateName,
DefaultCertificatePolicy,
testPollerProperties
);
await createPoller.pollUntilDone();
const deletePoller = await client.beginDeleteCertificate(certificateName, testPollerProperties);
await deletePoller.pollUntilDone();

const poller = await client.beginRecoverDeletedCertificate(
const recoverPoller = await client.beginRecoverDeletedCertificate(
certificateName,
testPollerProperties
);
assert.ok(poller.getOperationState().isStarted);
assert.ok(recoverPoller.getOperationState().isStarted);

poller.pollUntilDone().catch((e) => {
recoverPoller.pollUntilDone().catch((e) => {
assert.ok(e instanceof PollerStoppedError);
assert.equal(e.name, "PollerStoppedError");
assert.equal(e.message, "This poller is already stopped");
});

await poller.poll(); // Making sure it has some data
await recoverPoller.poll(); // Making sure it has some data

poller.stopPolling();
assert.ok(poller.isStopped());
assert.ok(!poller.getOperationState().isCompleted);
recoverPoller.stopPolling();
assert.ok(recoverPoller.isStopped());
assert.ok(!recoverPoller.getOperationState().isCompleted);

const serialized = poller.toString();
const serialized = recoverPoller.toString();

const resumePoller = await client.beginRecoverDeletedCertificate(certificateName, {
resumeFrom: serialized,
...testPollerProperties
});

assert.ok(poller.getOperationState().isStarted);
assert.ok(recoverPoller.getOperationState().isStarted);
const deletedCertificate: DeletedCertificate = await resumePoller.pollUntilDone();
assert.equal(deletedCertificate.name, certificateName);
assert.ok(resumePoller.getOperationState().isCompleted);
Expand All @@ -115,11 +117,12 @@ describe("Certificates client - LRO - recoverDelete", () => {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
await client.beginCreateCertificate(
const createPoller = await client.beginCreateCertificate(
certificateName,
DefaultCertificatePolicy,
testPollerProperties
);
await createPoller.pollUntilDone();
const deletePoller = await client.beginDeleteCertificate(certificateName, testPollerProperties);
await deletePoller.pollUntilDone();
await assertThrowsAbortError(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ describe("Certificates client - restore certificates and recover backups", () =>

it("can recover a deleted certificate", async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
const createPoller = await client.beginCreateCertificate(
certificateName,
basicCertificatePolicy,
testPollerProperties
);
await createPoller.pollUntilDone();
const deletePoller = await client.beginDeleteCertificate(certificateName, testPollerProperties);
const getDeletedResult = await deletePoller.pollUntilDone();
assert.equal(
Expand Down Expand Up @@ -82,11 +83,12 @@ describe("Certificates client - restore certificates and recover backups", () =>
// since the purge operation currently can't be expected to finish anytime soon.
it("can restore a certificate", async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
const createPoller = await client.beginCreateCertificate(
certificateName,
basicCertificatePolicy,
testPollerProperties
);
await createPoller.pollUntilDone();
const backup = await client.backupCertificate(certificateName);
await testClient.flushCertificate(certificateName);
// eslint-disable-next-line no-constant-condition
Expand Down Expand Up @@ -139,11 +141,12 @@ describe("Certificates client - restore certificates and recover backups", () =>
// On playback mode, the tests happen too fast for the timeout to work
it("can restore a key with requestOptions timeout", async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
const createPoller = await client.beginCreateCertificate(
certificateName,
basicCertificatePolicy,
testPollerProperties
);
await createPoller.pollUntilDone();
const backup = await client.backupCertificate(certificateName);
await testClient.flushCertificate(certificateName);

Expand Down

0 comments on commit 0caf060

Please sign in to comment.