Fix idempotence issues in unit tests