Added orderWatchCount to return total count of orders watched.

This commit is contained in:
amaurer
2018-10-06 10:06:34 -04:00
parent 119f8c9449
commit bd3f101ab8
2 changed files with 20 additions and 0 deletions

View File

@@ -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<void> {
for (const orderHash of _.keys(this._orderByOrderHash)) {
this._cleanupOrderRelatedState(orderHash);

View File

@@ -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();