You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[P2][test] MemoryGuard's 512 MB floor is hardcoded, so the memory-truncation path cannot be tested #540
execute builds the guard itself (let mut mem_guard = MemoryGuard::new();), so there is no way for a test to choose the floor. Provoking the real one means starving the machine of RAM, which no test should do.
Why it matters
The consequence showed up while fixing #413. When the guard trips, the fetch loop breaks and a block after the loop pushes the partial result with TruncationReason::MemoryGuard. That block is the only thing that produces a memory-truncated result, and it is not exercised by any test.
Everything around it is covered — truncation_for picks the reason, truncationMessage renders it, the banner tests assert both variants, and integration tests confirm the RowLimit reason survives a real round trip. The block that joins them up is not.
Suggested fix
Give the guard an injectable floor and default it to today's value:
Then let execute take one (or take a floor), so an integration test can pass a floor of u64::MAX — always tripping — and assert that a multi-row SELECT comes back with rows_truncated == true and truncation_reason == Some(MemoryGuard). That exercises the real control flow rather than the pieces.
While there, 512 deserves a named constant either way.
Related, and deliberately not folded in
The guard's break may leave the statement running server-side. The timeout path a few lines up explicitly does drop(stream) then KILL QUERY, with a comment saying that abandoning the stream would leave the statement running. The memory path breaks out and does neither.
If that reasoning holds for timeouts it should hold here. I have not verified what sqlx does with a fetch_many stream dropped mid-result, and could not, for the same reason this issue exists — the guard cannot be triggered on demand. Flagging it as a question rather than asserting it is a bug. An injectable floor would make it answerable.
Activity
test(query): make the memory-truncation path reachable
test(query): make the memory-truncation path reachable (#630)