@@ -116,12 +116,16 @@ def test_busy_timeout
116116 def test_busy_timeout_blocks_gvl
117117 threads = [ 1 , 2 ] . map do
118118 Thread . new do
119- db = SQLite3 ::Database . new ( "test.db" )
120- db . busy_timeout = 3000
121- db . transaction ( :immediate ) do
122- db . execute "insert into foo ( b ) values ( ? )" , rand ( 1000 ) . to_s
123- sleep 1
124- db . execute "insert into foo ( b ) values ( ? )" , rand ( 1000 ) . to_s
119+ begin
120+ db = SQLite3 ::Database . new ( "test.db" )
121+ db . busy_timeout = 3000
122+ db . transaction ( :immediate ) do
123+ db . execute "insert into foo ( b ) values ( ? )" , rand ( 1000 ) . to_s
124+ sleep 1
125+ db . execute "insert into foo ( b ) values ( ? )" , rand ( 1000 ) . to_s
126+ end
127+ ensure
128+ db . close if db
125129 end
126130 end
127131 end
@@ -134,12 +138,16 @@ def test_busy_timeout_blocks_gvl
134138 def test_busy_handler_timeout_releases_gvl
135139 threads = [ 1 , 2 ] . map do
136140 Thread . new do
137- db = SQLite3 ::Database . new ( "test.db" )
138- db . busy_handler_timeout = 3000
139- db . transaction ( :immediate ) do
140- db . execute "insert into foo ( b ) values ( ? )" , rand ( 1000 ) . to_s
141- sleep 1
142- db . execute "insert into foo ( b ) values ( ? )" , rand ( 1000 ) . to_s
141+ begin
142+ db = SQLite3 ::Database . new ( "test.db" )
143+ db . busy_handler_timeout = 3000
144+ db . transaction ( :immediate ) do
145+ db . execute "insert into foo ( b ) values ( ? )" , rand ( 1000 ) . to_s
146+ sleep 1
147+ db . execute "insert into foo ( b ) values ( ? )" , rand ( 1000 ) . to_s
148+ end
149+ ensure
150+ db . close if db
143151 end
144152 end
145153 end
0 commit comments