Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Test groups will often run for different times, making the full test run as slow

**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 <file>` if you picked a location different from below)
**Step 2**: The next test run will use the recorded test runtimes (use `--runtime-log <file>` if you wrote to a location different from default)

**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))

Expand All @@ -140,17 +140,17 @@ Rspec: Add to your `.rspec_parallel` (or `.rspec`), but can also be used via `--
--format progress
--format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log

To use a custom logfile location (default: `tmp/parallel_runtime_rspec.log`), use the CLI: `parallel_test spec -t rspec --runtime-log my.log`

### Minitest

Add to your `test_helper.rb`:
```ruby
require 'parallel_tests/test/runtime_logger' if ENV['RECORD_RUNTIME']
if ENV['RECORD_RUNTIME']
require 'parallel_tests/test/runtime_logger'
# ParallelTests::Test::RuntimeLogger.logfile = "tmp/parallel_runtime_test.log" # where to write it
end
```

results will be logged to `tmp/parallel_runtime_test.log` when `RECORD_RUNTIME` is set,
so it is not always required or overwritten.
results will be logged when `RECORD_RUNTIME` is set, so it is not always required or overwritten.

Loggers
=======
Expand Down
4 changes: 3 additions & 1 deletion lib/parallel_tests/test/runtime_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class RuntimeLogger
@@prepared = false

class << self
attr_writer :logfile

def log_test_run(test)
prepare

Expand Down Expand Up @@ -66,7 +68,7 @@ def message(test, delta)
end

def logfile
ParallelTests::Test::Runner.runtime_log
@logfile || ParallelTests::Test::Runner.runtime_log
end
end
end
Expand Down
24 changes: 24 additions & 0 deletions spec/parallel_tests/test/runtime_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,28 @@ def test_foo
)
end
end

it "can write to a custom location" do
skip if RUBY_PLATFORM == "java" # just too slow ...
repo_root = Dir.pwd

use_temporary_directory do
FileUtils.mkdir "test"
File.write("test/a_test.rb", <<-RUBY)
require 'minitest/autorun'
require 'parallel_tests/test/runtime_logger'
ParallelTests::Test::RuntimeLogger.logfile = "foo.log"

class Bar < Minitest::Test
def test_foo
assert true
end
end
RUBY

run_tests(repo_root)

expect(File.exist?("foo.log")).to eq(true)
end
end
end
Loading