Skip to content

Commit 5e320ae

Browse files
authored
fix: only initialize NOT_READY providers (#507)
See here. We should only run initialize if `ProviderStatus` is `NOT_READY` to prevent duplicate calls to `initialize`, as we [Java](https://github.com/open-feature/java-sdk/blob/main/src/main/java/dev/openfeature/sdk/ProviderRepository.java#L107-L108) and [Go](https://github.com/open-feature/go-sdk/blob/main/pkg/openfeature/api.go#L173). Most of this is test and formatting changes (I had to update the tests not to use the same object literal). The import change is the single line here. Note: it's likely this will break _some_ providers that didn't implement `status`. I think the [flagd web provider](https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd-web/src/lib/flagd-web-provider.ts), [GoFF](https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.ts) provider and the [config-cat](https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/config-cat/src/lib/config-cat-provider.ts) could be impacted. I created issues for these: - open-feature/js-sdk-contrib#488 - open-feature/js-sdk-contrib#489 - open-feature/js-sdk-contrib#490 Fixes: #505 I've also removed all the `setTimeouts` in our test suite. Everything is working "properly" now with plain events, since all flagd providers are fully updated. --------- Signed-off-by: Todd Baert <[email protected]>
1 parent 8734b77 commit 5e320ae

File tree

8 files changed

+217
-197
lines changed

8 files changed

+217
-197
lines changed

package-lock.json

Lines changed: 52 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"node": ">=16"
3535
},
3636
"devDependencies": {
37-
"@openfeature/flagd-provider": "^0.7.6",
38-
"@openfeature/flagd-web-provider": "^0.3.4",
37+
"@openfeature/flagd-provider": "^0.8.1",
38+
"@openfeature/flagd-web-provider": "^0.3.5",
3939
"@rollup/plugin-alias": "^5.0.0",
4040
"@rollup/plugin-typescript": "^11.0.0",
4141
"@types/events": "^3.0.0",

packages/client/e2e/step-definitions/evaluation.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ const client = OpenFeature.getClient();
1717
const givenAnOpenfeatureClientIsRegisteredWithCacheDisabled = (
1818
given: (stepMatcher: string, stepDefinitionCallback: () => void) => void
1919
) => {
20-
// TODO: when the FlagdProvider is updated to support caching, we may need to disable it here for this test to work as expected.
2120
given('a provider is registered with cache disabled', () => undefined);
2221
};
2322

2423
defineFeature(feature, (test) => {
2524
beforeAll((done) => {
2625
client.addHandler(ProviderEvents.Ready, async () => {
27-
setTimeout(() => {
28-
done(); // TODO remove this once flagd provider properly implements readiness (for now, we add a 2s wait).
29-
}, 2000);
26+
done();
3027
});
3128
});
3229

packages/client/e2e/step-definitions/setup.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ import assert from 'assert';
22
import { OpenFeature } from '../..';
33
import { FlagdWebProvider } from '@openfeature/flagd-web-provider';
44

5-
const FLAGD_NAME = 'flagd-web';
5+
const FLAGD_WEB_NAME = 'flagd-web';
66

77
// register the flagd provider before the tests.
88
console.log('Setting flagd web provider...');
9-
OpenFeature.setProvider(
10-
new FlagdWebProvider({
11-
host: 'localhost',
12-
port: 8013,
13-
tls: false,
14-
maxRetries: -1,
15-
})
16-
);
9+
OpenFeature.setProvider(new FlagdWebProvider({
10+
host: 'localhost',
11+
port: 8013,
12+
tls: false,
13+
maxRetries: -1,
14+
}));
1715
assert(
18-
OpenFeature.providerMetadata.name === FLAGD_NAME,
19-
new Error(`Expected ${FLAGD_NAME} provider to be configured, instead got: ${OpenFeature.providerMetadata.name}`)
16+
OpenFeature.providerMetadata.name === FLAGD_WEB_NAME,
17+
new Error(`Expected ${FLAGD_WEB_NAME} provider to be configured, instead got: ${OpenFeature.providerMetadata.name}`)
2018
);
2119
console.log('flagd web provider configured!');

0 commit comments

Comments
 (0)