Fixed some fragile waiting conditions in tests.