about summary refs log tree commit homepage
path: root/test/test_config.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-10-20 00:31:35 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-20 00:31:35 +0000
commitf593504584288fa9b0a434d8c87feb8e89041f29 (patch)
treebde784b6ea3bf325041216f4174d16b97c0e4927 /test/test_config.rb
parent6e07ca9107a58af6a2fd8ba534f84019fc5a1114 (diff)
downloadyahns-f593504584288fa9b0a434d8c87feb8e89041f29.tar.gz
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.
Diffstat (limited to 'test/test_config.rb')
-rw-r--r--test/test_config.rb72
1 files changed, 39 insertions, 33 deletions
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