Fix flaky unit tests