1 # -*- encoding: binary -*-
4 require 'mogstored_rack'
11 class TestMogstoredRack < Test::Unit::TestCase
12 include TestFreshSetup
18 add_host_device_domain
19 client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain
20 node = "#@test_host:#@mogstored_http_port"
22 # not modifying this hash in the same process
23 MogileFS::HTTPFile::MD5_TRAILER_NODES[node] = true
24 client.store_content("md5_me", nil, "HELLO WORLD")
26 _, status = Process.waitpid2(pid)
27 assert status.success?, status.inspect
28 assert_equal "HELLO WORLD", client.get_file_data("md5_me")
32 @docroot = Dir.mktmpdir(["mogfresh", "docroot"])
33 @mogstored_mgmt = TCPServer.new(@test_host, 0)
34 @mogstored_http = TCPServer.new(@test_host, 0)
35 @mogstored_mgmt_port = @mogstored_mgmt.addr[1]
36 @mogstored_http_port = @mogstored_http.addr[1]
37 @mogstored_conf = Tempfile.new(["mogstored", "conf"])
38 @mogstored_pid = Tempfile.new(["mogstored", "pid"])
39 @mogstored_conf.write <<EOF
40 pidfile = #{@mogstored_pid.path}
42 mgmtlisten = #@test_host:#{@mogstored_mgmt_port}
51 x!("mogstored", "--daemon", "--config=#{@mogstored_conf.path}")
52 wait_for_port @mogstored_mgmt_port
55 # I would use Rainbows! + *Threads + Ruby 1.9.3 in production
57 @ru = Tempfile.new(%w(mogstored_rack .ru))
59 run MogstoredRack.new("#@docroot")
63 @unicorn_pid = Tempfile.new(%w(unicorn .pid))
64 @unicorn_conf = Tempfile.new(%w(unicorn.conf .rb))
65 @unicorn_stderr = Tempfile.new(%w(unicorn .stderr))
66 @unicorn_stdout = Tempfile.new(%w(unicorn .stdout))
67 @unicorn_conf.write <<EOF
68 require "mogstored_rack"
69 listen "#@test_host:#{@mogstored_http_port}"
70 pid "#{@unicorn_pid.path}"
71 stderr_path "#{@unicorn_stderr.path}"
72 stdout_path "#{@unicorn_stdout.path}"
73 rewindable_input false
78 x!("unicorn", "-E", "deployment",
79 "--daemon", "--config", @unicorn_conf.path, @ru.path)
80 wait_for_port @mogstored_http_port
82 break if File.size(@unicorn_pid.path) > 0
88 pid = File.read(@unicorn_pid.path).to_i
89 Process.kill(:QUIT, pid) if pid > 0
91 puts(@unicorn_stderr.read) if $DEBUG
93 end if ok && `which unicorn`.chomp.size > 0