From 21d25a701907e2830300d4ed42927929c58a587a Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Sat, 18 May 2024 20:43:41 +0200 Subject: [PATCH 1/3] direct build status to master branch --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 465a110c..964c7ccc 100644 --- a/Readme.md +++ b/Readme.md @@ -1,7 +1,7 @@ # parallel_tests [![Gem Version](https://badge.fury.io/rb/parallel_tests.svg)](https://rubygems.org/gems/parallel_tests) -[![Build status](https://github.com/grosser/parallel_tests/workflows/test/badge.svg)](https://github.com/grosser/parallel_tests/actions?query=workflow%3Atest) +[![Build status](https://github.com/grosser/parallel_tests/workflows/test/badge.svg)](https://github.com/grosser/parallel_tests/actions?query=workflow%3Atest&branch=master) Speedup Minitest + RSpec + Turnip + Cucumber + Spinach by running parallel on multiple CPU cores.
ParallelTests splits tests into balanced groups (by number of lines or runtime) and runs each group in a process with its own database. From 4754d4c5fde8b92cf4fd11c35aaae2ce946e48cd Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Sun, 19 May 2024 11:49:13 +0200 Subject: [PATCH 2/3] fix test runtime logger vs rails and add parallel example --- Readme.md | 11 +++---- lib/parallel_tests/test/runtime_logger.rb | 36 +++++++++-------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/Readme.md b/Readme.md index 964c7ccc..e9552601 100644 --- a/Readme.md +++ b/Readme.md @@ -93,7 +93,7 @@ rake "parallel:rake[my:custom:task,2]" ``` -Running things once +Running setup or teardown once =================== ```Ruby @@ -121,8 +121,11 @@ Even test group runtimes Test groups will often run for different times, making the full test run as slow as the slowest group. -Step 1: Use these loggers (see below) to record test runtime -Step 2: Your next run will use the recorded test runtimes (use `--runtime-log ` if you picked a location different from below) +**Step 1**: Use these loggers (see below) to record test runtime + +**Step 2**: The next test run will use the recorded test runtimes (use `--runtime-log ` if you picked a location different from below) + +**Step 3**: Automate upload/download of test runtime from your CI system [example](https://github.com/grosser/parallel_rails_example/blob/master/.github/workflows/test.yml) (chunks need to be combined, an alternative is [amend](https://github.com/grosser/amend)) ### RSpec @@ -143,8 +146,6 @@ require 'parallel_tests/test/runtime_logger' if ENV['RECORD_RUNTIME'] results will be logged to `tmp/parallel_runtime_test.log` when `RECORD_RUNTIME` is set, so it is not always required or overwritten. -### TODO: add instructions for other frameworks - Loggers ======= diff --git a/lib/parallel_tests/test/runtime_logger.rb b/lib/parallel_tests/test/runtime_logger.rb index 095208d2..6ad74c57 100644 --- a/lib/parallel_tests/test/runtime_logger.rb +++ b/lib/parallel_tests/test/runtime_logger.rb @@ -8,12 +8,12 @@ class RuntimeLogger @@prepared = false class << self - def log_test_run(test) + def log_test_run(file) prepare result = nil time = ParallelTests.delta { result = yield } - log(test, time) + log(file, time) result end @@ -51,20 +51,14 @@ def prepare File.write(logfile, '') end - def log(test, time) - return unless message = message(test, time) + def log(file, time) + return unless file with_locked_log do |logfile| - logfile.seek(0, IO::SEEK_END) - logfile.puts message + logfile.seek 0, IO::SEEK_END + logfile.puts "#{file.sub("#{Dir.pwd}/", "")}:#{time}" end end - def message(test, delta) - return unless method = test.public_instance_methods(true).detect { |m| m =~ /^test_/ } - filename = test.instance_method(method).source_location.first.sub("#{Dir.pwd}/", "") - "#{filename}:#{delta}" - end - def logfile ParallelTests::Test::Runner.runtime_log end @@ -73,18 +67,16 @@ def logfile end end -if defined?(Minitest::Runnable) # Minitest 5 - class << Minitest::Runnable - prepend( - Module.new do - def run(*) - ParallelTests::Test::RuntimeLogger.log_test_run(self) do - super - end +if defined?(Minitest::Test) # Minitest 5 + Minitest::Test.prepend( + Module.new do + def run(*) + ParallelTests::Test::RuntimeLogger.log_test_run(method(name).source_location.first) do + super end end - ) - end + end + ) class << Minitest prepend( From 5f662267eae89ef45f8d12245f63cbd509c30c02 Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Sun, 19 May 2024 21:32:18 +0200 Subject: [PATCH 3/3] undo somehow works now --- lib/parallel_tests/test/runtime_logger.rb | 36 ++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/parallel_tests/test/runtime_logger.rb b/lib/parallel_tests/test/runtime_logger.rb index 6ad74c57..095208d2 100644 --- a/lib/parallel_tests/test/runtime_logger.rb +++ b/lib/parallel_tests/test/runtime_logger.rb @@ -8,12 +8,12 @@ class RuntimeLogger @@prepared = false class << self - def log_test_run(file) + def log_test_run(test) prepare result = nil time = ParallelTests.delta { result = yield } - log(file, time) + log(test, time) result end @@ -51,14 +51,20 @@ def prepare File.write(logfile, '') end - def log(file, time) - return unless file + def log(test, time) + return unless message = message(test, time) with_locked_log do |logfile| - logfile.seek 0, IO::SEEK_END - logfile.puts "#{file.sub("#{Dir.pwd}/", "")}:#{time}" + logfile.seek(0, IO::SEEK_END) + logfile.puts message end end + def message(test, delta) + return unless method = test.public_instance_methods(true).detect { |m| m =~ /^test_/ } + filename = test.instance_method(method).source_location.first.sub("#{Dir.pwd}/", "") + "#{filename}:#{delta}" + end + def logfile ParallelTests::Test::Runner.runtime_log end @@ -67,16 +73,18 @@ def logfile end end -if defined?(Minitest::Test) # Minitest 5 - Minitest::Test.prepend( - Module.new do - def run(*) - ParallelTests::Test::RuntimeLogger.log_test_run(method(name).source_location.first) do - super +if defined?(Minitest::Runnable) # Minitest 5 + class << Minitest::Runnable + prepend( + Module.new do + def run(*) + ParallelTests::Test::RuntimeLogger.log_test_run(self) do + super + end end end - end - ) + ) + end class << Minitest prepend(