Skip to content

Conversation

@rolodato
Copy link
Contributor

When using local evaluation mode, the environment document is immediately fetched twice on when Flagsmith is instantiated. This can be observed by spinning up a dummy HTTP server:

python -m http.server

and then point the client to it:

import Flagsmith from "flagsmith-nodejs"

const flagsmith = new Flagsmith({
  environmentKey: "ser.foo",
  apiUrl: "http://127.0.0.1:8000",
  enableLocalEvaluation: true,
})

On startup, we can see that GET /environment-document is immediately called twice:

::ffff:127.0.0.1 - - [29/Apr/2024 08:48:33] code 404, message File not found
::ffff:127.0.0.1 - - [29/Apr/2024 08:48:33] code 404, message File not found
::ffff:127.0.0.1 - - [29/Apr/2024 08:48:33] "GET /environment-document/ HTTP/1.1" 404 -
::ffff:127.0.0.1 - - [29/Apr/2024 08:48:33] "GET /environment-document/ HTTP/1.1" 404 -

I was hoping to add this to a test to make it fail, but it does not - something might be happening with Jest and fetch being called from a setInterval:

diff --git a/tests/sdk/flagsmith-environment-flags.test.ts b/tests/sdk/flagsmith-environment-flags.test.ts
index 6262762..33f9676 100644
--- a/tests/sdk/flagsmith-environment-flags.test.ts
+++ b/tests/sdk/flagsmith-environment-flags.test.ts
@@ -191,6 +191,7 @@ test('test_local_evaluation', async () => {
   const flags = await flg.getEnvironmentFlags();
   const flag = flags.getFlag('some_feature');
 
+  expect(fetch).toBeCalledTimes(1);
   expect(flag.isDefault).toBe(false);
   expect(flag.value).not.toBe(defaultFlag.value);
   expect(flag.value).toBe('some-value');

@matthewelwell
Copy link
Contributor

@rolodato heads up that you've got CI failures here

@rolodato rolodato marked this pull request as draft May 8, 2024 10:24
@rolodato
Copy link
Contributor Author

rolodato commented May 8, 2024

Thanks, updated this PR to be a draft until I can get back to it.

@matthewelwell
Copy link
Contributor

Superseded by this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants