From bdb9d7125f62a36dd65cba6aa9110ce269359f0a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 27 Aug 2023 22:09:42 +0200 Subject: [PATCH] fix: fix worker usage statistics handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .c8rc.json | 2 +- CHANGELOG.md | 4 ++++ src/utils.ts | 4 ++++ tests/utils.test.js | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/.c8rc.json b/.c8rc.json index a6da2792..ab1b20fa 100644 --- a/.c8rc.json +++ b/.c8rc.json @@ -3,5 +3,5 @@ "lines": 92, "statements": 92, "functions": 95, - "branches": 90 + "branches": 92 } diff --git a/CHANGELOG.md b/CHANGELOG.md index f4c452a7..6cd21047 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Ensure unused worker usage statistics are deleted at runtime. + ### Changed - Rename worker choice strategy options `choiceRetries` to `retries`. diff --git a/src/utils.ts b/src/utils.ts index 38e15eb6..82c38c09 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -257,9 +257,13 @@ export const updateMeasurementStatistics = ( measurementStatistics.history.push(measurementValue) if (measurementRequirements.average) { measurementStatistics.average = average(measurementStatistics.history) + } else if (measurementStatistics.average != null) { + delete measurementStatistics.average } if (measurementRequirements.median) { measurementStatistics.median = median(measurementStatistics.history) + } else if (measurementStatistics.median != null) { + delete measurementStatistics.median } } } diff --git a/tests/utils.test.js b/tests/utils.test.js index ef7688d6..2c41b692 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -232,6 +232,41 @@ describe('Utils test suite', () => { average: 0.002, history: new CircularArray(DEFAULT_CIRCULAR_ARRAY_SIZE, 0.001, 0.003) }) + updateMeasurementStatistics( + measurementStatistics, + { aggregate: true, average: false, median: true }, + 0.006 + ) + expect(measurementStatistics).toStrictEqual({ + aggregate: 0.04, + maximum: 0.02, + minimum: 0.001, + median: 0.003, + history: new CircularArray( + DEFAULT_CIRCULAR_ARRAY_SIZE, + 0.001, + 0.003, + 0.006 + ) + }) + updateMeasurementStatistics( + measurementStatistics, + { aggregate: true, average: true, median: false }, + 0.01 + ) + expect(measurementStatistics).toStrictEqual({ + aggregate: 0.05, + maximum: 0.02, + minimum: 0.001, + average: 0.005, + history: new CircularArray( + DEFAULT_CIRCULAR_ARRAY_SIZE, + 0.001, + 0.003, + 0.006, + 0.01 + ) + }) }) it('Verify secureRandom() behavior', () => { -- 2.34.1