Skip to content

Commit 77906c4

Browse files
committed
Try to create a more resilient test for the busy_handler_timeout
1 parent a8d1715 commit 77906c4

File tree

1 file changed

+16
-44
lines changed

1 file changed

+16
-44
lines changed

test/test_integration_pending.rb

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -114,64 +114,36 @@ def test_busy_timeout
114114
end
115115

116116
def test_busy_timeout_blocks_gvl
117-
t1 = Thread.new do
118-
begin
119-
db1 = SQLite3::Database.open( "test.db" )
120-
db1.transaction( :exclusive ) do
121-
sleep 0.05
122-
end
123-
ensure
124-
db1.close if db1
125-
end
126-
end
117+
db2 = SQLite3::Database.open( "test.db" )
118+
db2.busy_timeout 1000
127119

128-
t2 = Thread.new do
129-
begin
130-
db2 = SQLite3::Database.open( "test.db" )
131-
db2.busy_timeout 1000
132-
db2.transaction( :exclusive ) do
133-
sleep 0.01
120+
time = Benchmark.measure do
121+
@db.transaction( :exclusive ) do
122+
assert_raises( SQLite3::BusyException ) do
123+
db2.transaction( :exclusive ) {}
134124
end
135-
ensure
136-
db2.close if db2
137125
end
138126
end
139127

140-
time = Benchmark.measure do
141-
[t1, t2].each(&:join)
142-
end
128+
db2.close
143129

144-
assert_operator time.real, :>=, 1
130+
assert_operator time.real, :>=, 2
145131
end
146132

147133
def test_busy_handler_timeout_releases_gvl
148-
t1 = Thread.new do
149-
begin
150-
db1 = SQLite3::Database.open( "test.db" )
151-
db1.transaction( :exclusive ) do
152-
sleep 0.05
153-
end
154-
ensure
155-
db1.close if db1
156-
end
157-
end
134+
db2 = SQLite3::Database.open( "test.db" )
135+
db2.busy_handler_timeout = 1000
158136

159-
t2 = Thread.new do
160-
begin
161-
db2 = SQLite3::Database.open( "test.db" )
162-
db2.busy_handler_timeout = 1000
163-
db2.transaction( :exclusive ) do
164-
sleep 0.01
137+
time = Benchmark.measure do
138+
@db.transaction( :exclusive ) do
139+
assert_raises( SQLite3::BusyException ) do
140+
db2.transaction( :exclusive ) {}
165141
end
166-
ensure
167-
db2.close if db2
168142
end
169143
end
170144

171-
time = Benchmark.measure do
172-
[t1, t2].each(&:join)
173-
end
145+
db2.close
174146

175-
assert_operator time.real, :<, 1
147+
assert_operator time.real, :>=, 1
176148
end
177149
end

0 commit comments

Comments
 (0)