fix: cast sequence number to bigint depth provider update, add captureException for update skip (#1895)

This commit is contained in:
Bartłomiej Głownia 2022-10-28 09:58:56 +02:00 committed by GitHub
parent 1cf398ad5f
commit 0be668ae86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -1,12 +1,13 @@
import { update } from './market-depth-provider'; import { update } from './market-depth-provider';
import { captureException } from '@sentry/react';
const mockCaptureException = jest.fn();
const reload = jest.fn(); const reload = jest.fn();
jest.mock('@sentry/react', () => { jest.mock('@sentry/react', () => {
const original = jest.requireActual('@sentry/react'); // Step 2. const original = jest.requireActual('@sentry/react'); // Step 2.
return { return {
...original, ...original,
captureException: jest.fn(), captureException: () => mockCaptureException(),
}; };
}); });
@ -15,7 +16,10 @@ jest.mock('./orderbook-data', () => ({
})); }));
describe('market depth provider update', () => { describe('market depth provider update', () => {
it('omits overlapping updates', () => { beforeEach(() => {
mockCaptureException.mockClear();
});
it('omits not matching market', () => {
const data = { const data = {
id: '1', id: '1',
depth: { depth: {
@ -31,7 +35,7 @@ describe('market depth provider update', () => {
expect(updatedData).toBe(data); expect(updatedData).toBe(data);
}); });
it('omits not matching market', () => { it('omits overlapping updates', () => {
const data = { const data = {
id: '1', id: '1',
depth: { depth: {
@ -52,6 +56,7 @@ describe('market depth provider update', () => {
]; ];
expect(update(data, delta.slice(0, 1), reload)).toBe(data); expect(update(data, delta.slice(0, 1), reload)).toBe(data);
expect(update(data, delta.slice(1, 2), reload)).toBe(data); expect(update(data, delta.slice(1, 2), reload)).toBe(data);
expect(mockCaptureException).toBeCalledTimes(2);
}); });
it('restarts and captureException when there is gap in updates', () => { it('restarts and captureException when there is gap in updates', () => {
@ -71,6 +76,6 @@ describe('market depth provider update', () => {
const updatedData = update(data, delta, reload); const updatedData = update(data, delta, reload);
expect(updatedData).toBe(data); expect(updatedData).toBe(data);
expect(reload).toBeCalled(); expect(reload).toBeCalled();
expect(captureException).toBeCalled(); expect(mockCaptureException).toBeCalled();
}); });
}); });

View File

@ -23,13 +23,18 @@ export const update: Update<
if (delta.marketId !== data.id) { if (delta.marketId !== data.id) {
continue; continue;
} }
if (Number(delta.sequenceNumber) <= Number(data.depth.sequenceNumber)) { if (BigInt(delta.sequenceNumber) <= BigInt(data.depth.sequenceNumber)) {
captureException(
new Error(
`Sequence number from delta is lower or equal to last sequenceNumber for ${data.id}, ${delta.sequenceNumber} <= ${data.depth.sequenceNumber}, update skipped`
)
);
return data; return data;
} }
if (delta.previousSequenceNumber !== data.depth.sequenceNumber) { if (delta.previousSequenceNumber !== data.depth.sequenceNumber) {
captureException( captureException(
new Error( new Error(
`Sequence number gap in marketsDepthUpdate for {data.id}, {sequenceNumbers[delta.marketId]} - {delta.previousSequenceNumber}` `Sequence number gap between delta previousSequenceNumber and stored sequence number in marketsDepthUpdate for market ${data.id}; ${delta.previousSequenceNumber} !== ${data.depth.sequenceNumber}, data provider reload`
) )
); );
reload(); reload();