Skip to content

Commit

Permalink
[AppConfig] allow setting updateIntervalInMs in LRO options (#27200)
Browse files Browse the repository at this point in the history
also add a `testPollingOptions` in recorder to help testing in playback
mode.
  • Loading branch information
jeremymeng authored Sep 21, 2023
1 parent 45d9f36 commit eb233b4
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 14 deletions.
2 changes: 2 additions & 0 deletions sdk/appconfiguration/app-configuration/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

### Features Added

- Allow setting `updateIntervalInMs` in `CreateSnapshotOptions`

### Bugs Fixed

### Other Changes
Expand Down
2 changes: 1 addition & 1 deletion sdk/appconfiguration/app-configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"@azure/identity": "^2.0.1",
"@azure/keyvault-secrets": "^4.2.0",
"@azure-tools/test-credential": "^1.0.0",
"@azure-tools/test-recorder": "^3.0.0",
"@azure-tools/test-recorder": "^3.1.0",
"@azure/test-utils": "^1.0.0",
"@microsoft/api-extractor": "^7.31.1",
"@types/chai": "^4.1.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface ConfigurationSettingsFilter {

// @public
export interface CreateSnapshotOptions extends OperationOptions {
updateIntervalInMs?: number;
}

// @public
Expand Down
7 changes: 6 additions & 1 deletion sdk/appconfiguration/app-configuration/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,12 @@ export interface RetryOptions {
/**
* Options used when creating a Snapshot.
*/
export interface CreateSnapshotOptions extends OperationOptions {}
export interface CreateSnapshotOptions extends OperationOptions {
/**
* The amount of time to wait (in milliseconds) between subsequent requests relating to the same operation.
*/
updateIntervalInMs?: number;
}

/**
* Response from adding a Snapshot.
Expand Down
21 changes: 11 additions & 10 deletions sdk/appconfiguration/app-configuration/test/public/snapshot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { Recorder, isPlaybackMode } from "@azure-tools/test-recorder";
import { Recorder, isPlaybackMode, testPollingOptions } from "@azure-tools/test-recorder";
import { assert } from "chai";
import { Context } from "mocha";
import { AppConfigurationClient } from "../../src/appConfigurationClient";
Expand Down Expand Up @@ -59,7 +59,7 @@ describe("AppConfigurationClient snapshot", () => {
describe("createSnapshot", () => {
it("create a snapshot", async () => {
// creating a new snapshot
const poller = await client.beginCreateSnapshot(snapshot1);
const poller = await client.beginCreateSnapshot(snapshot1, testPollingOptions);
newSnapshot = await poller.pollUntilDone();
assertEqualSnapshot(newSnapshot, snapshot1);

Expand All @@ -68,7 +68,7 @@ describe("AppConfigurationClient snapshot", () => {

it("service throws error when tried to create a snapshot with same name", async () => {
// creating a new snapshot
newSnapshot = await client.beginCreateSnapshotAndWait(snapshot1);
newSnapshot = await client.beginCreateSnapshotAndWait(snapshot1, testPollingOptions);
assertEqualSnapshot(newSnapshot, snapshot1);

const errorExpected = {
Expand All @@ -80,7 +80,7 @@ describe("AppConfigurationClient snapshot", () => {

// attempt to add the same snapshot
try {
await client.beginCreateSnapshotAndWait(snapshot1);
await client.beginCreateSnapshotAndWait(snapshot1, testPollingOptions);
throw new Error("Test failure");
} catch (err: any) {
assert.equal(err.message, JSON.stringify(errorExpected));
Expand All @@ -98,6 +98,7 @@ describe("AppConfigurationClient snapshot", () => {
requestOptions: {
timeout: 1,
},
updateIntervalInMs: testPollingOptions.updateIntervalInMs,
});
});
});
Expand All @@ -106,7 +107,7 @@ describe("AppConfigurationClient snapshot", () => {
describe("listConfigurationSettings of a Snapshot", () => {
it("list configuration settings", async () => {
// creating a new snapshot
newSnapshot = await client.beginCreateSnapshotAndWait(snapshot1);
newSnapshot = await client.beginCreateSnapshotAndWait(snapshot1, testPollingOptions);

// change the value of the setting
await client.setConfigurationSetting({ ...filter1, value: "value2" });
Expand All @@ -129,7 +130,7 @@ describe("AppConfigurationClient snapshot", () => {
describe("archiveSnapshot", () => {
it("archive a snapshot", async () => {
// creating a new snapshot
newSnapshot = await client.beginCreateSnapshotAndWait(snapshot1);
newSnapshot = await client.beginCreateSnapshotAndWait(snapshot1, testPollingOptions);
const archivedSnapshot = await client.archiveSnapshot(newSnapshot);

assert.equal(
Expand All @@ -154,7 +155,7 @@ describe("AppConfigurationClient snapshot", () => {
describe("getSnapshot", () => {
it("get a snapshot", async () => {
// creating a new snapshot
newSnapshot = await client.beginCreateSnapshotAndWait(snapshot1);
newSnapshot = await client.beginCreateSnapshotAndWait(snapshot1, testPollingOptions);

const snapshot = await client.getSnapshot(newSnapshot.name);
assertEqualSnapshot(snapshot, newSnapshot);
Expand All @@ -165,7 +166,7 @@ describe("AppConfigurationClient snapshot", () => {
it.skip("accepts operation options", async function () {
if (isPlaybackMode()) this.skip();
// creating a new snapshot
newSnapshot = await client.beginCreateSnapshotAndWait(snapshot1);
newSnapshot = await client.beginCreateSnapshotAndWait(snapshot1, testPollingOptions);
await assertThrowsAbortError(async () => {
await client.getSnapshot(newSnapshot.name, {
requestOptions: {
Expand Down Expand Up @@ -194,14 +195,14 @@ describe("AppConfigurationClient snapshot", () => {
assert.equal(num, 0, "There should be no snapshot in ready status");

// creating a new snapshot 1
await client.beginCreateSnapshotAndWait(snapshot1);
await client.beginCreateSnapshotAndWait(snapshot1, testPollingOptions);

// create a new snapshot 2
const snapshot2 = {
name: recorder.variable("snapshot2", `snapshot-${new Date().getTime()}`),
filters: [filter1, filter2],
};
await client.beginCreateSnapshotAndWait(snapshot2);
await client.beginCreateSnapshotAndWait(snapshot2, testPollingOptions);

// new snapshot lists
const listAfter = await client.listSnapshots({ statusFilter: ["ready"] });
Expand Down
3 changes: 2 additions & 1 deletion sdk/test-utils/recorder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Release History

## 3.0.1 (Unreleased)
## 3.1.0 (Unreleased)

### Features Added

- Add support for setting `TLSValidationCert` in the Test Proxy Transport.
- Add a `testPollingOptions` that allow skip polling wait in playback mode.

### Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion sdk/test-utils/recorder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/test-recorder",
"version": "3.0.1",
"version": "3.1.0",
"sdk-type": "utility",
"description": "This library provides interfaces and helper methods to provide recording and playback capabilities for the tests in Azure JS/TS SDKs",
"main": "dist/index.js",
Expand Down
1 change: 1 addition & 0 deletions sdk/test-utils/recorder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export {
isPlaybackMode,
isRecordMode,
assertEnvironmentVariable,
testPollingOptions,
} from "./utils/utils";
export { env } from "./utils/env";
export { delay } from "./utils/delay";
Expand Down
7 changes: 7 additions & 0 deletions sdk/test-utils/recorder/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,10 @@ export function assertEnvironmentVariable(variable: string): string {
if (!value) throw new Error(`${variable} is not defined`);
return value;
}

/**
* Polling options that don't wait in playback mode.
*/
export const testPollingOptions = {
updateIntervalInMs: isPlaybackMode() ? 0 : undefined,
};

0 comments on commit eb233b4

Please sign in to comment.