From 808e6c6269c6f83675273d7bd5a2998a09637e3f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 20 Oct 2013 00:03:43 +0000 Subject: test/helper: prevent minitest at_exit from running in children Since we fork in tests, at_exit handlers may run in children and cause strange test failures. This seems necessary in minitest 5.0.8, but not 4.3.2. We also cannot use exit! in forked children because apps hosted on yahns will probably expect at_exit handlers they register to run. --- test/helper.rb | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index 626a046..5fa9599 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -51,33 +51,29 @@ if ENV["COVERAGE"] end gem 'minitest' -require 'minitest/autorun' -require "tempfile" - -Testcase = begin - Minitest::Test # minitest 5 -rescue NameError - Minitest::Unit::TestCase # minitest 4 +begin # favor minitest 5 + require 'minitest' + Testcase = Minitest::Test + mtobj = Minitest +rescue NameError, LoadError # but support minitest 4 + require 'minitest/unit' + Testcase = Minitest::Unit::TestCase + mtobj = MiniTest::Unit.new end -FIFOS = [] -def tmpfifo - tmp = Tempfile.new(%w(yahns-test .fifo)) - path = tmp.path - tmp.close! - assert system(*%W(mkfifo #{path})), "mkfifo #{path}" - - GTL.synchronize do - if FIFOS.empty? - at_exit do - FIFOS.each { |(pid,_path)| File.unlink(_path) if $$ == pid } - end - end - FIFOS << [ $$, path ] +# Not using minitest/autorun because that doesn't guard against redundant +# extra runs with fork. We cannot use exit! in the tests either +# (since users/apps hosted on yahns _should_ expect exit, not exit!). +TSTART_PID = $$ +at_exit do + # skipping @@after_run stuff in minitest since we don't need it + case $! + when nil, SystemExit + mtobj.run(ARGV) if $$ == TSTART_PID end - path end +require "tempfile" require 'tmpdir' class Dir require 'fileutils' -- cgit v1.2.3-24-ge0c7