Skip to content

Commit 030bce6

Browse files
authored
Improve Dependency Processing (#26)
Cache the filtered files to speed up changed dependencies per example. Also, do not compute diff when last example and current example coverage is same for a given file.
1 parent aa421c3 commit 030bce6

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

lib/rspec_tracer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def write_coverage_report(file_name)
250250
}
251251
}
252252

253-
File.write(file_name, JSON.generate(report))
253+
File.write(file_name, JSON.pretty_generate(report))
254254
end
255255

256256
def print_coverage_stats(file_name, elpased)

lib/rspec_tracer/coverage_reporter.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ def record_coverage
2929

3030
def compute_diff(example_id)
3131
peek_coverage.each_pair do |file_path, current_stats|
32-
if @coverage.key?(file_path)
33-
existing_file_diff_coverage(example_id, file_path, current_stats)
34-
else
32+
unless @coverage.key?(file_path)
3533
missing_file_diff_coverage(example_id, file_path, current_stats)
34+
35+
next
3636
end
37+
38+
next if current_stats == @coverage[file_path]
39+
40+
existing_file_diff_coverage(example_id, file_path, current_stats)
3741
end
3842
end
3943

lib/rspec_tracer/reporter.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,56 +229,56 @@ def format_reverse_dependency_report
229229
def write_all_examples_report
230230
file_name = File.join(@cache_dir, 'all_examples.json')
231231

232-
File.write(file_name, JSON.generate(@all_examples))
232+
File.write(file_name, JSON.pretty_generate(@all_examples))
233233
end
234234

235235
def write_flaky_examples_report
236236
file_name = File.join(@cache_dir, 'flaky_examples.json')
237237

238-
File.write(file_name, JSON.generate(@flaky_examples.to_a))
238+
File.write(file_name, JSON.pretty_generate(@flaky_examples.to_a))
239239
end
240240

241241
def write_failed_examples_report
242242
file_name = File.join(@cache_dir, 'failed_examples.json')
243243

244-
File.write(file_name, JSON.generate(@failed_examples.to_a))
244+
File.write(file_name, JSON.pretty_generate(@failed_examples.to_a))
245245
end
246246

247247
def write_pending_examples_report
248248
file_name = File.join(@cache_dir, 'pending_examples.json')
249249

250-
File.write(file_name, JSON.generate(@pending_examples.to_a))
250+
File.write(file_name, JSON.pretty_generate(@pending_examples.to_a))
251251
end
252252

253253
def write_all_files_report
254254
file_name = File.join(@cache_dir, 'all_files.json')
255255

256-
File.write(file_name, JSON.generate(@all_files))
256+
File.write(file_name, JSON.pretty_generate(@all_files))
257257
end
258258

259259
def write_dependency_report
260260
file_name = File.join(@cache_dir, 'dependency.json')
261261

262-
File.write(file_name, JSON.generate(@dependency))
262+
File.write(file_name, JSON.pretty_generate(@dependency))
263263
end
264264

265265
def write_reverse_dependency_report
266266
file_name = File.join(@cache_dir, 'reverse_dependency.json')
267267

268-
File.write(file_name, JSON.generate(@reverse_dependency))
268+
File.write(file_name, JSON.pretty_generate(@reverse_dependency))
269269
end
270270

271271
def write_examples_coverage_report
272272
file_name = File.join(@cache_dir, 'examples_coverage.json')
273273

274-
File.write(file_name, JSON.generate(@examples_coverage))
274+
File.write(file_name, JSON.pretty_generate(@examples_coverage))
275275
end
276276

277277
def write_last_run_report
278278
file_name = File.join(RSpecTracer.cache_path, 'last_run.json')
279279
last_run_data = @last_run.merge(run_id: @run_id, timestamp: Time.now.utc)
280280

281-
File.write(file_name, JSON.generate(last_run_data))
281+
File.write(file_name, JSON.pretty_generate(last_run_data))
282282
end
283283
end
284284
end

lib/rspec_tracer/runner.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,15 @@ def generate_missed_coverage
9090
# rubocop:enable Metrics/AbcSize
9191

9292
def register_dependency(examples_coverage)
93+
filtered_files = Set.new
94+
9395
examples_coverage.each_pair do |example_id, example_coverage|
9496
register_example_files_dependency(example_id)
9597

9698
example_coverage.each_key do |file_path|
97-
source_file = RSpecTracer::SourceFile.from_path(file_path)
98-
99-
next if RSpecTracer.filters.any? { |filter| filter.match?(source_file) }
99+
next if filtered_files.include?(file_path)
100100

101-
@reporter.register_source_file(source_file)
102-
@reporter.register_dependency(example_id, source_file[:file_name])
101+
filtered_files << file_path unless register_file_dependency(example_id, file_path)
103102
end
104103
end
105104

@@ -260,6 +259,17 @@ def register_example_file_dependency(example_id, file_name)
260259
@reporter.register_dependency(example_id, file_name)
261260
end
262261

262+
def register_file_dependency(example_id, file_path)
263+
source_file = RSpecTracer::SourceFile.from_path(file_path)
264+
265+
return false if RSpecTracer.filters.any? { |filter| filter.match?(source_file) }
266+
267+
@reporter.register_source_file(source_file)
268+
@reporter.register_dependency(example_id, source_file[:file_name])
269+
270+
true
271+
end
272+
263273
def generate_examples_status_report
264274
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
265275

0 commit comments

Comments
 (0)