Skip to content

Commit

Permalink
Fix bug with data pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Oct 10, 2023
1 parent e7051c4 commit 43fb2ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/pusher/src/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,22 @@ describe(DelayedSignedDataQueue.name, () => {

expect(queue.getAll()).toStrictEqual([data2, data3]);
});

it('keeps data in the queue if none of the items exceed maxUpdateDelay', () => {
jest.useFakeTimers().setSystemTime(new Date('2023-01-20'));
const queue = new DelayedSignedDataQueue(30);
const data = nodarySignedTemplateResponses[0]![1];
const timestamp = Number.parseInt(data.timestamp, 10);
const oldData = [
{ ...data, timestamp: (timestamp - 20).toString() },
{ ...data, timestamp: (timestamp - 15).toString() },
{ ...data, timestamp: (timestamp - 10).toString() },
];
for (const item of oldData) queue.put(item);

queue.prune();

// All data points remain in the queue.
expect(queue.getAll()).toStrictEqual(oldData);
});
});
1 change: 1 addition & 0 deletions packages/pusher/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export class DelayedSignedDataQueue {
this.isDelayedEnough(data, Date.now() / 1000 - this.maxUpdateDelay)
);

if (index === -1) return;
this.storage = this.storage.slice(index);
}

Expand Down

0 comments on commit 43fb2ba

Please sign in to comment.