Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[App Config] Put node test in a node only file #16229

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});
});