diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 98bf21aa0..7a3793461 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -92,7 +92,7 @@ jobs: env: VERBOSE: true TIMEOUT: 30 - LOW_TIMEOUT: 0.07 + LOW_TIMEOUT: 0.14 DRIVER: ${{ matrix.driver }} REDIS_BRANCH: ${{ matrix.redis }} steps: diff --git a/makefile b/makefile index 80fc6062e..307e75c30 100644 --- a/makefile +++ b/makefile @@ -11,6 +11,7 @@ PORT := 6381 SLAVE_PORT := 6382 SLAVE_PID_PATH := ${BUILD_DIR}/redis_slave.pid SLAVE_SOCKET_PATH := ${BUILD_DIR}/redis_slave.sock +HA_GROUP_NAME := master1 SENTINEL_PORTS := 6400 6401 6402 SENTINEL_PID_PATHS := $(addprefix ${TMP}/redis,$(addsuffix .pid,${SENTINEL_PORTS})) CLUSTER_PORTS := 7000 7001 7002 7003 7004 7005 @@ -24,7 +25,7 @@ endef all: start_all test stop_all -start_all: start start_slave start_sentinel start_cluster create_cluster +start_all: start start_slave start_sentinel wait_for_sentinel start_cluster create_cluster stop_all: stop_sentinel stop_slave stop stop_cluster @@ -67,10 +68,10 @@ start_sentinel: ${BINARY} conf=${TMP}/sentinel$$port.conf;\ touch $$conf;\ echo '' > $$conf;\ - echo 'sentinel monitor master1 127.0.0.1 ${PORT} 2' >> $$conf;\ - echo 'sentinel down-after-milliseconds master1 5000' >> $$conf;\ - echo 'sentinel failover-timeout master1 30000' >> $$conf;\ - echo 'sentinel parallel-syncs master1 1' >> $$conf;\ + echo 'sentinel monitor ${HA_GROUP_NAME} 127.0.0.1 ${PORT} 2' >> $$conf;\ + echo 'sentinel down-after-milliseconds ${HA_GROUP_NAME} 5000' >> $$conf;\ + echo 'sentinel failover-timeout ${HA_GROUP_NAME} 30000' >> $$conf;\ + echo 'sentinel parallel-syncs ${HA_GROUP_NAME} 1' >> $$conf;\ ${BINARY} $$conf\ --daemonize yes\ --pidfile ${TMP}/redis$$port.pid\ @@ -78,6 +79,17 @@ start_sentinel: ${BINARY} --sentinel;\ done +wait_for_sentinel: + @for port in ${SENTINEL_PORTS}; do\ + while : ; do\ + if [ $$(${REDIS_CLIENT} -p $${port} SENTINEL SLAVES ${HA_GROUP_NAME} | wc -l) -gt 1 ]; then\ + break;\ + fi;\ + echo 'Waiting for Redis sentinel to be ready...';\ + sleep 1;\ + done;\ + done + stop_cluster: @$(call kill-redis,${CLUSTER_PID_PATHS}) @rm -f appendonly.aof || true diff --git a/test/cluster_commands_on_keys_test.rb b/test/cluster_commands_on_keys_test.rb index 124a28709..011bbfadd 100644 --- a/test/cluster_commands_on_keys_test.rb +++ b/test/cluster_commands_on_keys_test.rb @@ -49,8 +49,7 @@ def test_object assert_equal 1, redis.object('refcount', 'mylist') expected_encoding = version < '3.2.0' ? 'ziplist' : 'quicklist' assert_equal expected_encoding, redis.object('encoding', 'mylist') - expected_instance_type = RUBY_VERSION < '2.4.0' ? Fixnum : Integer - assert_instance_of expected_instance_type, redis.object('idletime', 'mylist') + assert(redis.object('idletime', 'mylist') >= 0) redis.set('foo', 1000) assert_equal 'int', redis.object('encoding', 'foo') diff --git a/test/cluster_commands_on_pub_sub_test.rb b/test/cluster_commands_on_pub_sub_test.rb index 1599dd798..66c166d96 100644 --- a/test/cluster_commands_on_pub_sub_test.rb +++ b/test/cluster_commands_on_pub_sub_test.rb @@ -56,13 +56,13 @@ def test_publish_psubscribe_punsubscribe_pubsub messages = {} wire = Wire.new do - redis.psubscribe('cha*', 'her*') do |on| + redis.psubscribe('guc*', 'her*') do |on| on.psubscribe { |_c, t| sub_cnt = t } on.punsubscribe { |_c, t| sub_cnt = t } on.pmessage do |_ptn, chn, msg| messages[chn] = msg # FIXME: blocking occurs when `unsubscribe` method was called with channel arguments - redis.punsubscribe if messages.size == 3 + redis.punsubscribe if messages.size == 2 end end end @@ -72,30 +72,27 @@ def test_publish_psubscribe_punsubscribe_pubsub publisher = build_another_client assert_equal [], publisher.pubsub(:channels) - assert_equal [], publisher.pubsub(:channels, 'cha*') - assert_equal [], publisher.pubsub(:channels, 'her*') + assert_equal [], publisher.pubsub(:channels, 'bur*') assert_equal [], publisher.pubsub(:channels, 'guc*') + assert_equal [], publisher.pubsub(:channels, 'her*') assert_equal({}, publisher.pubsub(:numsub)) - assert_equal({ 'channel1' => 0, 'channel2' => 0, 'hermes3' => 0, 'gucci4' => 0 }, - publisher.pubsub(:numsub, 'channel1', 'channel2', 'hermes3', 'gucci4')) + assert_equal({ 'burberry1' => 0, 'gucci2' => 0, 'hermes3' => 0 }, publisher.pubsub(:numsub, 'burberry1', 'gucci2', 'hermes3')) assert_equal 2, publisher.pubsub(:numpat) - publisher.publish('chanel1', 'one') - publisher.publish('chanel2', 'two') + publisher.publish('burberry1', 'one') + publisher.publish('gucci2', 'two') publisher.publish('hermes3', 'three') - publisher.publish('gucci4', 'four') wire.join - assert_equal({ 'chanel1' => 'one', 'chanel2' => 'two', 'hermes3' => 'three' }, messages.sort.to_h) + assert_equal({ 'gucci2' => 'two', 'hermes3' => 'three' }, messages.sort.to_h) assert_equal [], publisher.pubsub(:channels) - assert_equal [], publisher.pubsub(:channels, 'cha*') - assert_equal [], publisher.pubsub(:channels, 'her*') + assert_equal [], publisher.pubsub(:channels, 'bur*') assert_equal [], publisher.pubsub(:channels, 'guc*') + assert_equal [], publisher.pubsub(:channels, 'her*') assert_equal({}, publisher.pubsub(:numsub)) - assert_equal({ 'channel1' => 0, 'channel2' => 0, 'hermes3' => 0, 'gucci4' => 0 }, - publisher.pubsub(:numsub, 'channel1', 'channel2', 'hermes3', 'gucci4')) + assert_equal({ 'burberry1' => 0, 'gucci2' => 0, 'hermes3' => 0 }, publisher.pubsub(:numsub, 'burberry1', 'gucci2', 'hermes3')) assert_equal 0, publisher.pubsub(:numpat) end end