Skip to content

Commit 69ee1d9

Browse files
committed
Make allocation tests more robust
I don't remember why we made these changes specifically but I'd like not to lose them for now
1 parent 9230f69 commit 69ee1d9

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

test/integration/documents_allocations_create_test.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ class DocumentsIntegrationTest < ActionDispatch::IntegrationTest
1111
end
1212
end
1313

14-
ObjectSpace.trace_object_allocations do
14+
ObjectSpace::AllocationTracer.setup(%i{path line type})
15+
result = ObjectSpace::AllocationTracer.trace do
1516
3000.times do
1617
Minitest.run_one_method(DocumentsIntegrationTest, 'test_create')
1718
end
1819
end
19-
20+
p allocated: ObjectSpace::AllocationTracer.allocated_count_table[:T_STRING]
21+
result.sort_by { |info, counts| counts.first }.reverse.first(5).each do |r|
22+
p r
23+
end
2024
__END__
2125
ObjectSpace::AllocationTracer.setup(%i{path line type})
2226
result = ObjectSpace::AllocationTracer.trace do

test/integration/documents_allocations_index_test.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,32 @@ class DocumentsIntegrationTest < ActionDispatch::IntegrationTest
88
end
99
end
1010

11-
ObjectSpace.trace_object_allocations do
12-
3000.times do
13-
Minitest.run_one_method(DocumentsIntegrationTest, 'test_index')
14-
end
15-
end
11+
Minitest.run_one_method(DocumentsIntegrationTest, 'test_index')
12+
Minitest.run_one_method(DocumentsIntegrationTest, 'test_index')
1613

17-
__END__
1814
ObjectSpace::AllocationTracer.setup(%i{path line type})
1915
result = ObjectSpace::AllocationTracer.trace do
2016
3000.times do
2117
Minitest.run_one_method(DocumentsIntegrationTest, 'test_index')
2218
end
2319
end
20+
21+
p :TOTAL => ObjectSpace::AllocationTracer.allocated_count_table.values.inject(:+)
22+
23+
result.sort_by { |info, counts| counts.first }.find_all { |info, counts| info.last == :T_ARRAY}.each do |r|
24+
p r
25+
end
26+
__END__
2427
result.sort_by { |info, counts| counts.first }.reverse.first(5).each do |r|
2528
p r
2629
end
30+
ObjectSpace::AllocationTracer.allocated_count_table.each do |k,v|
31+
p k => (v / 3000)
32+
end
33+
34+
ObjectSpace.trace_object_allocations do
35+
3000.times do
36+
Minitest.run_one_method(DocumentsIntegrationTest, 'test_index')
37+
end
38+
end
39+

0 commit comments

Comments
 (0)