From 394c28f23fbfcdaa885930ce557a19e53a5f3ce0 Mon Sep 17 00:00:00 2001 From: Vyacheslav Alexeev Date: Mon, 6 Jul 2020 15:10:55 +0300 Subject: [PATCH] tmp_path --- test/helper.rb | 7 +++++ test/helpers/integration.rb | 3 ++- test/test_binder.rb | 23 +++++++++-------- test/test_cli.rb | 4 +-- test/test_integration_pumactl.rb | 4 +-- test/test_launcher.rb | 44 +++++++++++++------------------- test/test_rack_server.rb | 1 + test/test_unix_socket.rb | 2 +- 8 files changed, 44 insertions(+), 44 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index 47240707..28ca392e 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -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| diff --git a/test/helpers/integration.rb b/test/helpers/integration.rb index 7234df7f..4f3e3063 100644 --- a/test/helpers/integration.rb +++ b/test/helpers/integration.rb @@ -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 diff --git a/test/test_binder.rb b/test/test_binder.rb index 8341c586..a21051c0 100644 --- a/test/test_binder.rb +++ b/test/test_binder.rb @@ -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]]] diff --git a/test/test_cli.rb b/test/test_cli.rb index a2c39a55..bdb43f9d 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -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 diff --git a/test/test_integration_pumactl.rb b/test/test_integration_pumactl.rb index 98557570..1fe5fa9d 100644 --- a/test/test_integration_pumactl.rb +++ b/test/test_integration_pumactl.rb @@ -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 diff --git a/test/test_launcher.rb b/test/test_launcher.rb index 39fb7ab8..1a4de12f 100644 --- a/test/test_launcher.rb +++ b/test/test_launcher.rb @@ -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 diff --git a/test/test_rack_server.rb b/test/test_rack_server.rb index f7d2a683..369f41f8 100644 --- a/test/test_rack_server.rb +++ b/test/test_rack_server.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true require_relative "helper" +require "net/http" require "rack" diff --git a/test/test_unix_socket.rb b/test/test_unix_socket.rb index eb689005..8f35ae5b 100644 --- a/test/test_unix_socket.rb +++ b/test/test_unix_socket.rb @@ -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