Skip to content

Commit

Permalink
Merge 896b2d6 into 406d749
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein authored Jul 7, 2023
2 parents 406d749 + 896b2d6 commit 7250320
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/ConfigServiceBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,15 @@ export abstract class ConfigServiceBase<TOptions extends OptionsBase> {
const success = fetchResult.status === FetchStatus.Fetched;
if (success
|| fetchResult.config.timestamp > latestConfig.timestamp && (!fetchResult.config.isEmpty || latestConfig.isEmpty)) {
await this.options.cache.set(this.cacheKey, fetchResult.config);

latestConfig = fetchResult.config;

await this.options.cache.set(this.cacheKey, latestConfig);

this.onConfigUpdated(latestConfig);
this.onConfigUpdated(fetchResult.config);

if (success) {
this.onConfigChanged(latestConfig);
if (success && (fetchResult.config.httpETag != latestConfig.httpETag || fetchResult.config.configJson != latestConfig.configJson)) {
this.onConfigChanged(fetchResult.config);
}

latestConfig = fetchResult.config;
}

return [fetchResult, latestConfig];
Expand Down
18 changes: 18 additions & 0 deletions test/ConfigCatClientTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,24 @@ describe("ConfigCatClient", () => {
assert.equal(configChangedEventCount, 3);
});

it("Initialization With AutoPollOptions - config doesn't change - should fire configChanged only once", async () => {

const configCatKernel: FakeConfigCatKernel = { configFetcher: new FakeConfigFetcher(), sdkType: "common", sdkVersion: "1.0.0" };
let configChangedEventCount = 0;
const pollIntervalSeconds = 1;
const userOptions: IAutoPollOptions = {
logger: null,
pollIntervalSeconds,
setupHooks: hooks => hooks.on("configChanged", () => configChangedEventCount++)
};
const options: AutoPollOptions = new AutoPollOptions("APIKEY", "common", "1.0.0", userOptions, null);
new ConfigCatClient(options, configCatKernel);

await delay(2.5 * pollIntervalSeconds * 1000);

assert.equal(configChangedEventCount, 1);
});

it("Initialization With AutoPollOptions - with maxInitWaitTimeSeconds - getValueAsync should wait", async () => {

const maxInitWaitTimeSeconds = 2;
Expand Down

0 comments on commit 7250320

Please sign in to comment.