The proper way would be to capture the jobstatus from the undo_import and then check the status a couple times instead of sleeping. It would also provide a good example of using async jobs in the API :) While the sleep does solve the problem, I really hate it when we do this and I know we do it a few times in unit tests for very similar reasons.