From bd3f101ab8735f97646d1031126fb9e55b67a93d Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 10:06:34 -0400 Subject: Added orderWatchCount to return total count of orders watched. --- .../order-watcher/src/order_watcher/order_watcher.ts | 3 +++ packages/order-watcher/test/order_watcher_test.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'packages') diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index f9a63efe3..9b2999285 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -213,6 +213,9 @@ export class OrderWatcher { this._expirationWatcher.unsubscribe(); intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists); } + public getWatchCount(): number { + return _.size(this._orderByOrderHash); + } private async _cleanupAsync(): Promise { for (const orderHash of _.keys(this._orderByOrderHash)) { this._cleanupOrderRelatedState(orderHash); diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index 60d9069e8..f504dda8e 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -140,6 +140,23 @@ describe('OrderWatcher', () => { expect(() => orderWatcher.subscribe(_.noop.bind(_))).to.throw(OrderWatcherError.SubscriptionAlreadyPresent); }); }); + describe('#getWatchCount', async () => { + it('should increment and decrement order counts', async() => { + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerAssetData, + takerAssetData, + makerAddress, + takerAddress, + fillableAmount, + ); + const orderHash = orderHashUtils.getOrderHashHex(signedOrder); + expect(orderWatcher.getWatchCount()).to.be.eq(0); + await orderWatcher.addOrderAsync(signedOrder); + expect(orderWatcher.getWatchCount()).to.be.eq(1); + orderWatcher.removeOrder(orderHash); + expect(orderWatcher.getWatchCount()).to.be.eq(0); + }); + }); describe('tests with cleanup', async () => { afterEach(async () => { orderWatcher.unsubscribe(); -- cgit v1.2.3