lib/grntest/tester.rb in grntest-1.6.0 vs lib/grntest/tester.rb in grntest-1.6.1
- old
+ new
@@ -197,11 +197,12 @@
"This option can be used multiple times") do |name|
tester.exclude_test_suite_patterns << parse_name_or_pattern(name)
end
parser.on("--n-workers=N", Integer,
- "Use N workers to run tests") do |n|
+ "Use N workers to run tests",
+ "(#{tester.n_workers})") do |n|
tester.n_workers = n
end
parser.on("--gdb[=COMMAND]",
"Run Groonga on gdb and use COMMAND as gdb",
@@ -380,11 +381,11 @@
@output_type = "json"
@testee = "groonga"
@base_directory = Pathname(".")
@database_path = nil
@reporter = nil
- @n_workers = 1
+ @n_workers = guess_n_cores
@output = $stdout
@keep_database = false
@use_color = nil
@stop_on_failure = false
@suppress_omit_log = true
@@ -540,9 +541,31 @@
end
def run_test_suites(test_suites)
runner = TestSuitesRunner.new(self)
runner.run(test_suites)
+ end
+
+ def guess_n_cores
+ begin
+ if command_exist?("nproc")
+ # Linux
+ Integer(`nproc`.strip, 10)
+ elsif command_exist?("sysctl")
+ # macOS
+ Integer(`sysctl -n hw.logicalcpu`.strip, 10)
+ else
+ # Windows
+ value = ENV["NUMBER_OF_PROCESSORS"]
+ if value
+ Integer(value, 10)
+ else
+ 1
+ end
+ end
+ rescue ArgumentError
+ 1
+ end
end
def detect_suitable_diff
if command_exist?("cut-diff")
@diff = "cut-diff"