Refactoring of ws tests

This PR is mostly about replacing some sleep methods with wait ones.