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 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
|
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative "../lib/sus/config"
config = Sus::Config.load
Result = Struct.new(:job, :assertions)
require_relative "../lib/sus"
require_relative "../lib/sus/output"
jobs = Thread::Queue.new
results = Thread::Queue.new
guard = Thread::Mutex.new
progress = Sus::Output::Progress.new(config.output)
require "etc"
count = Etc.nprocessors
loader = Thread.new do
registry = config.registry
registry.each do |child|
guard.synchronize{progress.expand}
jobs << child
end
jobs.close
end
top = Sus::Assertions.new(output: Sus::Output::Null.new)
config.before_tests(top)
aggregation = Thread.new do
while result = results.pop
guard.synchronize{progress.increment}
top.add(result.assertions)
guard.synchronize{progress.report(count, top, :busy)}
end
guard.synchronize{progress.clear}
top
end
workers = count.times.map do |index|
Thread.new do
while job = jobs.pop
guard.synchronize{progress.report(index, job, :busy)}
assertions = Sus::Assertions.new(output: Sus::Output::Null.new)
job.call(assertions)
results << Result.new(job, assertions)
guard.synchronize{progress.report(index, "idle", :free)}
end
end
end
loader.join
workers.each(&:join)
results.close
assertions = aggregation.value
config.after_tests(assertions)
unless assertions.passed?
exit(1)
end
|