Fix sleep issues in the tests for the API