Add hearbeats logging.
Add tests.
Fix setTimeout in tests.