@@ -302,8 +302,8 @@ public function testConnectWillStartConnectingWithAlternatingIPv6AndIPv4WhenReso
302
302
$ connector ->expects ($ this ->exactly (4 ))->method ('connect ' )->withConsecutive (
303
303
array ('tcp://[::1]:80?hostname=reactphp.org ' ),
304
304
array ('tcp://127.0.0.1:80?hostname=reactphp.org ' ),
305
- array ('tcp://[::2 ]:80?hostname=reactphp.org ' ),
306
- array ('tcp://127.0.0.2 :80?hostname=reactphp.org ' )
305
+ array ('tcp://[::1 ]:80?hostname=reactphp.org ' ),
306
+ array ('tcp://127.0.0.1 :80?hostname=reactphp.org ' )
307
307
)->willReturnOnConsecutiveCalls (
308
308
$ deferred ->promise (),
309
309
$ deferred ->promise (),
@@ -316,8 +316,8 @@ public function testConnectWillStartConnectingWithAlternatingIPv6AndIPv4WhenReso
316
316
array ('reactphp.org ' , Message::TYPE_AAAA ),
317
317
array ('reactphp.org ' , Message::TYPE_A )
318
318
)->willReturnOnConsecutiveCalls (
319
- \React \Promise \resolve (array ('::1 ' , '::2 ' )),
320
- \React \Promise \resolve (array ('127.0.0.1 ' , '127.0.0.2 ' ))
319
+ \React \Promise \resolve (array ('::1 ' , '::1 ' )),
320
+ \React \Promise \resolve (array ('127.0.0.1 ' , '127.0.0.1 ' ))
321
321
);
322
322
323
323
$ uri = 'tcp://reactphp.org:80 ' ;
@@ -341,7 +341,7 @@ public function testConnectWillStartConnectingWithAttemptTimerWhenOnlyIpv6Resolv
341
341
$ connector = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
342
342
$ connector ->expects ($ this ->exactly (2 ))->method ('connect ' )->withConsecutive (
343
343
array ('tcp://[::1]:80?hostname=reactphp.org ' ),
344
- array ('tcp://[::2 ]:80?hostname=reactphp.org ' )
344
+ array ('tcp://[::1 ]:80?hostname=reactphp.org ' )
345
345
)->willReturnOnConsecutiveCalls (
346
346
\React \Promise \reject (new \RuntimeException ()),
347
347
new Promise (function () { })
@@ -352,7 +352,7 @@ public function testConnectWillStartConnectingWithAttemptTimerWhenOnlyIpv6Resolv
352
352
array ('reactphp.org ' , Message::TYPE_AAAA ),
353
353
array ('reactphp.org ' , Message::TYPE_A )
354
354
)->willReturnOnConsecutiveCalls (
355
- \React \Promise \resolve (array ('::1 ' , '::2 ' )),
355
+ \React \Promise \resolve (array ('::1 ' , '::1 ' )),
356
356
\React \Promise \reject (new \RuntimeException ())
357
357
);
358
358
@@ -799,4 +799,56 @@ public function testCleanUpCancelsAllPendingConnectionAttemptsWithoutStartingNew
799
799
800
800
$ builder ->cleanUp ();
801
801
}
802
+
803
+ public function testMixIpsIntoConnectQueueSometimesAssignsInOriginalOrder ()
804
+ {
805
+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
806
+ $ connector = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
807
+ $ resolver = $ this ->getMockBuilder ('React\Dns\Resolver\ResolverInterface ' )->getMock ();
808
+
809
+ $ uri = 'tcp://reactphp.org:80/path?test=yes#start ' ;
810
+ $ host = 'reactphp.org ' ;
811
+ $ parts = parse_url ($ uri );
812
+
813
+ for ($ i = 0 ; $ i < 100 ; ++$ i ) {
814
+ $ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
815
+ $ builder ->mixIpsIntoConnectQueue (array ('::1 ' , '::2 ' ));
816
+
817
+ $ ref = new \ReflectionProperty ($ builder , 'connectQueue ' );
818
+ $ ref ->setAccessible (true );
819
+ $ value = $ ref ->getValue ($ builder );
820
+
821
+ if ($ value === array ('::1 ' , '::2 ' )) {
822
+ break ;
823
+ }
824
+ }
825
+
826
+ $ this ->assertEquals (array ('::1 ' , '::2 ' ), $ value );
827
+ }
828
+
829
+ public function testMixIpsIntoConnectQueueSometimesAssignsInReverseOrder ()
830
+ {
831
+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
832
+ $ connector = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
833
+ $ resolver = $ this ->getMockBuilder ('React\Dns\Resolver\ResolverInterface ' )->getMock ();
834
+
835
+ $ uri = 'tcp://reactphp.org:80/path?test=yes#start ' ;
836
+ $ host = 'reactphp.org ' ;
837
+ $ parts = parse_url ($ uri );
838
+
839
+ for ($ i = 0 ; $ i < 100 ; ++$ i ) {
840
+ $ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
841
+ $ builder ->mixIpsIntoConnectQueue (array ('::1 ' , '::2 ' ));
842
+
843
+ $ ref = new \ReflectionProperty ($ builder , 'connectQueue ' );
844
+ $ ref ->setAccessible (true );
845
+ $ value = $ ref ->getValue ($ builder );
846
+
847
+ if ($ value === array ('::2 ' , '::1 ' )) {
848
+ break ;
849
+ }
850
+ }
851
+
852
+ $ this ->assertEquals (array ('::2 ' , '::1 ' ), $ value );
853
+ }
802
854
}
0 commit comments