forked from avalanche123/uvrb
- Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathzen_spec.rb
34 lines (26 loc) · 967 Bytes
/
zen_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
require'libuv'
describeLibuv::Listenerdo
it"should ensure there are no remaining object references in callbacks",network: truedo
require'objspace'
checked=[]
# These are created by loop objects and are never cleaned up
# This is OK as the loops are expected to execute for the life of the application
except=[::Libuv::Async, ::Libuv::Timer, ::Libuv::Prepare, ::Libuv::Signal]
ObjectSpace.each_object(Class)do |cls|
nextunlesscls.ancestors.include? ::Libuv::Handle
nextifchecked.include?cls
checked << cls
values=cls.callback_lookup.values
values.select!{|val| except.include?(val.class) ? false : val.class}
ifvalues.length > 0
puts"\nMemory Leak in #{cls} with #{values.length} left over objects"
puts"Checked #{checked.length} classes, objects are:"
values.eachdo |val|
puts"\n#{val}\n"
end
raise'Free the machines!'
end
end
expect(checked.length).tobe > 3
end
end