Skip to content

Commit

Permalink
Merge pull request #1211 from supercaracal/remove-flaky-and-redundant…
Browse files Browse the repository at this point in the history
…-cases-for-pubsub-in-cluster-mode

Remove flaky and redundant test cases for Pub/Sub in cluster mode
  • Loading branch information
byroot authored Aug 20, 2023
2 parents c92e403 + 92dc3fd commit a9b8c23
Showing 1 changed file with 12 additions and 39 deletions.
51 changes: 12 additions & 39 deletions cluster/test/commands_on_pub_sub_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ def test_publish_subscribe_unsubscribe_pubsub

thread = Thread.new do
redis.subscribe('channel1', 'channel2') do |on|
on.subscribe { |_c, t| sub_cnt = t }
on.unsubscribe { |_c, t| sub_cnt = t }
on.subscribe { sub_cnt += 1 }
on.message do |c, msg|
messages[c] = msg
# FIXME: blocking occurs when `unsubscribe` method was called with channel arguments
redis.unsubscribe if messages.size == 2
end
end
Expand All @@ -27,28 +25,19 @@ def test_publish_subscribe_unsubscribe_pubsub

publisher = build_another_client

assert_equal %w[channel1 channel2], publisher.pubsub(:channels)
assert_equal %w[channel1 channel2], publisher.pubsub(:channels, 'cha*')
assert_equal [], publisher.pubsub(:channels, 'chachacha*')
assert_equal({}, publisher.pubsub(:numsub))
assert_equal %w[channel1 channel2], publisher.pubsub(:channels, 'channel*')
assert_equal({ 'channel1' => 1, 'channel2' => 1, 'channel3' => 0 },
publisher.pubsub(:numsub, 'channel1', 'channel2', 'channel3'))
assert_equal 0, publisher.pubsub(:numpat)

publisher.publish('channel1', 'one')
publisher.publish('channel2', 'two')
publisher.publish('channel3', 'three')

thread.join

assert_equal({ 'channel1' => 'one', 'channel2' => 'two' }, messages.sort.to_h)

assert_equal [], publisher.pubsub(:channels)
assert_equal [], publisher.pubsub(:channels, 'cha*')
assert_equal [], publisher.pubsub(:channels, 'chachacha*')
assert_equal({}, publisher.pubsub(:numsub))
assert_equal({ 'channel1' => 0, 'channel2' => 0, 'channel3' => 0 },
publisher.pubsub(:numsub, 'channel1', 'channel2', 'channel3'))
assert_equal 0, publisher.pubsub(:numpat)
assert_equal(2, messages.size)
assert_equal('one', messages['channel1'])
assert_equal('two', messages['channel2'])
end

def test_publish_psubscribe_punsubscribe_pubsub
Expand All @@ -57,11 +46,9 @@ def test_publish_psubscribe_punsubscribe_pubsub

thread = Thread.new do
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
on.psubscribe { sub_cnt += 1 }
on.pmessage do |_ptn, c, msg|
messages[c] = msg
redis.punsubscribe if messages.size == 2
end
end
Expand All @@ -71,13 +58,6 @@ def test_publish_psubscribe_punsubscribe_pubsub

publisher = build_another_client

assert_equal [], publisher.pubsub(:channels)
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({ 'burberry1' => 0, 'gucci2' => 0, 'hermes3' => 0 },
publisher.pubsub(:numsub, 'burberry1', 'gucci2', 'hermes3'))
assert_equal 2, publisher.pubsub(:numpat)

publisher.publish('burberry1', 'one')
Expand All @@ -86,15 +66,8 @@ def test_publish_psubscribe_punsubscribe_pubsub

thread.join

assert_equal({ 'gucci2' => 'two', 'hermes3' => 'three' }, messages.sort.to_h)

assert_equal [], publisher.pubsub(:channels)
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({ 'burberry1' => 0, 'gucci2' => 0, 'hermes3' => 0 },
publisher.pubsub(:numsub, 'burberry1', 'gucci2', 'hermes3'))
assert_equal 0, publisher.pubsub(:numpat)
assert_equal(2, messages.size)
assert_equal('two', messages['gucci2'])
assert_equal('three', messages['hermes3'])
end
end

0 comments on commit a9b8c23

Please sign in to comment.