From: Jérôme Benoit Date: Sun, 27 Aug 2023 20:09:42 +0000 (+0200) Subject: fix: fix worker usage statistics handling X-Git-Tag: v2.6.37~24 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=bdb9d7125f62a36dd65cba6aa9110ce269359f0a;p=poolifier.git fix: fix worker usage statistics handling Signed-off-by: Jérôme Benoit --- 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', () => {