Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions test/test_discarding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ def in_a_forked_process
@read.close
end

# A writable connection leaked by an earlier test triggers the fork-safety warning. GC.start
# cannot free a leaked connection that is still reachable, so close it instead.
def close_leaked_writable_connections
ObjectSpace.each_object(SQLite3::Database) do |db|
db.close unless db.closed? || db.readonly?
end
end

def test_fork_discards_an_open_readwrite_connection
skip("interpreter doesn't support fork") unless Process.respond_to?(:fork)
skip("valgrind doesn't handle forking") if i_am_running_in_valgrind

GC.start
close_leaked_writable_connections
begin
db = SQLite3::Database.new(DBPATH)

Expand All @@ -66,7 +74,7 @@ def test_fork_does_not_discard_closed_connections
skip("interpreter doesn't support fork") unless Process.respond_to?(:fork)
skip("valgrind doesn't handle forking") if i_am_running_in_valgrind

GC.start
close_leaked_writable_connections
begin
db = SQLite3::Database.new(DBPATH)
db.close
Expand All @@ -91,7 +99,7 @@ def test_fork_does_not_discard_readonly_connections
skip("interpreter doesn't support fork") unless Process.respond_to?(:fork)
skip("valgrind doesn't handle forking") if i_am_running_in_valgrind

GC.start
close_leaked_writable_connections
begin
SQLite3::Database.open(DBPATH) do |db|
db.execute("create table foo (bar int)")
Expand Down Expand Up @@ -122,7 +130,7 @@ def test_close_does_not_discard_readonly_connections
skip("interpreter doesn't support fork") unless Process.respond_to?(:fork)
skip("valgrind doesn't handle forking") if i_am_running_in_valgrind

GC.start
close_leaked_writable_connections
begin
SQLite3::Database.open(DBPATH) do |db|
db.execute("create table foo (bar int)")
Expand Down
Loading