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
TestListVideosOffloading::test_event_loop_stays_responsive_while_scan_is_in_flight
(tests/unit/test_v1_router_extended.py, added in #1382) does not prove the
property its name claims. It passes just as happily against an implementation
that runs the scan inline on the event loop.
The test parks the mocked service on a bounded wait and then counts ticks:
def_block():
release.wait(timeout=2.0) # <- bounded, so it always returns
...
for_inrange(10):
awaitasyncio.sleep(0.01)
ticks.append(1)
assertlen(ticks) >=3
Why it is vacuous
Trace an inline (unfixed) implementation:
step
what happens
1
endpoint calls the service directly on the loop
2
release.wait(timeout=2.0) blocks the loop thread for 2s
3
the timeout expires, _block returns, the endpoint completes
4
control returns to the loop; all 10 ticks now run back to back
5
len(ticks) >= 3 → passes
The bounded timeout is what defeats the test. The ticks are never required to
interleave with the blocking call — they are only required to happen eventually, and they always do once the timeout expires. The assertion
therefore measures nothing about where the work ran.
This was confirmed by CodeRabbit during review of #1388:
TestListVideosOffloading::test_event_loop_stays_responsive_while_scan_is_in_flight
still has the timeout-based vacuity defect. […] the existing test does not
prove the protection it claims to prove.
Evidence the defect is real and detectable
The same weakness was found and fixed in the sibling class added in #1388
(TestLearningLogOffloading). Before the repair, a negative control that
reverted the source to the inline implementation produced 2 failed; after
making the assertion timing-relative it produced 3 failed — the
responsiveness test flipped from silently passing on broken code to correctly
failing on it.
Proposed fix
Make the assertion timing-relative rather than count-only: record a
timestamp per tick and per worker completion, then assert that ticks were
observed while the blocking call was still in flight.
importtime# not currently imported at module scoperelease=threading.Event()
finished_at: dict[str, float] = {}
def_block():
release.wait(timeout=5.0)
finished_at["scan"] =time.monotonic()
...
tick_times.append(time.monotonic()) # per tick, before release.set()
...
concurrent= [tfortintick_timesift<finished_at["scan"]]
assertlen(concurrent) >=3, (
"no loop ticks were observed while the scan was in flight; the scan is ""running inline on the event loop"
)
The other three tests in TestListVideosOffloading (thread-identity,
one-hop, error-contract). Those are sound.
Adding a concurrency bound to list_videos_v1. Track separately if wanted.
Acceptance criteria
test_event_loop_stays_responsive_while_scan_is_in_flight asserts on
timestamps captured before the worker is released.
A negative control that reverts list_videos_v1 to the inline
implementation makes this test fail, and the failure message names the
inline-execution cause.
The repaired test still passes against current main.
Problem
TestListVideosOffloading::test_event_loop_stays_responsive_while_scan_is_in_flight(
tests/unit/test_v1_router_extended.py, added in #1382) does not prove theproperty its name claims. It passes just as happily against an implementation
that runs the scan inline on the event loop.
The test parks the mocked service on a bounded wait and then counts ticks:
Why it is vacuous
Trace an inline (unfixed) implementation:
release.wait(timeout=2.0)blocks the loop thread for 2s_blockreturns, the endpoint completeslen(ticks) >= 3→ passesThe bounded timeout is what defeats the test. The ticks are never required to
interleave with the blocking call — they are only required to happen
eventually, and they always do once the timeout expires. The assertion
therefore measures nothing about where the work ran.
This was confirmed by CodeRabbit during review of #1388:
Evidence the defect is real and detectable
The same weakness was found and fixed in the sibling class added in #1388
(
TestLearningLogOffloading). Before the repair, a negative control thatreverted the source to the inline implementation produced 2 failed; after
making the assertion timing-relative it produced 3 failed — the
responsiveness test flipped from silently passing on broken code to correctly
failing on it.
Proposed fix
Make the assertion timing-relative rather than count-only: record a
timestamp per tick and per worker completion, then assert that ticks were
observed while the blocking call was still in flight.
Out of scope
router.pyor the/api/v1/videosbehaviour. The productionfix from perf: offload /api/v1/videos page read off the event loop #1382 is correct; only the test's proof is weak.
TestListVideosOffloading(thread-identity,one-hop, error-contract). Those are sound.
list_videos_v1. Track separately if wanted.Acceptance criteria
test_event_loop_stays_responsive_while_scan_is_in_flightasserts ontimestamps captured before the worker is released.
list_videos_v1to the inlineimplementation makes this test fail, and the failure message names the
inline-execution cause.
main.src/.