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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/minitest/queue/lazy_test_discovery.rb', line 22
def each_test(files)
discovery_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
total_files = 0
new_runnable_files = 0
reopened_files = 0
reopened_candidates = 0
reopened_scan_time = 0.0
seen = Set.new
runnables = Minitest::Test.runnables
known_count = runnables.size
by_full_name = {}
by_short_name = Hash.new { |h, k| h[k] = [] }
index_runnables(runnables, by_full_name, by_short_name)
files.each do |file|
total_files += 1
file_path = File.expand_path(file)
begin
@loader.load_file(file_path)
rescue CI::Queue::FileLoadError => error
method_name = "load_file_#{Zlib.crc32(file_path).to_s(16)}"
class_name = "CIQueue::FileLoadError"
test_id = "#{class_name}##{method_name}"
entry = CI::Queue::QueueEntry.format(
test_id,
CI::Queue::QueueEntry.encode_load_error(file_path, error),
)
yield Minitest::Queue::LazySingleExample.new(
class_name,
method_name,
file_path,
loader: @loader,
resolver: @resolver,
load_error: error,
queue_entry: entry,
)
next
end
runnables = Minitest::Test.runnables
candidates = []
if runnables.size > known_count
new_runnables = runnables[known_count..]
known_count = runnables.size
index_runnables(new_runnables, by_full_name, by_short_name)
candidates.concat(new_runnables)
new_runnable_files += 1
else
reopened_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
reopened = reopened_runnables_for_file(file_path, by_full_name, by_short_name)
reopened_scan_time += Process.clock_gettime(Process::CLOCK_MONOTONIC) - reopened_start
unless reopened.empty?
reopened_files += 1
reopened_candidates += reopened.size
end
candidates.concat(reopened)
end
enqueue_discovered_tests(candidates.uniq, file_path, seen) do |test|
yield test
end
end
ensure
debug_discovery_profile(
discovery_start: discovery_start,
total_files: total_files,
new_runnable_files: new_runnable_files,
reopened_files: reopened_files,
reopened_candidates: reopened_candidates,
reopened_scan_time: reopened_scan_time,
)
end
|