Move the retrial loop to receive_messages so all the tests can benefit
from it.