From f593504584288fa9b0a434d8c87feb8e89041f29 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 20 Oct 2013 00:31:35 +0000 Subject: test_config: isolate directories with logs Otherwise, this is racy when we have the reopen logs tests running in the same process. We can't workaround this in the process reopening logs (by ignoring ENOENT) since recreating the file can also race with the FileUtils.rm_rf. --- test/test_config.rb | 72 +++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 33 deletions(-) (limited to 'test/test_config.rb') diff --git a/test/test_config.rb b/test/test_config.rb index 2afcecb..2f87136 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -12,45 +12,51 @@ class TestConfig < Testcase end def test_multi_conf_example - tmpdir = Dir.mktmpdir + pid = fork do + tmpdir = Dir.mktmpdir - # modify the example config file for testing - path = "examples/yahns_multi.conf.rb" - cfgs = File.read(path) - cfgs.gsub!(%r{/path/to/}, "#{tmpdir}/") - conf = File.open("#{tmpdir}/yahns_multi.conf.rb", "w") - conf.sync = true - conf.write(cfgs) - File.open("#{tmpdir}/another.ru", "w") do |fp| - fp.puts("run Rack::Lobster.new\n") - end - FileUtils.mkpath("#{tmpdir}/another") + # modify the example config file for testing + path = "examples/yahns_multi.conf.rb" + cfgs = File.read(path) + cfgs.gsub!(%r{/path/to/}, "#{tmpdir}/") + conf = File.open("#{tmpdir}/yahns_multi.conf.rb", "w") + conf.sync = true + conf.write(cfgs) + File.open("#{tmpdir}/another.ru", "w") do |fp| + fp.puts("run Rack::Lobster.new\n") + end + FileUtils.mkpath("#{tmpdir}/another") - cfg = GTL.synchronize { Yahns::Config.new(conf.path) } - assert_instance_of Yahns::Config, cfg - ensure - FileUtils.rm_rf(tmpdir) if tmpdir + cfg = Yahns::Config.new(conf.path) + FileUtils.rm_rf(tmpdir) + exit!(Yahns::Config === cfg) + end + _, status = Process.waitpid2(pid) + assert status.success? end def test_rack_basic_conf_example - tmpdir = Dir.mktmpdir + pid = fork do + tmpdir = Dir.mktmpdir - # modify the example config file for testing - path = "examples/yahns_rack_basic.conf.rb" - cfgs = File.read(path) - cfgs.gsub!(%r{/path/to/}, "#{tmpdir}/") - Dir.mkdir("#{tmpdir}/my_app") - Dir.mkdir("#{tmpdir}/my_logs") - Dir.mkdir("#{tmpdir}/my_pids") - conf = File.open("#{tmpdir}/yahns_rack_basic.conf.rb", "w") - conf.sync = true - conf.write(cfgs) - File.open("#{tmpdir}/my_app/config.ru", "w") do |fp| - fp.puts("run Rack::Lobster.new\n") + # modify the example config file for testing + path = "examples/yahns_rack_basic.conf.rb" + cfgs = File.read(path) + cfgs.gsub!(%r{/path/to/}, "#{tmpdir}/") + Dir.mkdir("#{tmpdir}/my_app") + Dir.mkdir("#{tmpdir}/my_logs") + Dir.mkdir("#{tmpdir}/my_pids") + conf = File.open("#{tmpdir}/yahns_rack_basic.conf.rb", "w") + conf.sync = true + conf.write(cfgs) + File.open("#{tmpdir}/my_app/config.ru", "w") do |fp| + fp.puts("run Rack::Lobster.new\n") + end + cfg = Yahns::Config.new(conf.path) + FileUtils.rm_rf(tmpdir) if tmpdir + exit!(Yahns::Config === cfg) end - cfg = GTL.synchronize { Yahns::Config.new(conf.path) } - assert_instance_of Yahns::Config, cfg - ensure - FileUtils.rm_rf(tmpdir) if tmpdir + _, status = Process.waitpid2(pid) + assert status.success? end end -- cgit v1.2.3-24-ge0c7