[misc] Make test less fragile

(cherry picked from commit 6d458a20d7815754fc3ce2475e158822ebeca341)