Skip to content

Commit 9393a5d

Browse files
committed
init throws for double invocation
1 parent ce0d4ae commit 9393a5d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/feature-toggles.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,9 +1002,10 @@ class FeatureToggles {
10021002
* @param {InitializeOptions} [options]
10031003
*/
10041004
async initializeFeatures(options) {
1005-
if (!this.__initializePromise) {
1006-
this.__initializePromise = this._initializeFeatures(options);
1005+
if (this.__initializePromise) {
1006+
throw new VError({ name: VERROR_CLUSTER_NAME }, "already initialized");
10071007
}
1008+
this.__initializePromise = this._initializeFeatures(options);
10081009
return await this.__initializePromise;
10091010
}
10101011

test/integration-local/feature-toggles.integration.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ describe("local integration test", () => {
7373
},
7474
};
7575

76+
test("init throws for double invocation", async () => {
77+
await toggles.initializeFeatures();
78+
await expect(toggles.initializeFeatures()).rejects.toMatchInlineSnapshot(
79+
`[FeatureTogglesError: already initialized]`
80+
);
81+
});
82+
7683
test("init throws for non-existing filepaths", async () => {
7784
mockReadFile.mockImplementationOnce(fsActual.readFile);
7885
await expect(toggles.initializeFeatures({ configFile: "fantasy_name" })).rejects.toMatchInlineSnapshot(

0 commit comments

Comments
 (0)