cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob 261c7e3e06f90b0352afee613e186039b684b6b1 1605 bytes (raw)
$ git show HEAD:test/test_helper.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
 
# -*- encoding: binary -*-
# Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
ARGV << "-v"
require 'test/unit'
require 'tmpdir'
require 'tempfile'
require 'socket'
require 'fileutils'
$stderr.sync = $stdout.sync = Thread.abort_on_exception = true

# use absolute path for TMPDIR to make our chdir tests happy with valgrind
if tmpdir = ENV["TMPDIR"]
  if tmpdir[0] != ?/
    ENV["TMPDIR"] = File.expand_path(tmpdir)
  end
end


TEST_HOST = ENV["TEST_HOST"] ||
            (RUBY_PLATFORM =~ /linux/ ?
             "127.#{rand(256)}.#{rand(256)}.#{rand(256)}" : "127.0.0.1")

TEST_HOST6 = ENV["TEST_HOST6"] || "::1"

# expand relative paths, --daemonize chdirs
path = ENV["PATH"].split(/:/)
ENV["PATH"] = path.map { |x| File.expand_path(x) }.join(":")

EPOCH = "Thu, 01 Jan 1970 00:00:00 GMT"

def replace_dates!(header)
  rv = header.gsub!(/: \w{3}, \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2} GMT\r\n/,
                    ": #{EPOCH}\r\n")
  assert(rv, header)
end

def t_yield
  100000.times { Thread.pass }
  sleep(ENV["VALGRIND"] ? 0.05 : 0.015)
  100000.times { Thread.pass }
end

def get_client(tries = 300, port = @port)
  begin
    c = TCPSocket.new(@host, port)
    @to_close << c
    c.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
    return c
  rescue
    if (tries-=1) > 0
      t_yield
    else
      warn "get_client Failed on #@host #{port}"
      raise
    end
  end while true
end

def new_req(meth, path)
  r = Net::HTTP.const_get(meth).new(path)
  r.content_type = "application/octet-stream"
  r
end

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