Skip to content

Add event listener memory leak detection tests - #175

Merged
malibio merged 2 commits into
mainfrom
feature/issue-162-event-listener-leak-tests
Oct 6, 2025
Merged

malibio merged 2 commits into
mainfrom
feature/issue-162-event-listener-leak-tests

Conversation

@malibio

@malibio malibio commented Oct 6, 2025

Copy link
Copy Markdown
Collaborator

Closes #162

malibio and others added 2 commits October 6, 2025 15:37
Implemented 12 tests across 4 categories to verify proper event listener cleanup:

Component Lifecycle (4 tests):
- NodeAutocomplete removes keydown listener on unmount
- SlashCommandDropdown removes keydown listener on unmount
- No listener accumulation over multiple mount/unmount cycles
- Cleanup resilient to errors during unmount

Rapid Operations (3 tests):
- 100 rapid mount/unmount cycles without leaking
- Listener count returns to baseline after rapid operations
- Acceptable memory usage during mixed component operations

EventBus Subscriptions (3 tests):
- Unsubscribe actually removes handlers
- reset() clears all handlers
- Wildcard subscriptions cleaned up properly

Verification Tools (2 tests):
- Programmatic leak detection capability
- Accurate handler count measurement

All tests verify that document event listeners and EventBus subscriptions are properly cleaned up to prevent memory leaks during normal and edge-case scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Implemented all critical, important, and optional improvements from PR review:

**Critical Fixes:**
- Add handler reference verification (Finding #3)
  - Tests #1 and #2 now verify exact handler reference equality
  - Ensures removeEventListener receives same function reference as addEventListener
  - Prevents common memory leak bug of creating new functions

**Important Improvements:**
- Rename test #4 to match actual behavior (Finding #1)
  - Changed "error during unmount" → "normal unmount lifecycle"
  - Added explanatory comment about Svelte's onDestroy guarantees

- Add explicit cleanup to test #7 (Finding #5)
  - Intentional leak test now properly unmounts component
  - Verifies cleanup worked by checking balance returns to initial state
  - Ensures test isolation and prevents cross-test contamination

**Code Quality Enhancements:**
- Extract helper functions for common spy patterns (Suggestion #4)
  - getKeydownListenerCounts(): Centralizes listener counting logic
  - getKeydownListenerHandlers(): Extracts handler reference tracking
  - measureListenerDelta(): Standard baseline measurement pattern

- Standardize baseline measurement patterns (Finding #2)
  - All rapid operation tests now use consistent slice() pattern
  - Improved readability and maintainability
  - Consistent terminology (added/removed/balance)

**Results:**
- All 12 tests still pass ✅
- Zero lint/format warnings ✅
- Improved test reliability and maintainability
- Better documentation of test intent

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit d54dac3 into main Oct 6, 2025
@malibio
malibio deleted the feature/issue-162-event-listener-leak-tests branch October 6, 2025 15:44
malibio added a commit that referenced this pull request Feb 4, 2026
* Add comprehensive event listener memory leak detection tests

Implemented 12 tests across 4 categories to verify proper event listener cleanup:

Component Lifecycle (4 tests):
- NodeAutocomplete removes keydown listener on unmount
- SlashCommandDropdown removes keydown listener on unmount
- No listener accumulation over multiple mount/unmount cycles
- Cleanup resilient to errors during unmount

Rapid Operations (3 tests):
- 100 rapid mount/unmount cycles without leaking
- Listener count returns to baseline after rapid operations
- Acceptable memory usage during mixed component operations

EventBus Subscriptions (3 tests):
- Unsubscribe actually removes handlers
- reset() clears all handlers
- Wildcard subscriptions cleaned up properly

Verification Tools (2 tests):
- Programmatic leak detection capability
- Accurate handler count measurement

All tests verify that document event listeners and EventBus subscriptions are properly cleaned up to prevent memory leaks during normal and edge-case scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Address all code review findings for event listener tests

Implemented all critical, important, and optional improvements from PR review:

**Critical Fixes:**
- Add handler reference verification (Finding #3)
  - Tests #1 and #2 now verify exact handler reference equality
  - Ensures removeEventListener receives same function reference as addEventListener
  - Prevents common memory leak bug of creating new functions

**Important Improvements:**
- Rename test #4 to match actual behavior (Finding #1)
  - Changed "error during unmount" → "normal unmount lifecycle"
  - Added explanatory comment about Svelte's onDestroy guarantees

- Add explicit cleanup to test #7 (Finding #5)
  - Intentional leak test now properly unmounts component
  - Verifies cleanup worked by checking balance returns to initial state
  - Ensures test isolation and prevents cross-test contamination

**Code Quality Enhancements:**
- Extract helper functions for common spy patterns (Suggestion #4)
  - getKeydownListenerCounts(): Centralizes listener counting logic
  - getKeydownListenerHandlers(): Extracts handler reference tracking
  - measureListenerDelta(): Standard baseline measurement pattern

- Standardize baseline measurement patterns (Finding #2)
  - All rapid operation tests now use consistent slice() pattern
  - Improved readability and maintainability
  - Consistent terminology (added/removed/balance)

**Results:**
- All 12 tests still pass ✅
- Zero lint/format warnings ✅
- Improved test reliability and maintainability
- Better documentation of test intent

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
* Add comprehensive event listener memory leak detection tests

Implemented 12 tests across 4 categories to verify proper event listener cleanup:

Component Lifecycle (4 tests):
- NodeAutocomplete removes keydown listener on unmount
- SlashCommandDropdown removes keydown listener on unmount
- No listener accumulation over multiple mount/unmount cycles
- Cleanup resilient to errors during unmount

Rapid Operations (3 tests):
- 100 rapid mount/unmount cycles without leaking
- Listener count returns to baseline after rapid operations
- Acceptable memory usage during mixed component operations

EventBus Subscriptions (3 tests):
- Unsubscribe actually removes handlers
- reset() clears all handlers
- Wildcard subscriptions cleaned up properly

Verification Tools (2 tests):
- Programmatic leak detection capability
- Accurate handler count measurement

All tests verify that document event listeners and EventBus subscriptions are properly cleaned up to prevent memory leaks during normal and edge-case scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Address all code review findings for event listener tests

Implemented all critical, important, and optional improvements from PR review:

**Critical Fixes:**
- Add handler reference verification (Finding #3)
  - Tests #1 and #2 now verify exact handler reference equality
  - Ensures removeEventListener receives same function reference as addEventListener
  - Prevents common memory leak bug of creating new functions

**Important Improvements:**
- Rename test #4 to match actual behavior (Finding #1)
  - Changed "error during unmount" → "normal unmount lifecycle"
  - Added explanatory comment about Svelte's onDestroy guarantees

- Add explicit cleanup to test #7 (Finding #5)
  - Intentional leak test now properly unmounts component
  - Verifies cleanup worked by checking balance returns to initial state
  - Ensures test isolation and prevents cross-test contamination

**Code Quality Enhancements:**
- Extract helper functions for common spy patterns (Suggestion #4)
  - getKeydownListenerCounts(): Centralizes listener counting logic
  - getKeydownListenerHandlers(): Extracts handler reference tracking
  - measureListenerDelta(): Standard baseline measurement pattern

- Standardize baseline measurement patterns (Finding #2)
  - All rapid operation tests now use consistent slice() pattern
  - Improved readability and maintainability
  - Consistent terminology (added/removed/balance)

**Results:**
- All 12 tests still pass ✅
- Zero lint/format warnings ✅
- Improved test reliability and maintainability
- Better documentation of test intent

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
* Add comprehensive event listener memory leak detection tests

Implemented 12 tests across 4 categories to verify proper event listener cleanup:

Component Lifecycle (4 tests):
- NodeAutocomplete removes keydown listener on unmount
- SlashCommandDropdown removes keydown listener on unmount
- No listener accumulation over multiple mount/unmount cycles
- Cleanup resilient to errors during unmount

Rapid Operations (3 tests):
- 100 rapid mount/unmount cycles without leaking
- Listener count returns to baseline after rapid operations
- Acceptable memory usage during mixed component operations

EventBus Subscriptions (3 tests):
- Unsubscribe actually removes handlers
- reset() clears all handlers
- Wildcard subscriptions cleaned up properly

Verification Tools (2 tests):
- Programmatic leak detection capability
- Accurate handler count measurement

All tests verify that document event listeners and EventBus subscriptions are properly cleaned up to prevent memory leaks during normal and edge-case scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Address all code review findings for event listener tests

Implemented all critical, important, and optional improvements from PR review:

**Critical Fixes:**
- Add handler reference verification (Finding #3)
  - Tests #1 and #2 now verify exact handler reference equality
  - Ensures removeEventListener receives same function reference as addEventListener
  - Prevents common memory leak bug of creating new functions

**Important Improvements:**
- Rename test #4 to match actual behavior (Finding #1)
  - Changed "error during unmount" → "normal unmount lifecycle"
  - Added explanatory comment about Svelte's onDestroy guarantees

- Add explicit cleanup to test #7 (Finding #5)
  - Intentional leak test now properly unmounts component
  - Verifies cleanup worked by checking balance returns to initial state
  - Ensures test isolation and prevents cross-test contamination

**Code Quality Enhancements:**
- Extract helper functions for common spy patterns (Suggestion #4)
  - getKeydownListenerCounts(): Centralizes listener counting logic
  - getKeydownListenerHandlers(): Extracts handler reference tracking
  - measureListenerDelta(): Standard baseline measurement pattern

- Standardize baseline measurement patterns (Finding #2)
  - All rapid operation tests now use consistent slice() pattern
  - Improved readability and maintainability
  - Consistent terminology (added/removed/balance)

**Results:**
- All 12 tests still pass ✅
- Zero lint/format warnings ✅
- Improved test reliability and maintainability
- Better documentation of test intent

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
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.

Add event listener memory leak detection tests

1 participant