Fix unit tests which failed in rare occurrences.