Fix randomly failing unit test