@@ -41,16 +41,16 @@ public function testToString()
41
41
public function testSendAlternate ()
42
42
{
43
43
$ t1 = $ this ->createMock (TransportInterface::class);
44
- $ t1 ->expects ($ this ->exactly ( 2 ))->method ('send ' );
44
+ $ t1 ->expects ($ this ->atLeast ( 1 ))->method ('send ' );
45
45
$ t2 = $ this ->createMock (TransportInterface::class);
46
- $ t2 ->expects ($ this ->once ( ))->method ('send ' );
46
+ $ t2 ->expects ($ this ->atLeast ( 1 ))->method ('send ' );
47
47
$ t = new RoundRobinTransport ([$ t1 , $ t2 ]);
48
48
$ t ->send (new RawMessage ('' ));
49
- $ this ->assertTransports ($ t , 1 , []);
49
+ $ cursor = $ this ->assertTransports ($ t , - 1 , []);
50
50
$ t ->send (new RawMessage ('' ));
51
- $ this ->assertTransports ($ t , 0 , []);
51
+ $ cursor = $ this ->assertTransports ($ t , 0 === $ cursor ? 1 : 0 , []);
52
52
$ t ->send (new RawMessage ('' ));
53
- $ this ->assertTransports ($ t , 1 , []);
53
+ $ this ->assertTransports ($ t , 0 === $ cursor ? 1 : 0 , []);
54
54
}
55
55
56
56
public function testSendAllDead ()
@@ -73,6 +73,9 @@ public function testSendOneDead()
73
73
$ t2 = $ this ->createMock (TransportInterface::class);
74
74
$ t2 ->expects ($ this ->exactly (3 ))->method ('send ' );
75
75
$ t = new RoundRobinTransport ([$ t1 , $ t2 ]);
76
+ $ p = new \ReflectionProperty ($ t , 'cursor ' );
77
+ $ p ->setAccessible (true );
78
+ $ p ->setValue ($ t , 0 );
76
79
$ t ->send (new RawMessage ('' ));
77
80
$ this ->assertTransports ($ t , 0 , [$ t1 ]);
78
81
$ t ->send (new RawMessage ('' ));
@@ -88,6 +91,9 @@ public function testSendOneDeadAndRecoveryNotWithinRetryPeriod()
88
91
$ t2 = $ this ->createMock (TransportInterface::class);
89
92
$ t2 ->expects ($ this ->once ())->method ('send ' )->will ($ this ->throwException (new TransportException ()));
90
93
$ t = new RoundRobinTransport ([$ t1 , $ t2 ], 60 );
94
+ $ p = new \ReflectionProperty ($ t , 'cursor ' );
95
+ $ p ->setAccessible (true );
96
+ $ p ->setValue ($ t , 0 );
91
97
$ t ->send (new RawMessage ('' ));
92
98
$ this ->assertTransports ($ t , 1 , []);
93
99
$ t ->send (new RawMessage ('' ));
@@ -106,6 +112,9 @@ public function testSendOneDeadAndRecoveryWithinRetryPeriod()
106
112
$ t2 ->expects ($ this ->at (0 ))->method ('send ' )->will ($ this ->throwException (new TransportException ()));
107
113
$ t2 ->expects ($ this ->at (1 ))->method ('send ' );
108
114
$ t = new RoundRobinTransport ([$ t1 , $ t2 ], 3 );
115
+ $ p = new \ReflectionProperty ($ t , 'cursor ' );
116
+ $ p ->setAccessible (true );
117
+ $ p ->setValue ($ t , 0 );
109
118
$ t ->send (new RawMessage ('' ));
110
119
$ this ->assertTransports ($ t , 1 , []);
111
120
$ t ->send (new RawMessage ('' ));
@@ -121,10 +130,15 @@ private function assertTransports(RoundRobinTransport $transport, int $cursor, a
121
130
{
122
131
$ p = new \ReflectionProperty ($ transport , 'cursor ' );
123
132
$ p ->setAccessible (true );
124
- $ this ->assertSame ($ cursor , $ p ->getValue ($ transport ));
133
+ if (-1 !== $ cursor ) {
134
+ $ this ->assertSame ($ cursor , $ p ->getValue ($ transport ));
135
+ }
136
+ $ cursor = $ p ->getValue ($ transport );
125
137
126
138
$ p = new \ReflectionProperty ($ transport , 'deadTransports ' );
127
139
$ p ->setAccessible (true );
128
140
$ this ->assertSame ($ deadTransports , iterator_to_array ($ p ->getValue ($ transport )));
141
+
142
+ return $ cursor ;
129
143
}
130
144
}
0 commit comments