test: Add regression tests for BTreeIndex infinite loop with undefined keys - #1191
KyleAMathews wants to merge 3 commits into
Conversation
…lues (issue #1186) This test demonstrates the infinite loop bug that occurs when calling take() on a BTreeIndex containing items with undefined indexed values. The bug is in takeInternal() where nextHigherPair(undefined) returns the minimum pair [undefined, undefined], then key is set to pair[0] (undefined), causing the same pair to be returned infinitely since the while condition (pair !== undefined) is always true for arrays. https://claude.ai/code/session_01RKBKXMoKVe1hSXGy3VVEFo
|
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: 0 B Total Size: 90.9 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
|
Closing as superseded by merged PR #1198. The merged runtime fix includes a focused undefined-key BTree regression file and end-to-end ordering coverage, so this earlier standalone test PR is redundant. |
🎯 Changes
This PR adds comprehensive regression tests for GitHub issue #1186, which describes an infinite loop in
BTreeIndex.takeInternalwhen usingorderBy()andlimit()on collections containing items with undefined indexed values.The test suite includes:
take()andtakeReversed()with undefined indexed valuesBTreeIndex.takeInternalwhen using orderBy and limit withundefinedindexed values #1186 using live queries withorderByandlimitwhere,orderBy, andlimitwith undefined valuesAll tests include a 5-second timeout to catch infinite loops during test execution.
Root Cause (documented in test comments):
When
nextHigherPair(undefined)is called, it returns the minimum pair from the B-tree. If that minimum key is itselfundefined, the method returns[undefined, undefined]. After processing, the code setskey = pair[0](which isundefined) and callsnextHigherPair(undefined)again, returning the same pair and creating an infinite loop.✅ Checklist
pnpm test:pr.🚀 Release Impact
Note: This is a test-only addition that documents the bug for future reference and validation once the underlying issue is fixed.
https://claude.ai/code/session_01RKBKXMoKVe1hSXGy3VVEFo