Exemplo n.º 1
0
        public void When_retry_limits_force_a_message_onto_the_dlq()
        {
            //NOTE: This test is **slow** because it needs to ensure infrastructure and then wait whilst we requeue a message a number of times,
            //then propagate to the DLQ

            //start a message pump, let it create infrastructure
            var task = Task.Factory.StartNew(() => _messagePump.Run(), TaskCreationOptions.LongRunning);

            Task.Delay(20000).Wait();

            //put something on an SNS topic, which will be delivered to our SQS queue
            _sender.Send(_message);

            //Let the message be handled and deferred until it reaches the DLQ
            Task.Delay(20000).Wait();

            //send a quit message to the pump to terminate it
            var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody(""));

            _channel.Enqueue(quitMessage);

            //wait for the pump to stop once it gets a quit message
            Task.WaitAll(new[] { task });

            Task.Delay(5000).Wait();

            //inspect the dlq
            var dlqMessage = _deadLetterConsumer.Receive(10000).First();

            //assert this is our message
            dlqMessage.Body.Value.Should().Be(_message.Body.Value);

            _deadLetterConsumer.Acknowledge(dlqMessage);
        }