delay the Stream.end call to the next loop, add test