Skip to content

Commit

Permalink
Merge pull request #1239 from eregon/fix-race-update-truffleruby
Browse files Browse the repository at this point in the history
Fix races in publish_subscribe_test.rb and update truffleruby
  • Loading branch information
byroot committed Nov 17, 2023
2 parents a592a63 + 2a65de5 commit 58e43cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: truffleruby-22.2.0
ruby-version: truffleruby
bundler-cache: true
- name: Cache local temporary directory
uses: actions/cache@v3
Expand Down
18 changes: 9 additions & 9 deletions test/redis/publish_subscribe_test.rb
Expand Up @@ -177,7 +177,7 @@ def test_psubscribe_connection_usable_after_raise
end

def test_subscribe_within_subscribe
@channels = []
@channels = Queue.new

thread = new_thread do |r|
r.subscribe(channel_name) do |on|
Expand All @@ -192,7 +192,8 @@ def test_subscribe_within_subscribe

thread.join

assert_equal [channel_name, "bar"], @channels
assert_equal [channel_name, "bar"], [@channels.pop, @channels.pop]
assert_empty @channels
end

def test_other_commands_within_a_subscribe
Expand Down Expand Up @@ -270,8 +271,7 @@ def test_psubscribe_with_timeout
def test_unsubscribe_from_another_thread
@unsubscribed = @subscribed = false
@subscribed_redis = nil
@messages = []
@messages_count = 0
@messages = Queue.new
thread = new_thread do |r|
@subscribed_redis = r
r.subscribe(channel_name) do |on|
Expand All @@ -281,7 +281,6 @@ def test_unsubscribe_from_another_thread

on.message do |channel, message|
@messages << [channel, message]
@messages_count += 1
end

on.unsubscribe do |_channel, _total|
Expand All @@ -293,16 +292,16 @@ def test_unsubscribe_from_another_thread
Thread.pass until @subscribed

redis.publish(channel_name, "test")
Thread.pass until @messages_count == 1
assert_equal [channel_name, "test"], @messages.last
assert_equal [channel_name, "test"], @messages.pop
assert_empty @messages

@subscribed_redis.unsubscribe # this shouldn't block
refute_nil thread.join(2)
assert_equal true, @unsubscribed
end

def test_subscribe_from_another_thread
@events = []
@events = Queue.new
@subscribed_redis = nil
thread = new_thread do |r|
r.subscribe(channel_name) do |on|
Expand Down Expand Up @@ -339,7 +338,8 @@ def test_subscribe_from_another_thread
["unsubscribed", channel_name],
["unsubscribed", "#{channel_name}:2"]
]
assert_equal expected, @events
assert_equal(expected, expected.map { @events.pop })
assert_empty @events
end

private
Expand Down

0 comments on commit 58e43cf

Please sign in to comment.