Move memory limit detection to a subscriber
Add functional tests