Skip to content

Commit 58e43cf

Browse files
authored
Merge pull request #1239 from eregon/fix-race-update-truffleruby
Fix races in publish_subscribe_test.rb and update truffleruby
2 parents a592a63 + 2a65de5 commit 58e43cf

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
- name: Set up Ruby
8989
uses: ruby/setup-ruby@v1
9090
with:
91-
ruby-version: truffleruby-22.2.0
91+
ruby-version: truffleruby
9292
bundler-cache: true
9393
- name: Cache local temporary directory
9494
uses: actions/cache@v3

test/redis/publish_subscribe_test.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_psubscribe_connection_usable_after_raise
177177
end
178178

179179
def test_subscribe_within_subscribe
180-
@channels = []
180+
@channels = Queue.new
181181

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

193193
thread.join
194194

195-
assert_equal [channel_name, "bar"], @channels
195+
assert_equal [channel_name, "bar"], [@channels.pop, @channels.pop]
196+
assert_empty @channels
196197
end
197198

198199
def test_other_commands_within_a_subscribe
@@ -270,8 +271,7 @@ def test_psubscribe_with_timeout
270271
def test_unsubscribe_from_another_thread
271272
@unsubscribed = @subscribed = false
272273
@subscribed_redis = nil
273-
@messages = []
274-
@messages_count = 0
274+
@messages = Queue.new
275275
thread = new_thread do |r|
276276
@subscribed_redis = r
277277
r.subscribe(channel_name) do |on|
@@ -281,7 +281,6 @@ def test_unsubscribe_from_another_thread
281281

282282
on.message do |channel, message|
283283
@messages << [channel, message]
284-
@messages_count += 1
285284
end
286285

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

295294
redis.publish(channel_name, "test")
296-
Thread.pass until @messages_count == 1
297-
assert_equal [channel_name, "test"], @messages.last
295+
assert_equal [channel_name, "test"], @messages.pop
296+
assert_empty @messages
298297

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

304303
def test_subscribe_from_another_thread
305-
@events = []
304+
@events = Queue.new
306305
@subscribed_redis = nil
307306
thread = new_thread do |r|
308307
r.subscribe(channel_name) do |on|
@@ -339,7 +338,8 @@ def test_subscribe_from_another_thread
339338
["unsubscribed", channel_name],
340339
["unsubscribed", "#{channel_name}:2"]
341340
]
342-
assert_equal expected, @events
341+
assert_equal(expected, expected.map { @events.pop })
342+
assert_empty @events
343343
end
344344

345345
private

0 commit comments

Comments
 (0)