Skip to content

Add event handler dispatch and threading tests#33

Merged
brunoborges merged 2 commits intomainfrom
test/event-handler-dispatch-and-threading
Feb 6, 2026
Merged

Add event handler dispatch and threading tests#33
brunoborges merged 2 commits intomainfrom
test/event-handler-dispatch-and-threading

Conversation

@brunoborges
Copy link
Member

@brunoborges brunoborges commented Feb 6, 2026

Summary

Adds comprehensive tests for the event handler dispatch mechanism, covering duplicate handler registration, unsubscription behavior, and threading guarantees.

JUnit Tests (SessionEventHandlingTest)

7 new tests added:

  • testDuplicateTypedHandlersBothReceiveEvent — two handlers for the same event type both fire
  • testDuplicateGenericHandlersBothFire — two generic handlers both fire
  • testUnsubscribeOneKeepsOther — unsubscribing one same-type handler leaves the other active
  • testAllHandlersInvoked — 3 handlers all called (containsAll since ConcurrentHashMap order is not guaranteed)
  • testHandlersRunOnDispatchThread — handler executes on the thread that calls dispatchEvent()
  • testHandlersRunOffMainThread — handler does NOT run on the test/main thread when dispatched from background
  • testConcurrentDispatchFromMultipleThreads — 100 events from 10 concurrent threads, all delivered without loss

All 16 JUnit tests pass (9 existing + 7 new).

- Add 7 JUnit tests to SessionEventHandlingTest: duplicate typed/generic
  handlers, unsubscribe-one-keeps-other, all-handlers-invoked,
  handlers-run-on-dispatch-thread, handlers-run-off-main-thread,
  and concurrent dispatch from multiple threads
- Add JBang standalone test (jbang-test-duplicate-handlers.java) with
  the same coverage for quick out-of-build verification
@brunoborges brunoborges merged commit 4f80c5e into main Feb 6, 2026
2 checks passed
@brunoborges brunoborges deleted the test/event-handler-dispatch-and-threading branch February 16, 2026 15:43
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.

1 participant