Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyuanliang-ms committed Nov 19, 2024
1 parent 50fc5b6 commit 70bbdee
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/RefreshOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface RefreshOptions {
* Any modifications to watched settings will refresh all settings loaded by the configuration provider when refresh() is called.
*
* @remarks
* If no watched settings is specified, all configuration settings will be watched.
* If no watched setting is specified, all configuration settings will be watched.
*/
watchedSettings?: WatchedSetting[];
}
Expand Down
58 changes: 57 additions & 1 deletion test/refresh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,62 @@ describe("dynamic refresh", function () {
expect(settings.get("app.settings.fontColor")).eq("red");
});

it("should refresh key value based on page eTag, if no watched setting is specified", async () => {
const connectionString = createMockedConnectionString();
const settings = await load(connectionString, {
refreshOptions: {
enabled: true,
refreshIntervalInMs: 2000
}
});
expect(settings).not.undefined;
expect(settings.get("app.settings.fontColor")).eq("red");
expect(settings.get("app.settings.fontSize")).eq("40");

// change setting
updateSetting("app.settings.fontColor", "blue");

// after refreshInterval, should really refresh
await sleepInMs(2 * 1000 + 1);
await settings.refresh();
expect(settings.get("app.settings.fontColor")).eq("blue");
});

it("should refresh key value based on page Etag, only on change", async () => {
const connectionString = createMockedConnectionString();
const settings = await load(connectionString, {
refreshOptions: {
enabled: true,
refreshIntervalInMs: 2000
}
});

Check failure on line 334 in test/refresh.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Trailing spaces not allowed
let refreshSuccessfulCount = 0;
settings.onRefresh(() => {
refreshSuccessfulCount++;
});

expect(settings).not.undefined;
expect(settings.get("app.settings.fontColor")).eq("red");

Check failure on line 342 in test/refresh.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Trailing spaces not allowed
await sleepInMs(2 * 1000 + 1);
await settings.refresh();
expect(refreshSuccessfulCount).eq(0); // no change in feature flags, because page etags are the same.

// change key value
restoreMocks();
let changedKVs = [

Check failure on line 349 in test/refresh.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'changedKVs' is never reassigned. Use 'const' instead
{ value: "blue", key: "app.settings.fontColor" },
{ value: "40", key: "app.settings.fontSize" }
].map(createMockedKeyValue);
mockAppConfigurationClientListConfigurationSettings(changedKVs);
mockAppConfigurationClientGetConfigurationSetting(changedKVs);

await sleepInMs(2 * 1000 + 1);
await settings.refresh();
expect(refreshSuccessfulCount).eq(1); // change in key values, because page etags are different.
expect(settings.get("app.settings.fontColor")).eq("blue");
});
});

describe("dynamic refresh feature flags", function () {
Expand Down Expand Up @@ -358,7 +414,7 @@ describe("dynamic refresh feature flags", function () {

});

it("should refresh feature flags only on change, based on page etags", async () => {
it("should refresh feature flags based on page etags, only on change", async () => {
// mock multiple pages of feature flags
const page1 = [
createMockedFeatureFlag("Alpha_1", { enabled: true }),
Expand Down

0 comments on commit 70bbdee

Please sign in to comment.