-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[App Config] Put node test in a node only file (#16229)
- Loading branch information
1 parent
e68bd01
commit 2eabc6e
Showing
2 changed files
with
67 additions
and
63 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
sdk/appconfiguration/app-configuration/test/internal/node/throttlingRetryPolicy.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters