Skip to content

Commit

Permalink
fix: remove etag from streaming parsing (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Dec 20, 2024
1 parent 9b95247 commit f94be1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
8 changes: 1 addition & 7 deletions src/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,7 @@ export default class Repository extends EventEmitter implements EventEmitter {

private handleFlagsFromStream(event: { data: string }) {
try {
const data: ClientFeaturesResponse & { meta: { etag: string } } = JSON.parse(event.data);
const etag = data.meta.etag;
if (etag !== null) {
this.etag = etag;
} else {
this.etag = undefined;
}
const data: ClientFeaturesResponse = JSON.parse(event.data);
this.save(data, true);
} catch (err) {
this.emit(UnleashEvents.Error, err);
Expand Down
15 changes: 5 additions & 10 deletions src/test/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ test('Stopping repository should stop storage provider updates', async (t) => {
});

test('Streaming', async (t) => {
t.plan(7);
t.plan(5);
const url = 'http://unleash-test-streaming.app';
const feature = {
name: 'feature',
Expand Down Expand Up @@ -1408,7 +1408,7 @@ test('Streaming', async (t) => {
// first connection is ignored, since we do regular fetch
eventSource.emit('unleash-connected', {
type: 'unleash-connected',
data: JSON.stringify({ meta: {}, features: [{ ...feature, name: 'intialConnectedIgnored' }] }),
data: JSON.stringify({ features: [{ ...feature, name: 'intialConnectedIgnored' }] }),
});

const before = repo.getToggles();
Expand All @@ -1417,22 +1417,17 @@ test('Streaming', async (t) => {
// update with feature
eventSource.emit('unleash-updated', {
type: 'unleash-updated',
data: JSON.stringify({ meta: {}, features: [{ ...feature, name: 'firstUpdate' }] }),
data: JSON.stringify({ features: [{ ...feature, name: 'firstUpdate' }] }),
});
const firstUpdate = repo.getToggles();
t.deepEqual(firstUpdate, [{ ...feature, name: 'firstUpdate' }]);
// @ts-expect-error
t.is(repo.etag, undefined);

// update with etag
eventSource.emit('unleash-updated', {
type: 'unleash-updated',
data: JSON.stringify({ meta: { etag: 'updated' }, features: [] }),
data: JSON.stringify({ features: [] }),
});
const secondUpdate = repo.getToggles();
t.deepEqual(secondUpdate, []);
// @ts-expect-error
t.is(repo.etag, 'updated');

// SSE error translated to repo warning
repo.on('warn', (msg) => {
Expand All @@ -1443,7 +1438,7 @@ test('Streaming', async (t) => {
// re-connect simulation
eventSource.emit('unleash-connected', {
type: 'unleash-connected',
data: JSON.stringify({ meta: {}, features: [{ ...feature, name: 'reconnectUpdate' }] }),
data: JSON.stringify({ features: [{ ...feature, name: 'reconnectUpdate' }] }),
});
const reconnectUpdate = repo.getToggles();
t.deepEqual(reconnectUpdate, [{ ...feature, name: 'reconnectUpdate' }]);
Expand Down

0 comments on commit f94be1d

Please sign in to comment.