mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
tmp_path
This commit is contained in:
parent
a72c68b350
commit
394c28f23f
8 changed files with 44 additions and 44 deletions
|
@ -44,6 +44,13 @@ def hit(uris)
|
|||
end
|
||||
end
|
||||
|
||||
def tmp_path(extension=nil)
|
||||
sock_file = Tempfile.new(['', extension])
|
||||
path = sock_file.path
|
||||
sock_file.close!
|
||||
path
|
||||
end
|
||||
|
||||
module UniquePort
|
||||
def self.call
|
||||
TCPServer.open('127.0.0.1', 0) do |server|
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
require "puma/control_cli"
|
||||
require "open3"
|
||||
#require_relative "../helper"
|
||||
|
||||
# Only single mode tests go here. Cluster and pumactl tests
|
||||
# have their own files, use those instead
|
||||
|
@ -15,7 +16,7 @@ class TestIntegration < Minitest::Test
|
|||
|
||||
def setup
|
||||
@ios_to_close = []
|
||||
@bind_path = "test/#{name}_server.sock"
|
||||
@bind_path = tmp_path('.sock')
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
|
|
@ -123,8 +123,8 @@ class TestBinder < TestBinderBase
|
|||
|
||||
def test_pre_existing_unix
|
||||
skip UNIX_SKT_MSG unless UNIX_SKT_EXIST
|
||||
unix_path = "test/#{name}_server.sock"
|
||||
|
||||
unix_path = tmp_path('.sock')
|
||||
File.open(unix_path, mode: 'wb') { |f| f.puts 'pre existing' }
|
||||
@binder.parse ["unix://#{unix_path}"], @events
|
||||
|
||||
|
@ -248,13 +248,12 @@ class TestBinder < TestBinderBase
|
|||
def test_listeners_file_unlink_if_unix_listener
|
||||
skip UNIX_SKT_MSG unless UNIX_SKT_EXIST
|
||||
|
||||
@binder.parse ["unix://test/#{name}_server.sock"], @events
|
||||
|
||||
assert File.socket?("test/#{name}_server.sock")
|
||||
unix_path = tmp_path('.sock')
|
||||
@binder.parse ["unix://#{unix_path}"], @events
|
||||
assert File.socket?(unix_path)
|
||||
|
||||
@binder.close_listeners
|
||||
|
||||
refute File.socket?("test/#{name}_server.sock")
|
||||
refute File.socket?(unix_path)
|
||||
end
|
||||
|
||||
def test_import_from_env_listen_inherit
|
||||
|
@ -289,11 +288,12 @@ class TestBinder < TestBinderBase
|
|||
def test_socket_activation_unix
|
||||
skip_on :jruby # Failing with what I think is a JRuby bug
|
||||
skip UNIX_SKT_MSG unless UNIX_SKT_EXIST
|
||||
path = "test/unixserver.state"
|
||||
sock = Addrinfo.unix(path).listen
|
||||
assert_activates_sockets(path: path, sock: sock)
|
||||
|
||||
state_path = tmp_path('.state')
|
||||
sock = Addrinfo.unix(state_path).listen
|
||||
assert_activates_sockets(path: state_path, sock: sock)
|
||||
ensure
|
||||
File.unlink(path) rescue nil # JRuby race?
|
||||
File.unlink(state_path) rescue nil # JRuby race?
|
||||
end
|
||||
|
||||
def test_rack_multithread_default_configuration
|
||||
|
@ -345,10 +345,11 @@ class TestBinder < TestBinderBase
|
|||
def assert_parsing_logs_uri(order = [:unix, :tcp])
|
||||
skip UNIX_SKT_MSG if order.include?(:unix) && !UNIX_SKT_EXIST
|
||||
|
||||
unix_path = tmp_path('.sock')
|
||||
prepared_paths = {
|
||||
ssl: "ssl://127.0.0.1:#{UniquePort.call}?#{ssl_query}",
|
||||
tcp: "tcp://127.0.0.1:#{UniquePort.call}",
|
||||
unix: "unix://test/#{name}_server.sock"
|
||||
unix: "unix://#{unix_path}"
|
||||
}
|
||||
|
||||
tested_paths = [prepared_paths[order[0]], prepared_paths[order[1]]]
|
||||
|
|
|
@ -9,10 +9,8 @@ class TestCLI < Minitest::Test
|
|||
|
||||
def setup
|
||||
@environment = 'production'
|
||||
@tmp_file = Tempfile.new("puma-test")
|
||||
@tmp_path = @tmp_file.path
|
||||
@tmp_file.close!
|
||||
|
||||
@tmp_path = tmp_path('puma-test')
|
||||
@tmp_path2 = "#{@tmp_path}2"
|
||||
|
||||
File.unlink @tmp_path if File.exist? @tmp_path
|
||||
|
|
|
@ -7,8 +7,8 @@ class TestIntegrationPumactl < TestIntegration
|
|||
def setup
|
||||
super
|
||||
|
||||
@state_path = "test/#{name}_puma.state"
|
||||
@control_path = "test/#{name}_control.sock"
|
||||
@state_path = tmp_path('.state')
|
||||
@control_path = tmp_path('.sock')
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
|
|
@ -64,70 +64,62 @@ class TestLauncher < Minitest::Test
|
|||
end
|
||||
|
||||
def test_pid_file
|
||||
tmp_file = Tempfile.new("puma-test")
|
||||
tmp_path = tmp_file.path
|
||||
tmp_file.close!
|
||||
pid_path = tmp_path('.pid')
|
||||
|
||||
conf = Puma::Configuration.new do |c|
|
||||
c.pidfile tmp_path
|
||||
c.pidfile pid_path
|
||||
end
|
||||
|
||||
launcher(conf).write_state
|
||||
|
||||
assert_equal File.read(tmp_path).strip.to_i, Process.pid
|
||||
assert_equal File.read(pid_path).strip.to_i, Process.pid
|
||||
|
||||
File.unlink tmp_path
|
||||
File.unlink pid_path
|
||||
end
|
||||
|
||||
def test_state_permission_0640
|
||||
tmp_file = Tempfile.new("puma-test")
|
||||
tmp_path = tmp_file.path
|
||||
tmp_file.close!
|
||||
tmp_permission = 0640
|
||||
state_path = tmp_path('.state')
|
||||
state_permission = 0640
|
||||
|
||||
conf = Puma::Configuration.new do |c|
|
||||
c.state_path tmp_path
|
||||
c.state_permission tmp_permission
|
||||
c.state_path state_path
|
||||
c.state_permission state_permission
|
||||
end
|
||||
|
||||
launcher(conf).write_state
|
||||
|
||||
assert File.stat(tmp_path).mode.to_s(8)[-4..-1], tmp_permission
|
||||
assert File.stat(state_path).mode.to_s(8)[-4..-1], state_permission
|
||||
ensure
|
||||
File.unlink tmp_path
|
||||
File.unlink state_path
|
||||
end
|
||||
|
||||
def test_state_permission_nil
|
||||
tmp_file = Tempfile.new("puma-test")
|
||||
tmp_path = tmp_file.path
|
||||
tmp_file.close!
|
||||
state_path = tmp_path('.state')
|
||||
|
||||
conf = Puma::Configuration.new do |c|
|
||||
c.state_path tmp_path
|
||||
c.state_path state_path
|
||||
c.state_permission nil
|
||||
end
|
||||
|
||||
launcher(conf).write_state
|
||||
|
||||
assert File.exist?(tmp_path)
|
||||
assert File.exist?(state_path)
|
||||
ensure
|
||||
File.unlink tmp_path
|
||||
File.unlink state_path
|
||||
end
|
||||
|
||||
def test_no_state_permission
|
||||
tmp_file = Tempfile.new("puma-test")
|
||||
tmp_path = tmp_file.path
|
||||
tmp_file.close!
|
||||
state_path = tmp_path('.state')
|
||||
|
||||
conf = Puma::Configuration.new do |c|
|
||||
c.state_path tmp_path
|
||||
c.state_path state_path
|
||||
end
|
||||
|
||||
launcher(conf).write_state
|
||||
|
||||
assert File.exist?(tmp_path)
|
||||
assert File.exist?(state_path)
|
||||
ensure
|
||||
File.unlink tmp_path
|
||||
File.unlink state_path
|
||||
end
|
||||
|
||||
def test_puma_stats
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
require_relative "helper"
|
||||
require "net/http"
|
||||
|
||||
require "rack"
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class TestPumaUnixSocket < Minitest::Test
|
|||
|
||||
App = lambda { |env| [200, {}, ["Works"]] }
|
||||
|
||||
PATH = "test/puma.sock"
|
||||
PATH = tmp_path('.sock')
|
||||
|
||||
def setup
|
||||
return unless UNIX_SKT_EXIST
|
||||
|
|
Loading…
Reference in a new issue