Fix race condition with stubbing modal dialogs.