1 # -*- encoding: binary -*-
4 class TestMogstoredRack < Test::Unit::TestCase
11 add_host_device_domain
12 client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain
13 node = "#@test_host:#@mogstored_http_port"
15 # not modifying this hash in the same process
16 MogileFS::HTTPFile::MD5_TRAILER_NODES[node] = true
17 client.store_content("md5_me", nil, "HELLO WORLD")
19 _, status = Process.waitpid2(pid)
20 assert status.success?, status.inspect
21 assert_equal "HELLO WORLD", client.get_file_data("md5_me")
25 @docroot = Dir.mktmpdir(["mogfresh", "docroot"])
26 @mogstored_mgmt = TCPServer.new(@test_host, 0)
27 @mogstored_http = TCPServer.new(@test_host, 0)
28 @mogstored_mgmt_port = @mogstored_mgmt.addr[1]
29 @mogstored_http_port = @mogstored_http.addr[1]
30 @mogstored_conf = Tempfile.new(["mogstored", "conf"])
31 @mogstored_pid = Tempfile.new(["mogstored", "pid"])
32 @mogstored_conf.write <<EOF
33 pidfile = #{@mogstored_pid.path}
35 mgmtlisten = #@test_host:#{@mogstored_mgmt_port}
44 x!("mogstored", "--daemon", "--config=#{@mogstored_conf.path}")
45 wait_for_port @mogstored_mgmt_port
48 # I would use Rainbows! + *Threads + Ruby 1.9.3 in production
50 examples_dir = Dir.pwd + "/examples"
51 assert File.directory?(examples_dir)
52 @ru = Tempfile.new(%w(mogstored_rack .ru))
54 require "mogstored_rack"
56 run MogstoredRack.new("#@docroot")
60 @unicorn_pid = Tempfile.new(%w(unicorn .pid))
61 @unicorn_conf = Tempfile.new(%w(unicorn.conf .rb))
62 @unicorn_stderr = Tempfile.new(%w(unicorn .stderr))
63 @unicorn_stdout = Tempfile.new(%w(unicorn .stdout))
64 @unicorn_conf.write <<EOF
65 listen "#@test_host:#{@mogstored_http_port}"
66 pid "#{@unicorn_pid.path}"
67 stderr_path "#{@unicorn_stderr.path}"
68 stdout_path "#{@unicorn_stdout.path}"
69 rewindable_input false
74 x!("unicorn", "-I", examples_dir, "-E", "deployment",
75 "--daemon", "--config", @unicorn_conf.path, @ru.path)
76 wait_for_port @mogstored_http_port
78 break if File.size(@unicorn_pid.path) > 0
84 pid = File.read(@unicorn_pid.path).to_i
85 Process.kill(:QUIT, pid) if pid > 0
87 puts(@unicorn_stderr.read) if $DEBUG
89 end if `which unicorn`.chomp.size > 0