private TransportMessage SendAndReceiveCore(Action doSend) { // Definitely not thread safe; none of the integration tests that use // a single SqsTestContext instance can run in parallel. TransportMessage lastReceivedMessage = null; Exception lastThrownException = null; var retryCount = 0; using (ReceivedMessages.Subscribe(m => lastReceivedMessage = m)) using (ExceptionsThrownByReceiver.Subscribe(e => lastThrownException = e)) { doSend(); while (lastReceivedMessage == null && lastThrownException == null && retryCount < 100) { retryCount++; Thread.Sleep(50); } } if (retryCount >= 100) { throw new TimeoutException("Receiving a message timed out."); } if (lastThrownException == null) { return(lastReceivedMessage); } else { throw lastThrownException; } }