2

When run in parallel, Ruby 1.9.3 doesn't run any unit tests

Given the following code,

# Modified from https://gist.github.com/1334056/121396125ca4dd7ee1bb81536cce0754700f20fb
# replication.rb
require 'test/unit'
class TestTest < Test::Unit::TestCase
  def test_one
    assert true
  end

  def test_two
    assert true
  end
end

unit testing works when it's not run in parallel, but doesn't work when it's run in parallel:

$ ruby1.9.1 replication.rb 
Run options: 

# Running tests:

..

Finished tests in 0.000348s, 5740.7094 tests/s, 5740.7094 assertions/s.

2 tests, 2 assertions, 0 failures, 0 errors, 0 skips

$ ruby1.9.1 replication.rb --jobs=2 --ruby /usr/bin/ruby1.9.1
Run options: --jobs=2 --ruby /usr/bin/ruby1.9.1

# Running tests:


Retrying...





Finished tests in 0.039012s, 0.0000 tests/s, 0.0000 assertions/s.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

For what it's worth, here's what happens when the debugging switch is on:

$ export RUBYOPT="-d"
$ ruby1.9.1 replication.rb 
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1243 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1252 - cannot load such file -- rubygems/defaults/ruby
Run options: 

# Running tests:

..

Finished tests in 0.000350s, 5718.3539 tests/s, 5718.3539 assertions/s.

2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
$ ruby1.9.1 replication.rb --jobs=2 --ruby /usr/bin/ruby1.9.1
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1243 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1252 - cannot load such file -- rubygems/defaults/ruby
Run options: --jobs=2 --ruby /usr/bin/ruby1.9.1

# Running tests:

Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1243 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1252 - cannot load such file -- rubygems/defaults/ruby
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1243 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1252 - cannot load such file -- rubygems/defaults/ruby
/usr/lib/ruby/1.9.1/test/unit/parallel.rb:149: warning: method redefined; discarding old on_parallel_worker?
/usr/lib/ruby/1.9.1/test/unit/testcase.rb:11: warning: previous definition of on_parallel_worker? was here
/usr/lib/ruby/1.9.1/test/unit/parallel.rb:149: warning: method redefined; discarding old on_parallel_worker?
/usr/lib/ruby/1.9.1/test/unit/testcase.rb:11: warning: previous definition of on_parallel_worker? was here
Exception `Errno::EPIPE' at /usr/lib/ruby/1.9.1/test/unit/parallel.rb:125 - Broken pipe - <STDOUT>
Exception `Errno::EPIPE' at /usr/lib/ruby/1.9.1/test/unit/parallel.rb:133 - Broken pipe - <STDOUT>

Retrying...





Finished tests in 0.033203s, 0.0000 tests/s, 0.0000 assertions/s.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

I also tried requiring minitest, but that didn't have parallel testing available:

# mini_me.rb
# modified from http://apidock.com/ruby/MiniTest
require 'minitest/autorun'

class TestMeme < MiniTest::Unit::TestCase
  def test_one
    assert true
  end

  def test_two
    assert true
  end
end

gives

$ ruby1.9.1 mini_me.rb --help
minitest options:
    -h, --help                       Display this help.
    -s, --seed SEED                  Sets random seed
    -v, --verbose                    Verbose. Show progress processing files.
    -n, --name PATTERN               Filter test names on pattern.

And here's the version of Ruby and ubuntu.

$ ruby1.9.1 --version
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

$ uname -a
Linux [redacted] 3.2.0-24-generic #37-Ubuntu SMP Wed Apr 25 08:43:22 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

I've also run the first script using a recent commit of Ruby on OS X snow leopard (ruby 2.0.0dev (2012-05-05 trunk 35543) [x86_64-darwin10.8.0]), and it didn't work there.

What am I doing wrong?

The following happens when I have multiple files, but don't explicitly use Test::Unit::Runner

test1.rb

require "test/unit"

class Test1 < Test::Unit::TestCase
  def test_one
    assert true
  end
end

test2.rb

require "test/unit"

class Test2 < Test::Unit::TestCase
  def test_two
    assert true
  end
end

test_all.rb

require_relative "test1"
require_relative "test2"

Trying using this approach:

$ ruby test_all.rb --basedir=. --jobs 2 --ruby /Users/agrimm/.rvm/rubies/ruby-head/bin/ruby
Run options: --basedir=. --jobs 2 --ruby /Users/agrimm/.rvm/rubies/ruby-head/bin/ruby

# Running tests:


Retrying...





Finished tests in 0.075256s, 0.0000 tests/s, 0.0000 assertions/s.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

ruby -v: ruby 2.0.0dev (2012-05-05 trunk 35543) [x86_64-darwin10.8.0]

1 Answer 1

3

I'm sora_h a maintainer of test/unit.

test/unit parallelizes for each test file.

You need to separate test file and TestCase to parallelize.

Sorry for inconvenience, but we can't parallelize for each test_* methods because there are some test_* methods can't run separately. (needs to be ordered)

You can use Test::Unit::Runner to run multiple files.

Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.