|
6 | 6 | use OldSound\RabbitMqBundle\Event\BeforeProcessingMessageEvent; |
7 | 7 | use OldSound\RabbitMqBundle\Event\OnConsumeEvent; |
8 | 8 | use OldSound\RabbitMqBundle\RabbitMq\Consumer; |
| 9 | +use PhpAmqpLib\Exception\AMQPTimeoutException; |
9 | 10 | use PhpAmqpLib\Message\AMQPMessage; |
10 | 11 | use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface; |
11 | 12 |
|
@@ -170,4 +171,35 @@ function () use ($amqpChannel) { |
170 | 171 | $consumer->setEventDispatcher($eventDispatcher); |
171 | 172 | $consumer->consume(1); |
172 | 173 | } |
| 174 | + |
| 175 | + public function testIdleTimeoutExitCode() |
| 176 | + { |
| 177 | + // set up amqp connection |
| 178 | + $amqpConnection = $this->prepareAMQPConnection(); |
| 179 | + // set up amqp channel |
| 180 | + $amqpChannel = $this->prepareAMQPChannel(); |
| 181 | + $amqpChannel->expects($this->atLeastOnce()) |
| 182 | + ->method('getChannelId') |
| 183 | + ->with() |
| 184 | + ->willReturn(true); |
| 185 | + $amqpChannel->expects($this->once()) |
| 186 | + ->method('basic_consume') |
| 187 | + ->withAnyParameters() |
| 188 | + ->willReturn(true); |
| 189 | + |
| 190 | + // set up consumer |
| 191 | + $consumer = $this->getConsumer($amqpConnection, $amqpChannel); |
| 192 | + // disable autosetup fabric so we do not mock more objects |
| 193 | + $consumer->disableAutoSetupFabric(); |
| 194 | + $consumer->setChannel($amqpChannel); |
| 195 | + $consumer->setIdleTimeoutExitCode(2); |
| 196 | + $amqpChannel->callbacks = array('idle_timeout_exit_code'); |
| 197 | + |
| 198 | + $amqpChannel->expects($this->exactly(1)) |
| 199 | + ->method('wait') |
| 200 | + ->with(null, false, $consumer->getIdleTimeout()) |
| 201 | + ->willThrowException(new AMQPTimeoutException()); |
| 202 | + |
| 203 | + $this->assertTrue(2 == $consumer->consume(1)); |
| 204 | + } |
173 | 205 | } |
0 commit comments