Skip to content

Instantly share code, notes, and snippets.

@everton
Last active February 4, 2016 20:58
Show Gist options
  • Save everton/aa4a1fff3c6bc02e266d to your computer and use it in GitHub Desktop.
Save everton/aa4a1fff3c6bc02e266d to your computer and use it in GitHub Desktop.
Minitest running twice when dealing with forks
require 'minitest/autorun'
class TestSuite
def self.before_run
pid = fork do
puts "on fork"
exit 0
end
Process.detach pid
end
end
class MyTestCase < Minitest::Test
TestSuite.before_run
end
class TestTests < MyTestCase
def test_aa
puts "aaa"
end
end
@everton
Copy link
Author

everton commented Feb 4, 2016

$ ruby minitest_twice_fork.rb
on fork
Run options: --seed 13402Run options: --seed 30729

# Running:



# Running:



Finished in 0.000856s, 0.0000 runs/s, 0.0000 assertions/s.

0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
aaa
.

Finished in 0.001406s, 711.3979 runs/s, 0.0000 assertions/s.

1 runs, 0 assertions, 0 failures, 0 errors, 0 skips

@everton
Copy link
Author

everton commented Feb 4, 2016

The reason for this duplication is that Minitest uses #at_exit to write results (is the only way to deal with exits inside application); To workaround this, calls to Kernel#exit should be replaced by Kernel#exit!, which ignore callbacks).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment