Skip to content

Commit

Permalink
[App Config] Put node test in a node only file (#16229)
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshaNalluru committed Jul 6, 2021
1 parent e68bd01 commit 2eabc6e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import chai from "chai";
import { AppConfigurationClient } from "../../../src";
import { AbortController } from "@azure/abort-controller";
import nock from "nock";
import { generateUuid } from "@azure/core-http";

describe("Should not retry forever - honors the abort signal passed", () => {
let client: AppConfigurationClient;
const connectionString = "Endpoint=https://myappconfig.azconfig.io;Id=key:ai/u/fake;Secret=abcd=";

beforeEach(function() {
if (!nock.isActive()) {
nock.activate();
}
nock("https://myappconfig.azconfig.io:443")
.persist()
.put(/.*/g)
.reply(
429,
{
type: "https://azconfig.io/errors/too-many-requests",
title: "Resource utilization has surpassed the assigned quota",
policy: "Total Requests",
status: 429
},
["retry-after-ms", "123456"]
);

client = new AppConfigurationClient(connectionString);
});

afterEach(async function() {
nock.restore();
nock.cleanAll();
nock.enableNetConnect();
});

it("simulate the service throttling", async () => {
const key = generateUuid();
const numberOfSettings = 200;
const promises = [];
let errorWasThrown = false;
try {
for (let index = 0; index < numberOfSettings; index++) {
promises.push(
client.addConfigurationSetting(
{
key: key + "-" + index,
value: "added"
},
{
abortSignal: AbortController.timeout(1000)
}
)
);
}
await Promise.all(promises);
} catch (error) {
errorWasThrown = true;
chai.assert.equal((error as any).name, "AbortError", "Unexpected error thrown");
}
chai.assert.equal(errorWasThrown, true, "Error was not thrown");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import {
} from "@azure/core-http";
import { ThrottlingRetryPolicy, getDelayInMs } from "../../src/policies/throttlingRetryPolicy";
import { assertThrowsRestError } from "../public/utils/testHelpers";
import { AppConfigurationClient } from "../../src";
import { AbortController } from "@azure/abort-controller";
import nock from "nock";
import { generateUuid } from "@azure/core-http";

describe("ThrottlingRetryPolicy", () => {
class PassThroughPolicy {
Expand Down Expand Up @@ -192,62 +188,3 @@ describe("ThrottlingRetryPolicy", () => {
});
});
});

describe("Should not retry forever - honors the abort signal passed", () => {
let client: AppConfigurationClient;
const connectionString = "Endpoint=https://myappconfig.azconfig.io;Id=key:ai/u/fake;Secret=abcd=";

beforeEach(function() {
if (!nock.isActive()) {
nock.activate();
}
nock("https://myappconfig.azconfig.io:443")
.persist()
.put(/.*/g)
.reply(
429,
{
type: "https://azconfig.io/errors/too-many-requests",
title: "Resource utilization has surpassed the assigned quota",
policy: "Total Requests",
status: 429
},
["retry-after-ms", "123456"]
);

client = new AppConfigurationClient(connectionString);
});

afterEach(async function() {
nock.restore();
nock.cleanAll();
nock.enableNetConnect();
});

it("simulate the service throttling", async () => {
const key = generateUuid();
const numberOfSettings = 200;
const promises = [];
let errorWasThrown = false;
try {
for (let index = 0; index < numberOfSettings; index++) {
promises.push(
client.addConfigurationSetting(
{
key: key + "-" + index,
value: "added"
},
{
abortSignal: AbortController.timeout(1000)
}
)
);
}
await Promise.all(promises);
} catch (error) {
errorWasThrown = true;
chai.assert.equal((error as any).name, "AbortError", "Unexpected error thrown");
}
chai.assert.equal(errorWasThrown, true, "Error was not thrown");
});
});

0 comments on commit 2eabc6e

Please sign in to comment.