From bd1ae09177328bc9a8f40fd46f7b8708fb4b7bd9 Mon Sep 17 00:00:00 2001 From: Danny Paz Date: Wed, 15 May 2019 13:47:33 -0700 Subject: [PATCH 1/3] added amounts for insufficient funds errors updated enum to have unknown default value Fix - Error messaging for insufficient funds and filling orders (#522) * added amounts for insufficient funds errors * error logging for filling own order added amounts for insufficient funds errors (#523) updated enum to have unknown default value add command to validate proto file and update circleci to check added run: to circleci command remove unused file s update circle config to install protoc install protoc try to update repos try to fix apt-get add protoc installation for circle ci try new circle setup for protoc added config use unzip instead of tar fix jessie for deps added protoc check for circle ci readd package command and remove apt-get install of protoc stuff all your protoc are belong to us echo bash env echo bash env hail mary use 64 instead run file remove help file Fix/network status slow (#524) * added amounts for insufficient funds errors updated enum to have unknown default value Fix - Error messaging for insufficient funds and filling orders (#522) * added amounts for insufficient funds errors * error logging for filling own order add logs to check time for network status added amounts for insufficient funds errors (#523) updated enum to have unknown default value add command to validate proto file and update circleci to check added run: to circleci command remove unused file s update circle config to install protoc install protoc try to update repos try to fix apt-get add protoc installation for circle ci try new circle setup for protoc added config use unzip instead of tar fix jessie for deps added protoc check for circle ci readd package command and remove apt-get install of protoc stuff all your protoc are belong to us echo bash env echo bash env hail mary use 64 instead run file remove help file fix the way we inflate all block orders add more logging for testing edits to deadline for network status and removed dev logs from active fund calc * added check for deadline params * fix test with market * change from string to number * fix deadline usage in order summary and wallet * fix tests for deadline changes add json flag for healthcheck --- broker-cli/commands/health-check.js | 14 ++++++++++-- broker-cli/commands/health-check.spec.js | 29 +++++++++++++++++------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/broker-cli/commands/health-check.js b/broker-cli/commands/health-check.js index b8ec7022..f6dd7771 100644 --- a/broker-cli/commands/health-check.js +++ b/broker-cli/commands/health-check.js @@ -58,16 +58,25 @@ const ENGINE_STATUS_CODES = Object.freeze({ */ async function healthCheck (args, opts, logger) { - const { rpcAddress } = opts + const { + rpcAddress, + json + } = opts try { const client = new BrokerDaemonClient(rpcAddress) + const res = await client.adminService.healthCheck({}) + + if (json) { + return console.log(JSON.stringify(res)) + } + const { engineStatus = [], orderbookStatus: orderbookStatuses = [], relayerStatus = STATUS_CODES.UNKNOWN - } = await client.adminService.healthCheck({}) + } = res const healthcheckTable = new Table({ head: ['Component', 'Status'], @@ -114,5 +123,6 @@ module.exports = (program) => { program .command('healthcheck', 'Checks the connection between Broker and the Exchange') .option('--rpc-address [rpc-address]', RPC_ADDRESS_HELP_STRING, validations.isHost) + .option('--json', 'Export result as json', program.BOOL, false) .action(healthCheck) } diff --git a/broker-cli/commands/health-check.spec.js b/broker-cli/commands/health-check.spec.js index 05fb7cf8..d183718e 100644 --- a/broker-cli/commands/health-check.spec.js +++ b/broker-cli/commands/health-check.spec.js @@ -12,7 +12,6 @@ describe('healthCheck', () => { let args let opts let logger - let revert let infoSpy let errorSpy let healthCheckStub @@ -20,17 +19,23 @@ describe('healthCheck', () => { let rpcAddress let instanceTableStub let tableStub - let revertTable + let jsonStub + let healthCheckResponse + let reverts const healthCheck = program.__get__('healthCheck') beforeEach(() => { + reverts = [] + jsonStub = { + stringify: sinon.stub() + } rpcAddress = undefined args = {} opts = { rpcAddress } infoSpy = sinon.spy() errorSpy = sinon.spy() - healthCheckStub = sinon.stub().returns({ + healthCheckResponse = { engineStatus: [ { symbol: 'BTC', status: 'VALIDATED' }, { symbol: 'LTC', status: 'NOT_SYNCED' } @@ -40,15 +45,17 @@ describe('healthCheck', () => { { market: 'BTC/LTC', status: 'ORDERBOOK_OK' }, { market: 'ABC/XYZ', status: 'ORDERBOOK_NOT_SYNCED' } ] - }) + } + healthCheckStub = sinon.stub().returns(healthCheckResponse) instanceTableStub = { push: sinon.stub() } tableStub = sinon.stub().returns(instanceTableStub) - revertTable = program.__set__('Table', tableStub) brokerStub = sinon.stub() brokerStub.prototype.adminService = { healthCheck: healthCheckStub } - revert = program.__set__('BrokerDaemonClient', brokerStub) + reverts.push(program.__set__('Table', tableStub)) + reverts.push(program.__set__('BrokerDaemonClient', brokerStub)) + reverts.push(program.__set__('JSON', jsonStub)) logger = { info: infoSpy, @@ -57,8 +64,7 @@ describe('healthCheck', () => { }) afterEach(() => { - revert() - revertTable() + reverts.forEach(r => r()) }) it('makes a request to the broker', async () => { @@ -66,6 +72,13 @@ describe('healthCheck', () => { expect(healthCheckStub).to.have.been.called() }) + it('returns json if the user specifies a json flag', async () => { + opts.json = true + await healthCheck(args, opts, logger) + expect(instanceTableStub.push).to.not.have.been.called() + expect(jsonStub.stringify).to.have.been.calledWith(healthCheckResponse) + }) + it('adds engine statuses to the healthcheck table', async () => { await healthCheck(args, opts, logger) expect(instanceTableStub.push).to.have.been.calledWith(['BTC Engine', 'OK'.green]) From 5f0e2dd80953df74a14b520a07ee8d2f491cc33d Mon Sep 17 00:00:00 2001 From: Danny Paz Date: Fri, 24 May 2019 13:40:11 -0700 Subject: [PATCH 2/3] use logger instead of console and pretty print it --- broker-cli/commands/health-check.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/broker-cli/commands/health-check.js b/broker-cli/commands/health-check.js index f6dd7771..b955c76b 100644 --- a/broker-cli/commands/health-check.js +++ b/broker-cli/commands/health-check.js @@ -69,7 +69,7 @@ async function healthCheck (args, opts, logger) { const res = await client.adminService.healthCheck({}) if (json) { - return console.log(JSON.stringify(res)) + return logger.info(JSON.stringify(res, null, 2)) } const { From ac2a170f74cc032d4516e8b5e0cd05d619242446 Mon Sep 17 00:00:00 2001 From: Danny Paz Date: Fri, 24 May 2019 13:52:13 -0700 Subject: [PATCH 3/3] added log check for healthcheck cli test --- broker-cli/commands/health-check.spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/broker-cli/commands/health-check.spec.js b/broker-cli/commands/health-check.spec.js index d183718e..8ec208e9 100644 --- a/broker-cli/commands/health-check.spec.js +++ b/broker-cli/commands/health-check.spec.js @@ -74,9 +74,12 @@ describe('healthCheck', () => { it('returns json if the user specifies a json flag', async () => { opts.json = true + const result = 'result' + jsonStub.stringify.returns(result) await healthCheck(args, opts, logger) expect(instanceTableStub.push).to.not.have.been.called() expect(jsonStub.stringify).to.have.been.calledWith(healthCheckResponse) + expect(logger.info).to.have.been.calledWith(result) }) it('adds engine statuses to the healthcheck table', async () => {