Skip to content

test: add e2e checks for the evaluation sync status listener - #358

Draft
duyhungtnn wants to merge 9 commits into
feat/status-listenerfrom
test/e2e-status-listener
Draft

duyhungtnn wants to merge 9 commits into
feat/status-listenerfrom
test/e2e-status-listener

Conversation

@duyhungtnn

Copy link
Copy Markdown
Collaborator

Part of #355. Builds on #357.

What

E2E checks for the evaluation sync status, against the real backend:

Test Checks
New: successful init (polling) A listener added before the init await gets SYNCED. lastSyncedAt is set, lastError is null.
Stream opens during init SYNCED, no error.
REST unavailable, values from the stream Ends SYNCED. lastError keeps the init TimeoutException (source POLLING).
New: wrong API key Init rejects with ForbiddenException. The stream gets 401, so the SDK falls back to polling, which gets 403 again. The status ends FAILING with the polling error.

Notes

Apps can now see when updating flag values (polling or streaming) fails
and when it works again.

- New public API on BKTClient: evaluationSyncStatus(),
  addEvaluationSyncStatusListener(), removeEvaluationSyncStatusListener(),
  clearEvaluationSyncStatusListeners().
- New exported types: BKTEvaluationSyncStatus, BKTEvaluationSyncState,
  BKTEvaluationSyncSource, BKTEvaluationSyncError,
  BKTEvaluationSyncStatusListener.
- States: INITIALIZING, SYNCED, FAILING, DESTROYED. Listeners are called
  on every state change and on every failure that is not ignored.
- Stream failures now give the same BKTException types as polling.
  StreamConnection reports raw facts, StreamingTask maps them, and
  statusToBKTException is the one shared HTTP status mapping.
A listener that destroys the client, or removes another listener, no longer
causes a removed listener to be called. Before, the other listeners got
DESTROYED twice.
A sync status listener that calls initializeBKTClient() on DESTROYED now
gets a new client. Before, the old client was still registered, so init
returned early and the old client was removed right after.
…lient during init

A sync status listener can call destroyBKTClient() while TaskScheduler.start() runs, for example when the stream fails to open. TaskScheduler now starts no more tasks after stop(), and scheduleAndFetch() skips the first fetch when the client was destroyed.
… component

destroyBKTClient() now calls a method on the client, like resetTasks() and clearEvaluationUpdateListeners(). No behavior change.
When initializeCache() rejects, the client is removed but its sync status stayed INITIALIZING, so a listener added while init was pending never heard the end. It now gets DESTROYED after clearInstance(), so the listener can start a new client.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The streaming test can pass on the init failure alone without verifying that fallback polling starts or reports its failure.

1 open issue
What changed in this PR

Adds real-backend end-to-end coverage for the evaluation sync status API introduced in #357, supporting #355’s failure and recovery notifications.

Changes:

  • Verifies polling initialization reports SYNCED to a listener registered before awaiting initialization.
  • Adds status and error assertions for successful streaming and recovery after an initialization timeout.
  • Adds a wrong-API-key scenario covering authentication failures and polling fallback.
File Description
e2e/​streaming.spec.ts Adds sync-status assertions and an invalid-key fallback test.
e2e/​BKTClient.spec.ts Tests polling initialization status, timestamps, and listener notification.

Review effort: Balanced

Comment thread e2e/streaming.spec.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified in the added evaluation sync status end-to-end coverage.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@duyhungtnn
duyhungtnn marked this pull request as ready for review November 10, 2026 13:22
@duyhungtnn
duyhungtnn marked this pull request as draft November 19, 2026 09:05
@duyhungtnn
duyhungtnn force-pushed the feat/status-listener branch 2 times, most recently from e4bc637 to 1973bf1 Compare November 26, 2026 08:23
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.

2 participants