@@ -813,6 +813,73 @@ public function testItCanBeConstructedWithTLSOptionsAndNonTLSDsn()
813
813
);
814
814
}
815
815
816
+ public function testItCanRetryPublishWhenAMQPConnectionExceptionIsThrown ()
817
+ {
818
+ $ factory = new TestAmqpFactory (
819
+ $ amqpConnection = $ this ->createMock (\AMQPConnection::class),
820
+ $ amqpChannel = $ this ->createMock (\AMQPChannel::class),
821
+ $ amqpQueue = $ this ->createMock (\AMQPQueue::class),
822
+ $ amqpExchange = $ this ->createMock (\AMQPExchange::class)
823
+ );
824
+
825
+ $ amqpExchange ->expects ($ this ->exactly (2 ))
826
+ ->method ('publish ' )
827
+ ->willReturnOnConsecutiveCalls (
828
+ $ this ->throwException (new \AMQPConnectionException ('a socket error occurred ' )),
829
+ null
830
+ );
831
+
832
+ $ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
833
+ $ connection ->publish ('body ' );
834
+ }
835
+
836
+ public function testItCanRetryPublishWithDelayWhenAMQPConnectionExceptionIsThrown ()
837
+ {
838
+ $ factory = new TestAmqpFactory (
839
+ $ amqpConnection = $ this ->createMock (\AMQPConnection::class),
840
+ $ amqpChannel = $ this ->createMock (\AMQPChannel::class),
841
+ $ amqpQueue = $ this ->createMock (\AMQPQueue::class),
842
+ $ amqpExchange = $ this ->createMock (\AMQPExchange::class)
843
+ );
844
+
845
+ $ amqpExchange ->expects ($ this ->exactly (2 ))
846
+ ->method ('publish ' )
847
+ ->willReturnOnConsecutiveCalls (
848
+ $ this ->throwException (new \AMQPConnectionException ('a socket error occurred ' )),
849
+ null
850
+ );
851
+
852
+ $ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
853
+ $ connection ->publish ('body ' , [], 5000 );
854
+ }
855
+
856
+ public function testItWillRetryMaxThreeTimesWhenAMQPConnectionExceptionIsThrown ()
857
+ {
858
+ $ factory = new TestAmqpFactory (
859
+ $ amqpConnection = $ this ->createMock (\AMQPConnection::class),
860
+ $ amqpChannel = $ this ->createMock (\AMQPChannel::class),
861
+ $ amqpQueue = $ this ->createMock (\AMQPQueue::class),
862
+ $ amqpExchange = $ this ->createMock (\AMQPExchange::class)
863
+ );
864
+
865
+ $ exception = new \AMQPConnectionException ('a socket error occurred ' );
866
+
867
+ $ amqpExchange ->expects ($ this ->exactly (4 ))
868
+ ->method ('publish ' )
869
+ ->willReturnOnConsecutiveCalls (
870
+ $ this ->throwException ($ exception ),
871
+ $ this ->throwException ($ exception ),
872
+ $ this ->throwException ($ exception ),
873
+ $ this ->throwException ($ exception ),
874
+ );
875
+
876
+ self ::expectException (get_class ($ exception ));
877
+ self ::expectExceptionMessage ($ exception ->getMessage ());
878
+
879
+ $ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
880
+ $ connection ->publish ('body ' );
881
+ }
882
+
816
883
private function createDelayOrRetryConnection (\AMQPExchange $ delayExchange , string $ deadLetterExchangeName , string $ delayQueueName ): Connection
817
884
{
818
885
$ amqpConnection = $ this ->createMock (\AMQPConnection::class);
0 commit comments