Made wait condition in test more reliable.