@@ -113,30 +113,39 @@ def test_busy_timeout
113113 assert time . real *1000 >= 1000
114114 end
115115
116- def test_busy_timeout_blocks_gvl_while_busy_handler_timeout_releases_gvl
117- busy_timeout_db = SQLite3 ::Database . open ( "test.db" )
118- busy_timeout_db . busy_timeout 1000
119- busy_timeout_time = Benchmark . measure do
120- @db . transaction ( :exclusive ) do
121- assert_raises ( SQLite3 ::BusyException ) do
122- busy_timeout_db . transaction ( :exclusive ) { }
116+ def test_busy_timeout_blocks_gvl
117+ threads = [ 1 , 2 ] . map do
118+ 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
123125 end
124126 end
125127 end
126- busy_timeout_db . close
127-
128- busy_handler_timeout_db = SQLite3 ::Database . open ( "test.db" )
129- busy_handler_timeout_db . busy_handler_timeout = 1000
130- busy_handler_timeout_time = Benchmark . measure do
131- @db . transaction ( :exclusive ) do
132- assert_raises ( SQLite3 ::BusyException ) do
133- busy_handler_timeout_db . transaction ( :exclusive ) { }
128+
129+ assert_raise ( SQLite3 ::BusyException ) do
130+ threads . each ( &:join )
131+ end
132+ end
133+
134+ def test_busy_handler_timeout_releases_gvl
135+ threads = [ 1 , 2 ] . map do
136+ 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
134143 end
135144 end
136145 end
137- busy_handler_timeout_db . close
138146
139- assert_operator busy_timeout_time . real , :> , busy_handler_timeout_time . real
140- assert_operator busy_timeout_time . real , :> , busy_handler_timeout_time . real +1
147+ assert_nothing_raised do
148+ threads . each ( &:join )
149+ end
141150 end
142151end
0 commit comments