Skip to content

test: add cleanup tests for RateTicker interval lifecycle - #518

Open
ZacLou wants to merge 3 commits into
conduit-protocol:mainfrom
ZacLou:fix/rateticker-rAF-cleanup-465
Open

test: add cleanup tests for RateTicker interval lifecycle#518
ZacLou wants to merge 3 commits into
conduit-protocol:mainfrom
ZacLou:fix/rateticker-rAF-cleanup-465

Conversation

@ZacLou

@ZacLou ZacLou commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses #465

Context

The issue asks to confirm the update loop is cancelled on unmount and when ratePerSecond changes, and to add tests.

The RateTicker component uses setInterval (not requestAnimationFrame) for its 100ms tick. The cleanup is already correctly handled via the useEffect return function (() => clearInterval(id)), which runs both on unmount and whenever ratePerSecond, endTime, or decimals change.

Changes

Added 3 new tests to components/stream/__tests__/RateTicker.test.tsx:

  1. clears the interval on unmount — spies on setInterval/clearInterval, unmounts the component, and asserts the interval ID was passed to clearInterval
  2. clears the old interval when ratePerSecond changes — renders with one rate, re-renders with a different rate, and asserts the first interval was cleared before the second was created
  3. reflects the new rate after ratePerSecond changes — verifies the displayed amount uses the new rate after the prop changes

No production code changes — the existing cleanup is correct.

…rSecond change

Confirms the setInterval loop is properly cancelled on unmount and when
ratePerSecond changes (via useEffect cleanup). Adds three new tests:
- clears the interval on unmount (no stale intervals)
- clears the old interval when ratePerSecond changes
- reflects the new rate after ratePerSecond changes

Addresses conduit-protocol#465
@ZacLou
ZacLou force-pushed the fix/rateticker-rAF-cleanup-465 branch from 5750d46 to 87616fb Compare September 5, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants