From 5c4456842abef0a1a0154a02a3e75d1151ddee28 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 12 Aug 2022 18:55:22 +0200 Subject: [PATCH] Remove some synchrony driver support code --- test/cluster/commands_on_pub_sub_test.rb | 12 +++--- test/distributed/publish_subscribe_test.rb | 10 ++--- test/helper.rb | 1 - test/lint/streams.rb | 6 +-- test/redis/publish_subscribe_test.rb | 40 +++++++++---------- .../remote_server_control_commands_test.rb | 6 +-- test/support/connection/hiredis.rb | 3 -- test/support/connection/ruby.rb | 3 -- test/support/wire/synchrony.rb | 26 ------------ test/support/wire/thread.rb | 7 ---- 10 files changed, 37 insertions(+), 77 deletions(-) delete mode 100644 test/support/connection/hiredis.rb delete mode 100644 test/support/connection/ruby.rb delete mode 100644 test/support/wire/synchrony.rb delete mode 100644 test/support/wire/thread.rb diff --git a/test/cluster/commands_on_pub_sub_test.rb b/test/cluster/commands_on_pub_sub_test.rb index 8f4c2ca53..4782ef2b7 100644 --- a/test/cluster/commands_on_pub_sub_test.rb +++ b/test/cluster/commands_on_pub_sub_test.rb @@ -11,7 +11,7 @@ def test_publish_subscribe_unsubscribe_pubsub sub_cnt = 0 messages = {} - wire = Wire.new do + thread = Thread.new do redis.subscribe('channel1', 'channel2') do |on| on.subscribe { |_c, t| sub_cnt = t } on.unsubscribe { |_c, t| sub_cnt = t } @@ -23,7 +23,7 @@ def test_publish_subscribe_unsubscribe_pubsub end end - Wire.pass until sub_cnt == 2 + Thread.pass until sub_cnt == 2 publisher = build_another_client @@ -38,7 +38,7 @@ def test_publish_subscribe_unsubscribe_pubsub publisher.publish('channel1', 'one') publisher.publish('channel2', 'two') - wire.join + thread.join assert_equal({ 'channel1' => 'one', 'channel2' => 'two' }, messages.sort.to_h) @@ -55,7 +55,7 @@ def test_publish_psubscribe_punsubscribe_pubsub sub_cnt = 0 messages = {} - wire = Wire.new do + thread = Thread.new do redis.psubscribe('guc*', 'her*') do |on| on.psubscribe { |_c, t| sub_cnt = t } on.punsubscribe { |_c, t| sub_cnt = t } @@ -67,7 +67,7 @@ def test_publish_psubscribe_punsubscribe_pubsub end end - Wire.pass until sub_cnt == 2 + Thread.pass until sub_cnt == 2 publisher = build_another_client @@ -83,7 +83,7 @@ def test_publish_psubscribe_punsubscribe_pubsub publisher.publish('gucci2', 'two') publisher.publish('hermes3', 'three') - wire.join + thread.join assert_equal({ 'gucci2' => 'two', 'hermes3' => 'three' }, messages.sort.to_h) diff --git a/test/distributed/publish_subscribe_test.rb b/test/distributed/publish_subscribe_test.rb index 93d1d2b7d..bdd5313ee 100644 --- a/test/distributed/publish_subscribe_test.rb +++ b/test/distributed/publish_subscribe_test.rb @@ -19,7 +19,7 @@ def test_subscribe_and_unsubscribe_with_tags @subscribed = false @unsubscribed = false - wire = Wire.new do + thread = Thread.new do r.subscribe("foo") do |on| on.subscribe do |_channel, total| @subscribed = true @@ -41,11 +41,11 @@ def test_subscribe_and_unsubscribe_with_tags end # Wait until the subscription is active before publishing - Wire.pass until @subscribed + Thread.pass until @subscribed Redis::Distributed.new(NODES).publish("foo", "s1") - wire.join + thread.join assert @subscribed assert_equal 1, @t1 @@ -57,7 +57,7 @@ def test_subscribe_and_unsubscribe_with_tags def test_subscribe_within_subscribe @channels = [] - wire = Wire.new do + thread = Thread.new do r.subscribe("foo") do |on| on.subscribe do |channel, _total| @channels << channel @@ -68,7 +68,7 @@ def test_subscribe_within_subscribe end end - wire.join + thread.join assert_equal ["foo", "bar"], @channels end diff --git a/test/helper.rb b/test/helper.rb index ecd1f24f4..63a7f0ca6 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -16,7 +16,6 @@ require "redis/connection/#{ENV['DRIVER']}" require_relative "support/redis_mock" -require_relative "support/connection/#{ENV['DRIVER']}" require_relative 'support/cluster/orchestrator' PORT = 6381 diff --git a/test/lint/streams.rb b/test/lint/streams.rb index d7060fbb0..694f08c34 100644 --- a/test/lint/streams.rb +++ b/test/lint/streams.rb @@ -357,13 +357,13 @@ def test_xread_with_block_option def test_xread_does_not_raise_timeout_error_when_the_block_option_is_zero_msec prepared = false actual = nil - wire = Wire.new do + thread = Thread.new do prepared = true actual = redis.xread('s1', 0, block: 0) end - Wire.pass until prepared + Thread.pass until prepared redis.dup.xadd('s1', { f: 'v1' }, id: '0-1') - wire.join + thread.join assert_equal(['v1'], actual.fetch('s1').map { |i| i.last['f'] }) end diff --git a/test/redis/publish_subscribe_test.rb b/test/redis/publish_subscribe_test.rb index ebeda9a1d..a4a4e5864 100644 --- a/test/redis/publish_subscribe_test.rb +++ b/test/redis/publish_subscribe_test.rb @@ -12,7 +12,7 @@ def test_subscribe_and_unsubscribe @subscribed = false @unsubscribed = false - wire = Wire.new do + thread = Thread.new do r.subscribe("foo") do |on| on.subscribe do |_channel, total| @subscribed = true @@ -34,11 +34,11 @@ def test_subscribe_and_unsubscribe end # Wait until the subscription is active before publishing - Wire.pass until @subscribed + Thread.pass until @subscribed Redis.new(OPTIONS).publish("foo", "s1") - wire.join + thread.join assert @subscribed assert_equal 1, @t1 @@ -51,7 +51,7 @@ def test_psubscribe_and_punsubscribe @subscribed = false @unsubscribed = false - wire = Wire.new do + thread = Thread.new do r.psubscribe("f*") do |on| on.psubscribe do |_pattern, total| @subscribed = true @@ -73,11 +73,11 @@ def test_psubscribe_and_punsubscribe end # Wait until the subscription is active before publishing - Wire.pass until @subscribed + Thread.pass until @subscribed Redis.new(OPTIONS).publish("foo", "s1") - wire.join + thread.join assert @subscribed assert_equal 1, @t1 @@ -88,18 +88,18 @@ def test_psubscribe_and_punsubscribe def test_pubsub_with_numpat_subcommand @subscribed = false - wire = Wire.new do + thread = Thread.new do r.psubscribe("f*") do |on| on.psubscribe { |_channel, _total| @subscribed = true } on.pmessage { |_pattern, _channel, _message| r.punsubscribe } end end - Wire.pass until @subscribed + Thread.pass until @subscribed redis = Redis.new(OPTIONS) numpat_result = redis.pubsub(:numpat) redis.publish("foo", "s1") - wire.join + thread.join assert_equal redis.pubsub(:numpat), 0 assert_equal numpat_result, 1 @@ -107,20 +107,20 @@ def test_pubsub_with_numpat_subcommand def test_pubsub_with_channels_and_numsub_subcommnads @subscribed = false - wire = Wire.new do + thread = Thread.new do r.subscribe("foo") do |on| on.subscribe { |_channel, _total| @subscribed = true } on.message { |_channel, _message| r.unsubscribe } end end - Wire.pass until @subscribed + Thread.pass until @subscribed redis = Redis.new(OPTIONS) channels_result = redis.pubsub(:channels) channels_result.delete('__sentinel__:hello') numsub_result = redis.pubsub(:numsub, 'foo', 'boo') redis.publish("foo", "s1") - wire.join + thread.join assert_equal channels_result, ['foo'] assert_equal numsub_result, ['foo', 1, 'boo', 0] @@ -129,7 +129,7 @@ def test_pubsub_with_channels_and_numsub_subcommnads def test_subscribe_connection_usable_after_raise @subscribed = false - wire = Wire.new do + thread = Thread.new do r.subscribe("foo") do |on| on.subscribe do |_channel, _total| @subscribed = true @@ -143,11 +143,11 @@ def test_subscribe_connection_usable_after_raise end # Wait until the subscription is active before publishing - Wire.pass until @subscribed + Thread.pass until @subscribed Redis.new(OPTIONS).publish("foo", "s1") - wire.join + thread.join assert_equal "PONG", r.ping end @@ -155,7 +155,7 @@ def test_subscribe_connection_usable_after_raise def test_psubscribe_connection_usable_after_raise @subscribed = false - wire = Wire.new do + thread = Thread.new do r.psubscribe("f*") do |on| on.psubscribe do |_pattern, _total| @subscribed = true @@ -169,11 +169,11 @@ def test_psubscribe_connection_usable_after_raise end # Wait until the subscription is active before publishing - Wire.pass until @subscribed + Thread.pass until @subscribed Redis.new(OPTIONS).publish("foo", "s1") - wire.join + thread.join assert_equal "PONG", r.ping end @@ -181,7 +181,7 @@ def test_psubscribe_connection_usable_after_raise def test_subscribe_within_subscribe @channels = [] - wire = Wire.new do + thread = Thread.new do r.subscribe("foo") do |on| on.subscribe do |channel, _total| @channels << channel @@ -192,7 +192,7 @@ def test_subscribe_within_subscribe end end - wire.join + thread.join assert_equal ["foo", "bar"], @channels end diff --git a/test/redis/remote_server_control_commands_test.rb b/test/redis/remote_server_control_commands_test.rb index 81b669815..47a8b6a92 100644 --- a/test/redis/remote_server_control_commands_test.rb +++ b/test/redis/remote_server_control_commands_test.rb @@ -36,18 +36,18 @@ def test_info_commandstats def test_monitor_redis log = [] - wire = Wire.new do + thread = Thread.new do Redis.new(OPTIONS).monitor do |line| log << line break if line =~ /set/ end end - Wire.pass while log.empty? # Faster than sleep + Thread.pass while log.empty? # Faster than sleep r.set "foo", "s1" - wire.join + thread.join assert log[-1] =~ /\b15\b.* "set" "foo" "s1"/ end diff --git a/test/support/connection/hiredis.rb b/test/support/connection/hiredis.rb deleted file mode 100644 index 2545fa7ba..000000000 --- a/test/support/connection/hiredis.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -require_relative "../wire/thread" diff --git a/test/support/connection/ruby.rb b/test/support/connection/ruby.rb deleted file mode 100644 index 2545fa7ba..000000000 --- a/test/support/connection/ruby.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -require_relative "../wire/thread" diff --git a/test/support/wire/synchrony.rb b/test/support/wire/synchrony.rb deleted file mode 100644 index b147aae13..000000000 --- a/test/support/wire/synchrony.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class Wire < Fiber - # We cannot run this fiber explicitly because EM schedules it. Resuming the - # current fiber on the next tick to let the reactor do work. - def self.pass - f = Fiber.current - EM.next_tick { f.resume } - Fiber.yield - end - - def self.sleep(sec) - EM::Synchrony.sleep(sec) - end - - def initialize(&blk) - super - - # Schedule run in next tick - EM.next_tick { resume } - end - - def join - self.class.pass while alive? - end -end diff --git a/test/support/wire/thread.rb b/test/support/wire/thread.rb deleted file mode 100644 index d91a8f67e..000000000 --- a/test/support/wire/thread.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class Wire < Thread - def self.sleep(sec) - Kernel.sleep(sec) - end -end