From: Ardis Lu Date: Wed, 26 Feb 2025 19:22:54 +0000 (-0800) Subject: Add test for interval with 1 retry X-Git-Tag: v0.1.0~37 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=750d9884cdd66ef22e7d3b807d02c8f7b358b5fd;p=csvio Add test for interval with 1 retry --- diff --git a/test/errorStrategies.test.js b/test/errorStrategies.test.js index 2ea3b98..3fb2daa 100644 --- a/test/errorStrategies.test.js +++ b/test/errorStrategies.test.js @@ -87,7 +87,7 @@ suite('ErrorStrategies.placeholder', { concurrency: true }, () => { }); }); -suite('ErrorStrategies.retry', { concurrency: true }, () => { +suite('ErrorStrategies.retry', { concurrency: 1 }, () => { // TODO: concurrency does not work when mocking utils.sleep test('retries until successful (1 retry, 2 total calls)', async () => { const fn = retryFactory(2); // 1st try + 1 retry = 2 total calls await createCSVMockStream([ @@ -133,9 +133,22 @@ suite('ErrorStrategies.retry', { concurrency: true }, () => { [10] ])); }); - test('retries with interval', async (t) => { + test('retries with interval (1 retry)', async (t) => { + assertSleep(t, { min: 1000, max: 1100 }); + const fn = retryFactory(2); // 1st try + 1 retry = pass on 2nd + await createCSVMockStream([ + ['header'], + ['0'] + ]) + .pipeThrough(new CSVTransformer(fn, { onError: retry(1, { interval: 1000 }) })) + .pipeTo(csvStreamEqualWritable([ + ['header'], + [2] + ])); + }); + test('retries with interval (10 retries)', async (t) => { assertSleep(t, { min: 10 * 1000, max: 10 * 1000 + 1000 }); - const fn = retryFactory(11); // 1st try + 10 retries = pass on 11th with extra retries available + const fn = retryFactory(11); // 1st try + 10 retries = pass on 11th await createCSVMockStream([ ['header'], ['0']