-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgc_threading_spec.rb
52 lines (44 loc) · 1.33 KB
/
gc_threading_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
RSpec.describe 'Rszr' do
context 'Garbage collection' do
it 'releases instances' do
10.times { GC.start(full_mark: true, immediate_sweep: true); sleep 0.5; print '.' }
expect(ObjectSpace.each_object(Rszr::Image).count).to eq(0)
20.times { Rszr::Image.load(RSpec.root.join('images/bacon.png')) }
expect(ObjectSpace.each_object(Rszr::Image).count).to be > 0
5.times { GC.start(full_mark: true, immediate_sweep: true); sleep 0.5; print '.' }
expect(ObjectSpace.each_object(Rszr::Image).count).to eq(0)
end
end
context 'Threading' do
def data
@data ||= RSpec.root.join('images', 'bacon.png').binread.freeze
end
def resize
Tempfile.open('src') do |src_file|
src_file.binmode
src_file.write data
Rszr::Image.open(src_file.path) do |image|
image.resize!(200, :auto)
Tempfile.open('dst') do |dst_file|
image.save(dst_file.path)
dst_file.close(true)
end
end
src_file.close(true)
end
end
it 'synchronizes access to imlib2 context by GIL' do
threads = []
10.times do |t|
threads << Thread.new do
1000.times do |i|
print '.'
resize
end
end
end
threads.each(&:join)
puts
end
end
end