From c732dee31cd871cc51cbb5f30ff0230d847c28fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Thu, 17 Oct 2024 18:27:40 +0200 Subject: [PATCH] fix: handle rounds with zero retrieval tasks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- lib/tasker.js | 8 +++++--- test/tasker.test.js | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/tasker.js b/lib/tasker.js index 445d2509..65d0c67b 100644 --- a/lib/tasker.js +++ b/lib/tasker.js @@ -33,9 +33,11 @@ export async function getTasksAllowedForStations (roundDetails, randomness, meas if (tasksAllowedForStations.has(m.stationId)) continue const stationKey = await getStationKey(m.stationId) - const allowedTasks = seeker - .wHeap(stationKey, numberOfTasksToPick) - .map(({ key, ...t }) => (t)) + const allowedTasks = numberOfTasksToPick + ? seeker + .wHeap(stationKey, numberOfTasksToPick) + .map(({ key, ...t }) => (t)) + : [] tasksAllowedForStations.set(m.stationId, allowedTasks) } diff --git a/test/tasker.test.js b/test/tasker.test.js index d847e0b6..f4c2f2c8 100644 --- a/test/tasker.test.js +++ b/test/tasker.test.js @@ -78,4 +78,17 @@ describe('tasksAllowedForStations', async () => { assert.strictEqual(tasksAllowedForStations.get(VALID_MEASUREMENT.stationId)?.length, 2) }) + + it('handles round with zero tasks', async () => { + /** @type {Measurement[]} */ + const measurements = [VALID_MEASUREMENT] + + const tasksAllowedForStations = await getTasksAllowedForStations( + { retrievalTasks: [], maxTasksPerNode: 0 }, + RANDOMNESS, + measurements + ) + + assert.strictEqual(tasksAllowedForStations.get(VALID_MEASUREMENT.stationId)?.length, 0) + }) })