cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob fc2c592221795115782f64c5b9b9aa3fa872224a 1849 bytes (raw)
$ git show malloc:test/mgmt_persist_client.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
#!/usr/bin/env ruby
# -*- encoding: binary -*-
require 'test/test_helper'
require 'net/http'

class TestMgmtPersistClient < Test::Unit::TestCase
  def setup
    @tmpdir = Dir.mktmpdir('mgmt-persist-client-test')
    @host = TEST_HOST

    srv = TCPServer.new(@host, 0)
    @port = srv.addr[1]
    srv.close

    srv = TCPServer.new(@host, 0)
    @httpport = srv.addr[1]
    srv.close

    @pid = nil
    @to_close = []
    @err = Tempfile.new("stderr")
    Dir.mkdir("#@tmpdir/dev666")
    cmd = [ "cmogstored", "--docroot=#@tmpdir", "--mgmtlisten=#@host:#@port",
            "--httplisten=#@host:#@httpport",
            "--maxconns=500" ]
    vg = ENV["VALGRIND"] and cmd = vg.split(/\s+/).concat(cmd)
    @pid = fork {
      $stderr.reopen(@err)
      @err.close
      exec(*cmd)
    }
    @client = get_client
  end

  def test_persist_toggle
    {
      "off" => "on",
      "false" => "true",
      "0" => "1",
      "no" => "yes",
    }.each do |f,t|
      @client.write "SET mogstored.persist_client = #{f}\r\n"
      assert_equal "\r\n", @client.gets
      Net::HTTP.start(@host, @httpport) do |http|
        resp = http.request(Net::HTTP::Head.new('/'))
        assert_kind_of Net::HTTPOK, resp
        assert_equal "close", resp["Connection"]
      end

      @client.write "SET mogstored.persist_client = #{t}\r\n"
      assert_equal "\r\n", @client.gets
      Net::HTTP.start(@host, @httpport) do |http|
        resp = http.request(Net::HTTP::Head.new('/'))
        assert_kind_of Net::HTTPOK, resp
        assert_equal "keep-alive", resp["Connection"]
      end
    end
  end

  def teardown
    @to_close.each { |io| io.close unless io.closed? }
    FileUtils.rm_rf(@tmpdir)
    if @pid
      Process.kill(:QUIT, @pid) rescue nil
      _, status = Process.waitpid2(@pid)
      assert status.success?, status.inspect
    end
  end
end

git clone https://yhbt.net/cmogstored.git