-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class RactorTest < Minitest::Test | ||
def setup | ||
skip("Ractors are not supported on this Ruby version") unless defined?(::Ractor) | ||
skip("Hiredis is not Ractor safe") if RedisClient.default_driver.name == "RedisClient::HiredisConnection" | ||
begin | ||
Ractor.new { RedisClient.default_driver.name }.take | ||
rescue Ractor::RemoteError | ||
skip("Ractor implementation is too limited (MRI 3.0?)") | ||
end | ||
end | ||
|
||
def test_get_and_set_within_ractor | ||
ractor = Ractor.new do | ||
within_ractor_redis = ClientTestHelper.new_client | ||
within_ractor_redis.call("SET", "foo", "bar") | ||
within_ractor_redis.call("GET", "foo") | ||
end | ||
|
||
assert_equal("bar", ractor.take) | ||
end | ||
|
||
def test_multiple_ractors | ||
ractor1 = Ractor.new do | ||
within_ractor_redis = ClientTestHelper.new_client | ||
within_ractor_redis.call("SET", "foo", "bar") | ||
within_ractor_redis.call("GET", "foo") | ||
end | ||
|
||
ractor1.take # We do this to ensure that the SET has been processed | ||
|
||
ractor2 = Ractor.new do | ||
key = Ractor.receive | ||
within_ractor_redis = ClientTestHelper.new_client | ||
within_ractor_redis.call("GET", key) | ||
end | ||
ractor2.send("foo") | ||
|
||
assert_equal("bar", ractor2.take) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters