From 2e1222556ff8bd3923a5e91174f7d6bd92d6a02c Mon Sep 17 00:00:00 2001 From: amaurer Date: Sun, 7 Oct 2018 12:24:42 -0400 Subject: Changed getWatchedOrders to getStats and returns Stats object --- packages/order-watcher/CHANGELOG.json | 2 +- packages/order-watcher/src/order_watcher/order_watcher.ts | 12 +++++++++--- packages/order-watcher/test/order_watcher_test.ts | 10 +++++----- packages/types/src/index.ts | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) (limited to 'packages') diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index 6d1256d9e..7b8416428 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -3,7 +3,7 @@ "version": "2.1.2", "changes": [ { - "note": "Added getWatchCounts function" + "note": "Added getStats function and returns a Stats object" } ], "timestamp": 1538836030 diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index e59b56b90..4401b3f7e 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -57,6 +57,10 @@ interface OrderStateByOrderHash { [orderHash: string]: OrderState; } +export interface Stats { + orderCount: number; +} + const DEFAULT_ORDER_WATCHER_CONFIG: OrderWatcherConfig = { orderExpirationCheckingIntervalMs: 50, eventPollingIntervalMs: 200, @@ -214,10 +218,12 @@ export class OrderWatcher { intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists); } /** - * Gets number of orderHashes currently being watched by the order watcher instance. + * Gets statistics of the OrderWatcher Instance. */ - public getWatchCount(): number { - return _.size(this._orderByOrderHash); + public getStats(): Stats { + return { + orderCount : _.size(this._orderByOrderHash), + }; } private async _cleanupAsync(): Promise { for (const orderHash of _.keys(this._orderByOrderHash)) { diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index f1dbe9b2f..4545f84bf 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -140,8 +140,8 @@ describe('OrderWatcher', () => { expect(() => orderWatcher.subscribe(_.noop.bind(_))).to.throw(OrderWatcherError.SubscriptionAlreadyPresent); }); }); - describe('#getWatchCount', async () => { - it('should increment and decrement order counts', async () => { + describe('#getStats', async () => { + it('orderCount should increment and decrement with order additions and removals', async () => { signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerAssetData, takerAssetData, @@ -150,11 +150,11 @@ describe('OrderWatcher', () => { fillableAmount, ); const orderHash = orderHashUtils.getOrderHashHex(signedOrder); - expect(orderWatcher.getWatchCount()).to.be.eq(0); + expect(orderWatcher.getStats().orderCount).to.be.eq(0); await orderWatcher.addOrderAsync(signedOrder); - expect(orderWatcher.getWatchCount()).to.be.eq(1); + expect(orderWatcher.getStats().orderCount).to.be.eq(1); orderWatcher.removeOrder(orderHash); - expect(orderWatcher.getWatchCount()).to.be.eq(0); + expect(orderWatcher.getStats().orderCount).to.be.eq(0); }); }); describe('tests with cleanup', async () => { diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 3ae0536d5..0ea7d433a 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -598,4 +598,4 @@ export interface Metadata { exportPathOrder: string[]; externalTypeToLink: ExternalTypeToLink; externalExportToLink: ExternalExportToLink; -} +} \ No newline at end of file -- cgit