Ruby mogilefs-client dev/users discussion/patches/bugs/help/...
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: mogilefs-client-public@bogomips.org
Subject: [PATCH] test: switch to cmogstored for testing Content-Range PUTs
Date: Thu, 26 Jan 2017 23:32:46 +0000	[thread overview]
Message-ID: <20170126233246.30316-1-e@80x24.org> (raw)

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.
---
 test/fresh.rb                                      |  8 ++-
 .../{test_mogstored_rack.rb => test_cmogstored.rb} | 71 +++++-----------------
 2 files changed, 19 insertions(+), 60 deletions(-)
 rename test/{test_mogstored_rack.rb => test_cmogstored.rb} (74%)

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 @@ def setup_mogilefs(plugins = nil)
     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 @@ def add_host_device_domain
 
   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
similarity index 74%
rename from test/test_mogstored_rack.rb
rename to test/test_cmogstored.rb
index de27c53..6c5f2f6 100644
--- a/test/test_mogstored_rack.rb
+++ b/test/test_cmogstored.rb
@@ -1,12 +1,5 @@
 # -*- encoding: binary -*-
 require "./test/fresh"
-begin
-  require 'mogstored_rack'
-  require 'unicorn'
-  ok = true
-rescue LoadError
-  ok = false
-end
 
 class TestMogstoredRack < Test::Unit::TestCase
   include TestFreshSetup
@@ -136,60 +129,24 @@ def setup_mogstored
     @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
-- 
EW


                 reply	other threads:[~2017-01-26 23:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/mogilefs-client/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170126233246.30316-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=mogilefs-client-public@bogomips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/mogilefs-client.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).