about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-26 23:24:20 +0000
committerEric Wong <e@80x24.org>2017-01-27 03:41:16 +0000
commitdd53d097384154b9d2d100a9079f4dbf681a0925 (patch)
tree8e7894003315ebcc4f5aa9edcc5a118dfe79eb05
parentd080b456e129e2ebffdcdbfb601895b4c93dc1e4 (diff)
downloadmogilefs-client-dd53d097384154b9d2d100a9079f4dbf681a0925.tar.gz
mogstored_rack is long abandoned since I decided to work on
cmogstored (in C, not Ruby :) instead.
We still need this test since the original Perl mogstored
does not yet support Content-Range: in PUT requests.
-rw-r--r--test/fresh.rb8
-rw-r--r--test/test_cmogstored.rb (renamed from test/test_mogstored_rack.rb)85
2 files changed, 24 insertions, 69 deletions
diff --git a/test/fresh.rb b/test/fresh.rb
index 4c53ac2..972f834 100644
--- a/test/fresh.rb
+++ b/test/fresh.rb
@@ -42,7 +42,7 @@ EOF
     50.times do
       break if File.size(@mogstored_pid.path) > 0
       sleep 0.1
-    end
+    end unless Integer === @mogstored_pid
   end
 
   def start_tracker
@@ -108,10 +108,12 @@ EOF
 
   def teardown_mogilefs
     return if $$ != @teardown_pid
-    if @mogstored_pid
+    if Integer === @mogstored_pid
+      pid = @mogstored_pid
+    else
       pid = File.read(@mogstored_pid.path).to_i
-      Process.kill(:TERM, pid) if pid > 0
     end
+    Process.kill(:TERM, pid) if pid > 0
     if @mogilefsd_pid
       s = TCPSocket.new(@test_host, @tracker_port)
       s.write "!shutdown\r\n"
diff --git a/test/test_mogstored_rack.rb b/test/test_cmogstored.rb
index de27c53..586000b 100644
--- a/test/test_mogstored_rack.rb
+++ b/test/test_cmogstored.rb
@@ -1,18 +1,11 @@
 # -*- encoding: binary -*-
 require "./test/fresh"
-begin
-  require 'mogstored_rack'
-  require 'unicorn'
-  ok = true
-rescue LoadError
-  ok = false
-end
-
-class TestMogstoredRack < Test::Unit::TestCase
+
+# cmogstored allows Content-Range on PUT, unlike the original mogstored
+class Test_cmogstored < Test::Unit::TestCase
   include TestFreshSetup
-  def setup
-    setup_mogilefs
-  end
+  alias setup setup_mogilefs
+  alias teardown teardown_mogilefs
 
   def test_range_put_new_file
     add_host_device_domain
@@ -136,60 +129,20 @@ class TestMogstoredRack < Test::Unit::TestCase
     @mogstored_http = TCPServer.new(@test_host, 0)
     @mogstored_mgmt_port = @mogstored_mgmt.addr[1]
     @mogstored_http_port = @mogstored_http.addr[1]
-    @mogstored_conf = Tempfile.new(["mogstored", "conf"])
-    @mogstored_pid = Tempfile.new(["mogstored", "pid"])
-    @mogstored_conf.write <<EOF
-pidfile = #{@mogstored_pid.path}
-maxconns = 1000
-mgmtlisten = #@test_host:#{@mogstored_mgmt_port}
-server = none
-docroot = #@docroot
-EOF
-    @mogstored_conf.flush
-    @mogstored_mgmt.close
-
-    unicorn_setup
-
-    x!("mogstored", "--daemon", "--config=#{@mogstored_conf.path}")
-    wait_for_port @mogstored_mgmt_port
-  end
 
-  # I would use Rainbows! + *Threads + Ruby 1.9.3 in production
-  def unicorn_setup
-    @ru = Tempfile.new(%w(mogstored_rack .ru))
-    @ru.write <<EOF
-run MogstoredRack.new("#@docroot")
-EOF
-    @ru.flush
-
-    @unicorn_pid = Tempfile.new(%w(unicorn .pid))
-    @unicorn_conf = Tempfile.new(%w(unicorn.conf .rb))
-    @unicorn_stderr = Tempfile.new(%w(unicorn .stderr))
-    @unicorn_stdout = Tempfile.new(%w(unicorn .stdout))
-    @unicorn_conf.write <<EOF
-require "mogstored_rack"
-listen "#@test_host:#{@mogstored_http_port}"
-pid "#{@unicorn_pid.path}"
-stderr_path "#{@unicorn_stderr.path}"
-stdout_path "#{@unicorn_stdout.path}"
-rewindable_input false
-EOF
-    @unicorn_conf.flush
-
-    @mogstored_http.close
-    x!("unicorn", "-E", "deployment",
-       "--daemon", "--config", @unicorn_conf.path, @ru.path)
-    wait_for_port @mogstored_http_port
-    40.times do
-      break if File.size(@unicorn_pid.path) > 0
-      sleep 0.1
+    @mogstored_pid = fork do
+      mgmt_fd = @mogstored_mgmt.fileno
+      http_fd = @mogstored_http.fileno
+      args = []
+      ENV["CMOGSTORED_FD"] = "#{mgmt_fd},#{http_fd}"
+      if @mogstored_mgmt.respond_to?(:close_on_exec=)
+        @mogstored_mgmt.close_on_exec = @mogstored_http.close_on_exec = false
+        args << { mgmt_fd => mgmt_fd, http_fd => http_fd }
+      end
+      $stderr.reopen('/dev/null', 'a')
+      exec "cmogstored", "--httplisten=#@test_host:#@mogstored_http_port",
+           "--mgmtlisten=#@test_host:#@mogstored_mgmt_port",
+           "--maxconns=1000", "--docroot=#@docroot", *args
     end
   end
-
-  def teardown
-    pid = File.read(@unicorn_pid.path).to_i
-    Process.kill(:QUIT, pid) if pid > 0
-    teardown_mogilefs
-    puts(@unicorn_stderr.read) if $DEBUG
-  end
-end if ok && `which unicorn`.chomp.size > 0
+end if `which cmogstored`.chomp.size > 0