@@ -739,21 +739,45 @@ def test_circuit_breakers
739
739
end
740
740
741
741
def test_only_reshards_own_errors
742
- @client . call_v ( %w[ SADD testkey testvalue1 ] )
743
- @client . call_v ( %w[ SADD testkey testvalue2 ] )
744
742
slot = ::RedisClient ::Cluster ::KeySlotConverter . convert ( 'testkey' )
745
743
router = @client . instance_variable_get ( :@router )
746
744
correct_primary_key = router . find_node_key_by_key ( 'testkey' , primary : true )
747
745
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
+
748
765
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' )
751
769
end
752
770
end
753
771
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
757
781
end
758
782
759
783
def test_pinning_single_key
@@ -832,12 +856,12 @@ def hiredis_used?
832
856
class PrimaryOnly < TestingWrapper
833
857
include Mixin
834
858
835
- def new_test_client ( capture_buffer : @captured_commands , **opts )
859
+ def new_test_client ( custom : { captured_commands : @captured_commands } , middlewares : [ CommandCaptureMiddleware ] , **opts )
836
860
config = ::RedisClient ::ClusterConfig . new (
837
861
nodes : TEST_NODE_URIS ,
838
862
fixed_hostname : TEST_FIXED_HOSTNAME ,
839
- middlewares : [ CommandCaptureMiddleware ] ,
840
- custom : { captured_commands : capture_buffer } ,
863
+ middlewares : middlewares ,
864
+ custom : custom ,
841
865
**TEST_GENERIC_OPTIONS ,
842
866
**opts
843
867
)
@@ -848,14 +872,14 @@ def new_test_client(capture_buffer: @captured_commands, **opts)
848
872
class ScaleReadRandom < TestingWrapper
849
873
include Mixin
850
874
851
- def new_test_client ( capture_buffer : @captured_commands , **opts )
875
+ def new_test_client ( custom : { captured_commands : @captured_commands } , middlewares : [ CommandCaptureMiddleware ] , **opts )
852
876
config = ::RedisClient ::ClusterConfig . new (
853
877
nodes : TEST_NODE_URIS ,
854
878
replica : true ,
855
879
replica_affinity : :random ,
856
880
fixed_hostname : TEST_FIXED_HOSTNAME ,
857
- middlewares : [ CommandCaptureMiddleware ] ,
858
- custom : { captured_commands : capture_buffer } ,
881
+ middlewares : middlewares ,
882
+ custom : custom ,
859
883
**TEST_GENERIC_OPTIONS ,
860
884
**opts
861
885
)
@@ -866,14 +890,14 @@ def new_test_client(capture_buffer: @captured_commands, **opts)
866
890
class ScaleReadRandomWithPrimary < TestingWrapper
867
891
include Mixin
868
892
869
- def new_test_client ( capture_buffer : @captured_commands , **opts )
893
+ def new_test_client ( custom : { captured_commands : @captured_commands } , middlewares : [ CommandCaptureMiddleware ] , **opts )
870
894
config = ::RedisClient ::ClusterConfig . new (
871
895
nodes : TEST_NODE_URIS ,
872
896
replica : true ,
873
897
replica_affinity : :random_with_primary ,
874
898
fixed_hostname : TEST_FIXED_HOSTNAME ,
875
- middlewares : [ CommandCaptureMiddleware ] ,
876
- custom : { captured_commands : capture_buffer } ,
899
+ middlewares : middlewares ,
900
+ custom : custom ,
877
901
**TEST_GENERIC_OPTIONS ,
878
902
**opts
879
903
)
@@ -884,14 +908,14 @@ def new_test_client(capture_buffer: @captured_commands, **opts)
884
908
class ScaleReadLatency < TestingWrapper
885
909
include Mixin
886
910
887
- def new_test_client ( capture_buffer : @captured_commands , **opts )
911
+ def new_test_client ( custom : { captured_commands : @captured_commands } , middlewares : [ CommandCaptureMiddleware ] , **opts )
888
912
config = ::RedisClient ::ClusterConfig . new (
889
913
nodes : TEST_NODE_URIS ,
890
914
replica : true ,
891
915
replica_affinity : :latency ,
892
916
fixed_hostname : TEST_FIXED_HOSTNAME ,
893
- middlewares : [ CommandCaptureMiddleware ] ,
894
- custom : { captured_commands : capture_buffer } ,
917
+ middlewares : middlewares ,
918
+ custom : custom ,
895
919
**TEST_GENERIC_OPTIONS ,
896
920
**opts
897
921
)
@@ -902,12 +926,12 @@ def new_test_client(capture_buffer: @captured_commands, **opts)
902
926
class Pooled < TestingWrapper
903
927
include Mixin
904
928
905
- def new_test_client ( capture_buffer : @captured_commands , **opts )
929
+ def new_test_client ( custom : { captured_commands : @captured_commands } , middlewares : [ CommandCaptureMiddleware ] , **opts )
906
930
config = ::RedisClient ::ClusterConfig . new (
907
931
nodes : TEST_NODE_URIS ,
908
932
fixed_hostname : TEST_FIXED_HOSTNAME ,
909
- middlewares : [ CommandCaptureMiddleware ] ,
910
- custom : { captured_commands : capture_buffer } ,
933
+ middlewares : middlewares ,
934
+ custom : custom ,
911
935
**TEST_GENERIC_OPTIONS ,
912
936
**opts
913
937
)
0 commit comments