Skip to content

Commit 104ea23

Browse files
committed
test: handle Ruby 3.3 behavior around passing unshareable objects
1 parent 43cca4f commit 104ea23

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

test/test_integration_ractor.rb

+18-25
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,26 @@ def test_ractor_safe
2222
def test_ractor_share_database
2323
skip("Requires Ruby with Ractors") unless SQLite3.ractor_safe?
2424

25-
db_receiver = Ractor.new do
26-
db = Ractor.receive
27-
Ractor.yield db.object_id
28-
begin
29-
db.execute("create table test_table ( b integer primary key)")
30-
raise "Should have raised an exception in db.execute()"
31-
rescue => e
32-
Ractor.yield e
25+
db = SQLite3::Database.open(":memory:")
26+
27+
if RUBY_VERSION >= "3.3"
28+
# after ruby/ruby@ce47ee00
29+
ractor = Ractor.new do
30+
Ractor.receive
3331
end
32+
33+
assert_raises(Ractor::Error) { ractor.send(db) }
34+
else
35+
# before ruby/ruby@ce47ee00 T_DATA objects could be copied
36+
ractor = Ractor.new do
37+
local_db = Ractor.receive
38+
Ractor.yield local_db.object_id
39+
end
40+
ractor.send(db)
41+
copy_id = ractor.take
42+
43+
assert_not_equal db.object_id, copy_id
3444
end
35-
db_creator = Ractor.new(db_receiver) do |db_receiver|
36-
db = SQLite3::Database.open(":memory:")
37-
Ractor.yield db.object_id
38-
db_receiver.send(db)
39-
sleep 0.1
40-
db.execute("create table test_table ( a integer primary key)")
41-
end
42-
first_oid = db_creator.take
43-
second_oid = db_receiver.take
44-
assert_not_equal first_oid, second_oid
45-
ex = db_receiver.take
46-
# For now, let's assert that you can't pass database connections around
47-
# between different Ractors. Letting a live DB connection exist in two
48-
# threads that are running concurrently might expose us to footguns and
49-
# lead to data corruption, so we should avoid this possibility and wait
50-
# until connections can be given away using `yield` or `send`.
51-
assert_equal "prepare called on a closed database", ex.message
5245
end
5346

5447
def test_ractor_stress

0 commit comments

Comments
 (0)