@@ -31,20 +31,14 @@ def merge_results(*file_paths, ignore_timeout: false)
31
31
# In big CI setups you might deal with 100s of CI jobs and each one producing Megabytes
32
32
# of data. Reading them all in easily produces Gigabytes of memory consumption which
33
33
# we want to avoid.
34
- #
35
- # For similar reasons a SimpleCov::Result is only created in the end as that'd create
36
- # even more data especially when it also reads in all source files.
37
- initial_memo = valid_results ( file_paths . shift , ignore_timeout : ignore_timeout )
38
-
39
- command_names , coverage = file_paths . reduce ( initial_memo ) do |memo , file_path |
40
- merge_coverage ( memo , valid_results ( file_path , ignore_timeout : ignore_timeout ) )
41
- end
42
34
43
- create_result ( command_names , coverage )
35
+ results = file_paths . map { |path | valid_results ( path , ignore_timeout : ignore_timeout ) }
36
+ merge_coverage ( results )
44
37
end
45
38
46
39
def valid_results ( file_path , ignore_timeout : false )
47
- results = parse_file ( file_path )
40
+ raw_results = parse_file ( file_path )
41
+ results = Result . from_hash ( raw_results )
48
42
merge_valid_results ( results , ignore_timeout : ignore_timeout )
49
43
end
50
44
@@ -72,42 +66,25 @@ def parse_json(content)
72
66
end
73
67
74
68
def merge_valid_results ( results , ignore_timeout : false )
75
- results = results . select { |_command_name , data | within_merge_timeout? ( data ) } unless ignore_timeout
76
-
77
- command_plus_coverage = results . map do |command_name , data |
78
- [ [ command_name ] , adapt_result ( data . fetch ( "coverage" ) ) ]
79
- end
80
-
81
- # one file itself _might_ include multiple test runs
82
- merge_coverage ( *command_plus_coverage )
69
+ results = results . select { |x | within_merge_timeout? ( x ) } unless ignore_timeout
70
+ merge_coverage ( results )
83
71
end
84
72
85
- def within_merge_timeout? ( data )
86
- time_since_result_creation ( data ) < SimpleCov . merge_timeout
73
+ def within_merge_timeout? ( result )
74
+ Time . now - result . created_at < SimpleCov . merge_timeout
87
75
end
88
76
89
- def time_since_result_creation ( data )
90
- Time . now - Time . at ( data . fetch ( "timestamp" ) )
91
- end
92
-
93
- def create_result ( command_names , coverage )
94
- return nil unless coverage
95
-
96
- command_name = command_names . reject ( &:empty? ) . sort . join ( ", " )
97
- SimpleCov ::Result . new ( coverage , command_name : command_name )
98
- end
77
+ def merge_coverage ( results )
78
+ results = results . compact
99
79
100
- def merge_coverage ( *results )
101
- return [ [ "" ] , nil ] if results . empty?
80
+ return nil if results . size . zero?
102
81
return results . first if results . size == 1
103
82
104
- results . reduce do |( memo_command , memo_coverage ) , ( command , coverage ) |
105
- # timestamp is dropped here, which is intentional (we merge it, it gets a new time stamp as of now)
106
- merged_coverage = Combine . combine ( Combine ::ResultsCombiner , memo_coverage , coverage )
107
- merged_command = memo_command + command
108
-
109
- [ merged_command , merged_coverage ]
110
- end
83
+ parsed_results = results . map ( &:original_result )
84
+ combined_result = SimpleCov ::Combine ::ResultsCombiner . combine ( *parsed_results )
85
+ result = SimpleCov ::Result . new ( combined_result )
86
+ result . command_name = results . map ( &:command_name ) . reject ( &:empty? ) . sort . join ( ", " )
87
+ result
111
88
end
112
89
113
90
#
@@ -118,9 +95,8 @@ def merged_result
118
95
# conceptually this is just doing `merge_results(resultset_path)`
119
96
# it's more involved to make syre `synchronize_resultset` is only used around reading
120
97
resultset_hash = read_resultset
121
- command_names , coverage = merge_valid_results ( resultset_hash )
122
-
123
- create_result ( command_names , coverage )
98
+ results = Result . from_hash ( resultset_hash )
99
+ merge_valid_results ( results )
124
100
end
125
101
126
102
def read_resultset
@@ -164,31 +140,6 @@ def synchronize_resultset
164
140
@resultset_locked = false
165
141
end
166
142
end
167
-
168
- # We changed the format of the raw result data in simplecov, as people are likely
169
- # to have "old" resultsets lying around (but not too old so that they're still
170
- # considered we can adapt them).
171
- # See https://github.com/simplecov-ruby/simplecov/pull/824#issuecomment-576049747
172
- def adapt_result ( result )
173
- if pre_simplecov_0_18_result? ( result )
174
- adapt_pre_simplecov_0_18_result ( result )
175
- else
176
- result
177
- end
178
- end
179
-
180
- # pre 0.18 coverage data pointed from file directly to an array of line coverage
181
- def pre_simplecov_0_18_result? ( result )
182
- _key , data = result . first
183
-
184
- data . is_a? ( Array )
185
- end
186
-
187
- def adapt_pre_simplecov_0_18_result ( result )
188
- result . transform_values do |line_coverage_data |
189
- { "lines" => line_coverage_data }
190
- end
191
- end
192
143
end
193
144
end
194
145
end
0 commit comments