Supersedes !7928 with some test tweaks:
* Test that shutdown waits for any queued handler, * Use message loop only when necessary (DQTYPE_THREAD_CURRENT), * Remove some non-deterministic refcount checks after shutdown, as dispatch thread might still hold some until it exits.