Spaces:
Running
Running
Download tests/read-batches.test.ts from Shoraky/Sporalize-api: direct link, hf CLI and curl.
- Browser
- Download file 920 Bytes
-
https://huggingface.co/spaces/Shoraky/Sporalize-api/resolve/main/tests/read-batches.test.ts
- Command line
-
hf download hf://spaces/Shoraky/Sporalize-api/tests/read-batches.test.ts
-
curl -L -o read-batches.test.ts https://huggingface.co/spaces/Shoraky/Sporalize-api/resolve/main/tests/read-batches.test.ts
920 Bytes
| import assert from "node:assert/strict"; | |
| import { test } from "node:test"; | |
| import { readBatches } from "../src/read-batches.js"; | |
| test("caps concurrent reads, keeps result order and includes the final partial batch", async () => { | |
| let active = 0; | |
| let peak = 0; | |
| const input = Array.from({ length: 23 }, (_, index) => index); | |
| const output = await readBatches(input, async (batch) => { | |
| peak = Math.max(peak, ++active); | |
| await new Promise((resolve) => setTimeout(resolve, batch[0] % 2 ? 1 : 5)); | |
| active--; | |
| return batch; | |
| }, 5, 3); | |
| assert.equal(peak, 3); | |
| assert.deepEqual(output, input); | |
| }); | |
| test("does not query empty input or return incomplete results after failure", async () => { | |
| assert.deepEqual(await readBatches([], () => { throw new Error("should not run"); }), []); | |
| await assert.rejects(readBatches([1, 2], async () => { throw new Error("DB unavailable"); }), /DB unavailable/); | |
| }); | |