From 119345dff5bbe7728b8f03444df2b59fd5c21c97 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Thu, 5 Nov 2026 01:36:05 +0200 Subject: [PATCH] test(player): compare large byte arrays directly in the range handle tests CI timed out "fetches a read longer than the bound as asked" at 5 s. The read was not slow: toEqual walks a typed array element by element through its generic equality, 1.9 s locally for the two 1 MB comparisons and more on CI's runners. A direct comparison takes the case to 5 ms, and the stream case from 0.65 s to 12 ms. Co-Authored-By: Claude Opus 5.5 --- .../player/tests/unit/range-http-handle.test.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/player/tests/unit/range-http-handle.test.ts b/packages/player/tests/unit/range-http-handle.test.ts index eff37fa1..70774c3a 100644 --- a/packages/player/tests/unit/range-http-handle.test.ts +++ b/packages/player/tests/unit/range-http-handle.test.ts @@ -33,6 +33,17 @@ function countingBody(bytes: Uint8Array, piece = 1024) { return { stream, pulled: () => pulled, cancelled: () => cancelled } } +/** + * Whether two byte arrays are equal, compared directly. `toEqual` walks a typed array element by + * element through its generic equality, which took seconds on a megabyte and timed the case out on + * CI's runners. + */ +function sameBytes(actual: Uint8Array, expected: Uint8Array): boolean { + if (actual.length !== expected.length) return false + for (let i = 0; i < actual.length; i += 1) if (actual[i] !== expected[i]) return false + return true +} + /** A host that honours `Range` over `bytes`, keeping the ranges it was asked for. */ function rangeHost(bytes: Uint8Array) { const asked: string[] = [] @@ -96,7 +107,7 @@ describe('RangeHttpHandle.read', () => { const handle = await openSource('pkg', descriptor) const long = { start: 10, end: 10 + BLOCK_CACHE_MAX_READ } - expect(await handle.read(long)).toEqual(archive.subarray(long.start, long.end + 1)) + expect(sameBytes(await handle.read(long), archive.subarray(long.start, long.end + 1))).toBe(true) await handle.read(long) expect(asked).toEqual([`bytes=${long.start}-${long.end}`, `bytes=${long.start}-${long.end}`]) }) @@ -112,7 +123,7 @@ describe('RangeHttpHandle.stream', () => { expect(asked).toHaveLength(1) const media = { start: 200_000, end: 600_000 } - expect(await collect(await handle.stream(media))).toEqual(archive.subarray(media.start, media.end + 1)) + expect(sameBytes(await collect(await handle.stream(media)), archive.subarray(media.start, media.end + 1))).toBe(true) expect(asked).toEqual([`bytes=0-${BLOCK_SIZE - 1}`, `bytes=${media.start}-${media.end}`]) // Not kept: the cache holds index reads and small entries, not media. await handle.stream(media).then(collect)