@@ -64,6 +64,69 @@ public function testSendOneDead()
64
64
$ t ->send (new RawMessage ('' ));
65
65
}
66
66
67
+ public function testSendOneDeadAndRecoveryNotWithinRetryPeriod ()
68
+ {
69
+ $ t1 = $ this ->createMock (TransportInterface::class);
70
+ $ t1 ->expects ($ this ->at (0 ))->method ('send ' )->will ($ this ->throwException (new TransportException ()));
71
+ $ t1 ->expects ($ this ->once ())->method ('send ' );
72
+ $ t2 = $ this ->createMock (TransportInterface::class);
73
+ $ t2 ->expects ($ this ->exactly (5 ))->method ('send ' );
74
+ $ t = new FailoverTransport ([$ t1 , $ t2 ], 40 );
75
+ $ t ->send (new RawMessage ('' ));
76
+ sleep (4 );
77
+ $ t ->send (new RawMessage ('' ));
78
+ sleep (4 );
79
+ $ t ->send (new RawMessage ('' ));
80
+ sleep (4 );
81
+ $ t ->send (new RawMessage ('' ));
82
+ sleep (4 );
83
+ $ t ->send (new RawMessage ('' ));
84
+ }
85
+
86
+ public function testSendOneDeadAndRecoveryWithinRetryPeriod ()
87
+ {
88
+ $ t1 = $ this ->createMock (TransportInterface::class);
89
+ $ t1 ->expects ($ this ->at (0 ))->method ('send ' )->will ($ this ->throwException (new TransportException ()));
90
+ $ t1 ->expects ($ this ->at (1 ))->method ('send ' );
91
+ $ t1 ->expects ($ this ->exactly (3 ))->method ('send ' );
92
+ $ t2 = $ this ->createMock (TransportInterface::class);
93
+ $ t2 ->expects ($ this ->at (0 ))->method ('send ' );
94
+ $ t2 ->expects ($ this ->at (1 ))->method ('send ' );
95
+ $ t2 ->expects ($ this ->at (2 ))->method ('send ' );
96
+ $ t2 ->expects ($ this ->at (3 ))->method ('send ' )->will ($ this ->throwException (new TransportException ()));
97
+ $ t2 ->expects ($ this ->exactly (4 ))->method ('send ' );
98
+ $ t = new FailoverTransport ([$ t1 , $ t2 ], 6 );
99
+ $ t ->send (new RawMessage ('' )); // t1>fail - t2>sent
100
+ sleep (4 );
101
+ $ t ->send (new RawMessage ('' )); // t2>sent
102
+ sleep (4 );
103
+ $ t ->send (new RawMessage ('' )); // t2>sent
104
+ sleep (4 );
105
+ $ t ->send (new RawMessage ('' )); // t2>fail - t1>sent
106
+ sleep (4 );
107
+ $ t ->send (new RawMessage ('' )); // t1>sent
108
+ }
109
+
110
+ public function testSendAllDeadWithinRetryPeriod ()
111
+ {
112
+ $ t1 = $ this ->createMock (TransportInterface::class);
113
+ $ t1 ->expects ($ this ->at (0 ))->method ('send ' )->will ($ this ->throwException (new TransportException ()));
114
+ $ t1 ->expects ($ this ->once ())->method ('send ' );
115
+ $ t2 = $ this ->createMock (TransportInterface::class);
116
+ $ t2 ->expects ($ this ->at (0 ))->method ('send ' );
117
+ $ t2 ->expects ($ this ->at (1 ))->method ('send ' );
118
+ $ t2 ->expects ($ this ->at (2 ))->method ('send ' )->will ($ this ->throwException (new TransportException ()));
119
+ $ t2 ->expects ($ this ->exactly (3 ))->method ('send ' );
120
+ $ t = new FailoverTransport ([$ t1 , $ t2 ], 40 );
121
+ $ t ->send (new RawMessage ('' ));
122
+ sleep (4 );
123
+ $ t ->send (new RawMessage ('' ));
124
+ sleep (4 );
125
+ $ this ->expectException (TransportException::class);
126
+ $ this ->expectExceptionMessage ('All transports failed. ' );
127
+ $ t ->send (new RawMessage ('' ));
128
+ }
129
+
67
130
public function testSendOneDeadButRecover ()
68
131
{
69
132
$ t1 = $ this ->createMock (TransportInterface::class);
0 commit comments