Simplify code with cancellable read on a stream
adding some sleep for test that failed sometimes.