From 66e8386707b1bb3b31b5eba9f0711e69908ac557 Mon Sep 17 00:00:00 2001 From: Dave Kelsey <25582377+davidkel@users.noreply.github.com> Date: Wed, 6 Apr 2022 09:21:26 +0100 Subject: [PATCH] remove latency values if no successful txns in final report (#1290) closes #1065 Signed-off-by: D --- packages/caliper-core/lib/manager/report/report.js | 4 ++-- packages/caliper-core/test/manager/report/report.js | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/caliper-core/lib/manager/report/report.js b/packages/caliper-core/lib/manager/report/report.js index f1bce823d..a9cb3e1ff 100644 --- a/packages/caliper-core/lib/manager/report/report.js +++ b/packages/caliper-core/lib/manager/report/report.js @@ -156,8 +156,8 @@ class Report { resultMap.set('Name', testLabel ? testLabel : 'unknown'); resultMap.set('Succ', results.getTotalSuccessfulTx()); resultMap.set('Fail', results.getTotalFailedTx()); - resultMap.set('Max Latency (s)', CaliperUtils.millisToSeconds(results.getMaxLatencyForSuccessful()).toFixed(2)); - resultMap.set('Min Latency (s)', CaliperUtils.millisToSeconds(results.getMinLatencyForSuccessful()).toFixed(2)); + resultMap.set('Max Latency (s)', results.getTotalSuccessfulTx() > 0 ? CaliperUtils.millisToSeconds(results.getMaxLatencyForSuccessful()).toFixed(2) : '-'); + resultMap.set('Min Latency (s)', results.getTotalSuccessfulTx() > 0 ? CaliperUtils.millisToSeconds(results.getMinLatencyForSuccessful()).toFixed(2) : '-'); resultMap.set('Avg Latency (s)', results.getTotalSuccessfulTx() > 0 ? (CaliperUtils.millisToSeconds(results.getTotalLatencyForSuccessful() / results.getTotalSuccessfulTx())).toFixed(2) : '-'); // Send rate diff --git a/packages/caliper-core/test/manager/report/report.js b/packages/caliper-core/test/manager/report/report.js index 4a00fb207..d19e625d1 100644 --- a/packages/caliper-core/test/manager/report/report.js +++ b/packages/caliper-core/test/manager/report/report.js @@ -82,6 +82,7 @@ describe('report implementation', () => { it('should set Max Latency to 2DP if available', () => { const report = new Report(); const txnStats = new TransactionStatisticsCollector(); + txnStats.stats.txCounters.totalSuccessful = 100; txnStats.stats.latency.successful.max = 1232.2; const output = report.getResultValues('myTestLabel', txnStats ); @@ -91,18 +92,21 @@ describe('report implementation', () => { it('should set Min Latency to 2DP if available', () => { const report = new Report(); const txnStats = new TransactionStatisticsCollector(); + txnStats.stats.txCounters.totalSuccessful = 100; txnStats.stats.latency.successful.min = 232.2; const output = report.getResultValues('myTestLabel', txnStats); output.get('Min Latency (s)').should.equal('0.23'); }); - it('should set Avg Latency to `-` if no successful transactions', () => { + it('should set Min/Max/Avg Latency to `-` if no successful transactions', () => { const report = new Report(); const txnStats = new TransactionStatisticsCollector(); - + txnStats.stats.txCounters.totalSuccessful = 0; const output = report.getResultValues('myTestLabel', txnStats); output.get('Avg Latency (s)').should.equal('-'); + output.get('Min Latency (s)').should.equal('-'); + output.get('Max Latency (s)').should.equal('-'); }); it('should set Avg Latency to 2DP if available', () => {