(#2555) - fix 'change' event for db.sync()

This ought to fix it. I also added some tests to ensure we're not leaking any listeners. Apparently calling `removeAllListeners` in `cleanup` is unnecessary, because that gets taken care of in `completeReplication` anyway.
It's not safe to remove all the listeners for both `push` and `pull` when only one of them has told us to remove something.