File: runtime_logger_spec.rb

package info (click to toggle)
ruby-parallel-tests 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,280 kB
  • sloc: ruby: 5,381; javascript: 30; makefile: 4
file content (54 lines) | stat: -rw-r--r-- 1,342 bytes parent folder | download
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
# frozen_string_literal: true
require 'spec_helper'

describe ParallelTests::Test::RuntimeLogger do
  def run(command)
    result = IO.popen(command, err: [:child, :out], &:read)
    raise "FAILED: #{result}" unless $?.success?
  end

  def run_tests(repo_root_dir)
    run ["ruby", "#{repo_root_dir}/bin/parallel_test", "test", "-n", "2"]
  end

  it "writes a correct log on minitest-5" do
    skip if RUBY_PLATFORM == "java" # just too slow ...
    repo_root = Dir.pwd

    use_temporary_directory do
      # setup simple structure
      FileUtils.mkdir "test"
      2.times do |i|
        File.write("test/#{i}_test.rb", <<-RUBY)
          require 'minitest/autorun'
          require 'parallel_tests/test/runtime_logger'

          class Foo#{i} < Minitest::Test
            def test_foo
              sleep 0.5
              assert true
            end
          end

          class Bar#{i} < Minitest::Test
            def test_foo
              sleep 0.25111
              assert true
            end
          end
        RUBY
      end

      run_tests(repo_root)

      # log looking good ?
      lines = File.read("tmp/parallel_runtime_test.log").split("\n").sort.map { |x| x.sub(/\d$/, "") }
      expect(lines).to eq(
        [
          "test/0_test.rb:0.7",
          "test/1_test.rb:0.7"
        ]
      )
    end
  end
end