Sha256: 7b317f7f0e86b480f1b997bede92395e23bf687629ee08c3e1f6a15b24e1ab4b

Contents?: true

Size: 1.22 KB

Versions: 206

Compression:

Stored size: 1.22 KB

Contents

#!/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}")

Version data entries

206 entries across 206 versions & 16 rubygems

Version Path
unicorn-maintained-6.2.0 t/bin/unused_listen
unicorn-6.1.0 t/bin/unused_listen
unicorn-6.0.0 t/bin/unused_listen
unicorn-5.8.0 t/bin/unused_listen
unicorn-5.7.0 t/bin/unused_listen
unicorn-5.6.0 t/bin/unused_listen
unicorn-5.5.5 t/bin/unused_listen
unicorn-5.5.4 t/bin/unused_listen
regurgitator-0.9.1 t/bin/unused_listen
unicorn-5.5.3 t/bin/unused_listen
unicorn-5.5.2 t/bin/unused_listen
unicorn-5.5.1 t/bin/unused_listen
unicorn-5.5.0.1.g6836 t/bin/unused_listen
unicorn-5.5.0 t/bin/unused_listen
unicorn-5.5.0.pre1 t/bin/unused_listen
unicorn-5.4.1 t/bin/unused_listen
unicorn-5.4.0 t/bin/unused_listen
unicorn-5.3.1 t/bin/unused_listen
regurgitator-0.9.0 t/bin/unused_listen
unicorn-shopify-5.3.0 t/bin/unused_listen