Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several unstable test cases #930

Merged
merged 5 commits into from Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Expand Up @@ -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:
Expand Down
22 changes: 17 additions & 5 deletions makefile
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -67,17 +68,28 @@ 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\
--port $$port\
--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
Expand Down
3 changes: 1 addition & 2 deletions test/cluster_commands_on_keys_test.rb
Expand Up @@ -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')
Expand Down
25 changes: 11 additions & 14 deletions test/cluster_commands_on_pub_sub_test.rb
Expand Up @@ -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
Expand All @@ -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