(#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.