Improve test to be more deterministic