Ensure application shuts down gracefully if not killed and add tests
The first commit is cherry-picked from !654 (merged) to prevent libfolks from raising warnings.
The main changes are:
- invoking
quit_calls()
also when the process has not been SIGINT/SIGTERM'ed - respecting object lifecycles so callbacks will not be invoked with invalid data
- test shutting down