refactoring: common logic to wait for test completeness