about summary refs log tree commit homepage
path: root/t/bin
diff options
context:
space:
mode:
Diffstat (limited to 't/bin')
-rwxr-xr-xt/bin/content-md5-put36
-rwxr-xr-xt/bin/sha1sum.rb23
-rwxr-xr-xt/bin/unused_listen40
-rwxr-xr-xt/bin/utee12
4 files changed, 111 insertions, 0 deletions
diff --git a/t/bin/content-md5-put b/t/bin/content-md5-put
new file mode 100755
index 0000000..01da0bb
--- /dev/null
+++ b/t/bin/content-md5-put
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby
+# -*- encoding: binary -*-
+# simple chunked HTTP PUT request generator (and just that),
+# it reads stdin and writes to stdout so socat can write to a
+# UNIX or TCP socket (or to another filter or file) along with
+# a Content-MD5 trailer.
+require 'digest/md5'
+$stdout.sync = $stderr.sync = true
+$stdout.binmode
+$stdin.binmode
+
+bs = ENV['bs'] ? ENV['bs'].to_i : 4096
+
+if ARGV.grep("--no-headers").empty?
+  $stdout.write(
+      "PUT / HTTP/1.1\r\n" \
+      "Host: example.com\r\n" \
+      "Transfer-Encoding: chunked\r\n" \
+      "Trailer: Content-MD5\r\n" \
+      "\r\n"
+    )
+end
+
+digest = Digest::MD5.new
+if buf = $stdin.readpartial(bs)
+  begin
+    digest.update(buf)
+    $stdout.write("%x\r\n" % [ buf.size ])
+    $stdout.write(buf)
+    $stdout.write("\r\n")
+  end while $stdin.read(bs, buf)
+end
+
+digest = [ digest.digest ].pack('m').strip
+$stdout.write("0\r\n")
+$stdout.write("Content-MD5: #{digest}\r\n\r\n")
diff --git a/t/bin/sha1sum.rb b/t/bin/sha1sum.rb
new file mode 100755
index 0000000..b602e79
--- /dev/null
+++ b/t/bin/sha1sum.rb
@@ -0,0 +1,23 @@
+#!/usr/bin/env ruby
+# -*- encoding: binary -*-
+
+# Reads from stdin and outputs the SHA1 hex digest of the input this is
+# ONLY used as a last resort, our test code will try to use sha1sum(1),
+# openssl(1), or gsha1sum(1) before falling back to using this.  We try
+# all options first because we have a strong and healthy distrust of our
+# Ruby abilities in general, and *especially* when it comes to
+# understanding (and trusting the implementation of) Ruby 1.9 encoding.
+
+require 'digest/sha1'
+$stdout.sync = $stderr.sync = true
+$stdout.binmode
+$stdin.binmode
+bs = 16384
+digest = Digest::SHA1.new
+if buf = $stdin.read(bs)
+  begin
+    digest.update(buf)
+  end while $stdin.read(bs, buf)
+end
+
+$stdout.syswrite("#{digest.hexdigest}\n")
diff --git a/t/bin/unused_listen b/t/bin/unused_listen
new file mode 100755
index 0000000..b638f54
--- /dev/null
+++ b/t/bin/unused_listen
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+# -*- encoding: binary -*-
+# this is to remain compatible with the unused_port function in the
+# Unicorn test/test_helper.rb file
+require 'socket'
+require 'tmpdir'
+
+default_port = 8080
+addr = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1'
+retries = 100
+base = 5000
+port = sock = lock_path = nil
+
+begin
+  begin
+    port = base + rand(32768 - base)
+    while port == default_port
+      port = base + rand(32768 - base)
+    end
+
+    sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
+    sock.bind(Socket.pack_sockaddr_in(port, addr))
+    sock.listen(5)
+  rescue Errno::EADDRINUSE, Errno::EACCES
+    sock.close rescue nil
+    retry if (retries -= 1) >= 0
+  end
+
+  # since we'll end up closing the random port we just got, there's a race
+  # condition could allow the random port we just chose to reselect itself
+  # when running tests in parallel with gmake.  Create a lock file while
+  # we have the port here to ensure that does not happen.
+  lock_path = "#{Dir::tmpdir}/unicorn_test.#{addr}:#{port}.lock"
+  lock = File.open(lock_path, File::WRONLY|File::CREAT|File::EXCL, 0600)
+rescue Errno::EEXIST
+  sock.close rescue nil
+  retry
+end
+sock.close rescue nil
+puts %Q(listen=#{addr}:#{port} T_RM_LIST="$T_RM_LIST #{lock_path}")
diff --git a/t/bin/utee b/t/bin/utee
new file mode 100755
index 0000000..7b61fea
--- /dev/null
+++ b/t/bin/utee
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+# -*- encoding: binary -*-
+# tee(1) as distributed on most(all?) systems is buffered in luserspace
+# this only does unbuffered writes (with line-buffered input) to make
+# test output appear in real-time
+$stdin.binmode
+$stdout.binmode
+fp = File.open(ARGV.shift, "wb")
+$stdin.each_line do |line|
+  fp.syswrite line
+  $stdout.syswrite line
+end