Tests: Wait properly for processes to exit