YARN-2568. Fixed the potential test failures due to race conditions when RM work-preserving recovery is enabled. Contributed by Jian He.

(cherry picked from commit 6fe5c6b746a40019b9a43676c33efec0f971c4b9)