@@ -739,21 +739,45 @@ def test_circuit_breakers
739739 end
740740
741741 def test_only_reshards_own_errors
742- @client . call_v ( %w[ SADD testkey testvalue1 ] )
743- @client . call_v ( %w[ SADD testkey testvalue2 ] )
744742 slot = ::RedisClient ::Cluster ::KeySlotConverter . convert ( 'testkey' )
745743 router = @client . instance_variable_get ( :@router )
746744 correct_primary_key = router . find_node_key_by_key ( 'testkey' , primary : true )
747745 broken_primary_key = ( router . node_keys - [ correct_primary_key ] ) . first
746+
747+ client1 = new_test_client (
748+ middlewares : [
749+ ::RedisClient ::Cluster ::ErrorIdentification ::Middleware
750+ ]
751+ )
752+
753+ client2 = new_test_client (
754+ middlewares : [
755+ ::RedisClient ::Cluster ::ErrorIdentification ::Middleware ,
756+ RedirectionEmulationMiddleware
757+ ] ,
758+ custom : {
759+ redirect : RedirectionEmulationMiddleware ::Setting . new (
760+ slot : slot , to : broken_primary_key , command : %w[ SET testkey client2 ]
761+ )
762+ }
763+ )
764+
748765 assert_raises ( RedisClient ::CommandError ) do
749- @client . sscan ( 'testkey' , retry_count : 0 ) do
750- raise RedisClient ::CommandError , "MOVED #{ slot } #{ broken_primary_key } "
766+ client1 . call ( 'SET' , 'testkey' , 'client1' ) do |got |
767+ assert_equal ( 'OK' , got )
768+ client2 . call ( 'SET' , 'testkey' , 'client2' )
751769 end
752770 end
753771
754- # The exception should not have causes @client to update its shard mappings, because it didn't
755- # come from a RedisClient instance that @client knows about.
756- assert_equal correct_primary_key , router . find_node_key_by_key ( 'testkey' , primary : true )
772+ # The exception should not have causes client1 to update its shard mappings, because it didn't
773+ # come from a RedisClient instance that client1 knows about.
774+ assert_equal (
775+ correct_primary_key ,
776+ client1 . instance_variable_get ( :@router ) . find_node_key_by_key ( 'testkey' , primary : true )
777+ )
778+
779+ client1 . close
780+ client2 . close
757781 end
758782
759783 def test_pinning_single_key
@@ -832,12 +856,12 @@ def hiredis_used?
832856 class PrimaryOnly < TestingWrapper
833857 include Mixin
834858
835- def new_test_client ( capture_buffer : @captured_commands , **opts )
859+ def new_test_client ( custom : { captured_commands : @captured_commands } , middlewares : [ CommandCaptureMiddleware ] , **opts )
836860 config = ::RedisClient ::ClusterConfig . new (
837861 nodes : TEST_NODE_URIS ,
838862 fixed_hostname : TEST_FIXED_HOSTNAME ,
839- middlewares : [ CommandCaptureMiddleware ] ,
840- custom : { captured_commands : capture_buffer } ,
863+ middlewares : middlewares ,
864+ custom : custom ,
841865 **TEST_GENERIC_OPTIONS ,
842866 **opts
843867 )
@@ -848,14 +872,14 @@ def new_test_client(capture_buffer: @captured_commands, **opts)
848872 class ScaleReadRandom < TestingWrapper
849873 include Mixin
850874
851- def new_test_client ( capture_buffer : @captured_commands , **opts )
875+ def new_test_client ( custom : { captured_commands : @captured_commands } , middlewares : [ CommandCaptureMiddleware ] , **opts )
852876 config = ::RedisClient ::ClusterConfig . new (
853877 nodes : TEST_NODE_URIS ,
854878 replica : true ,
855879 replica_affinity : :random ,
856880 fixed_hostname : TEST_FIXED_HOSTNAME ,
857- middlewares : [ CommandCaptureMiddleware ] ,
858- custom : { captured_commands : capture_buffer } ,
881+ middlewares : middlewares ,
882+ custom : custom ,
859883 **TEST_GENERIC_OPTIONS ,
860884 **opts
861885 )
@@ -866,14 +890,14 @@ def new_test_client(capture_buffer: @captured_commands, **opts)
866890 class ScaleReadRandomWithPrimary < TestingWrapper
867891 include Mixin
868892
869- def new_test_client ( capture_buffer : @captured_commands , **opts )
893+ def new_test_client ( custom : { captured_commands : @captured_commands } , middlewares : [ CommandCaptureMiddleware ] , **opts )
870894 config = ::RedisClient ::ClusterConfig . new (
871895 nodes : TEST_NODE_URIS ,
872896 replica : true ,
873897 replica_affinity : :random_with_primary ,
874898 fixed_hostname : TEST_FIXED_HOSTNAME ,
875- middlewares : [ CommandCaptureMiddleware ] ,
876- custom : { captured_commands : capture_buffer } ,
899+ middlewares : middlewares ,
900+ custom : custom ,
877901 **TEST_GENERIC_OPTIONS ,
878902 **opts
879903 )
@@ -884,14 +908,14 @@ def new_test_client(capture_buffer: @captured_commands, **opts)
884908 class ScaleReadLatency < TestingWrapper
885909 include Mixin
886910
887- def new_test_client ( capture_buffer : @captured_commands , **opts )
911+ def new_test_client ( custom : { captured_commands : @captured_commands } , middlewares : [ CommandCaptureMiddleware ] , **opts )
888912 config = ::RedisClient ::ClusterConfig . new (
889913 nodes : TEST_NODE_URIS ,
890914 replica : true ,
891915 replica_affinity : :latency ,
892916 fixed_hostname : TEST_FIXED_HOSTNAME ,
893- middlewares : [ CommandCaptureMiddleware ] ,
894- custom : { captured_commands : capture_buffer } ,
917+ middlewares : middlewares ,
918+ custom : custom ,
895919 **TEST_GENERIC_OPTIONS ,
896920 **opts
897921 )
@@ -902,12 +926,12 @@ def new_test_client(capture_buffer: @captured_commands, **opts)
902926 class Pooled < TestingWrapper
903927 include Mixin
904928
905- def new_test_client ( capture_buffer : @captured_commands , **opts )
929+ def new_test_client ( custom : { captured_commands : @captured_commands } , middlewares : [ CommandCaptureMiddleware ] , **opts )
906930 config = ::RedisClient ::ClusterConfig . new (
907931 nodes : TEST_NODE_URIS ,
908932 fixed_hostname : TEST_FIXED_HOSTNAME ,
909- middlewares : [ CommandCaptureMiddleware ] ,
910- custom : { captured_commands : capture_buffer } ,
933+ middlewares : middlewares ,
934+ custom : custom ,
911935 **TEST_GENERIC_OPTIONS ,
912936 **opts
913937 )
0 commit comments