1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Add tmp_path manager module

This commit is contained in:
Vyacheslav Alexeev 2020-07-12 20:00:29 +03:00
parent bd39996987
commit a7455dff86
8 changed files with 52 additions and 11 deletions

View file

@ -44,13 +44,6 @@ 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|

View file

@ -2,10 +2,12 @@
require "puma/control_cli"
require "open3"
require_relative 'tmp_path'
# Only single mode tests go here. Cluster and pumactl tests
# have their own files, use those instead
class TestIntegration < Minitest::Test
include TmpPath
HOST = "127.0.0.1"
TOKEN = "xxyyzz"
WORKERS = 2

37
test/helpers/tmp_path.rb Normal file
View file

@ -0,0 +1,37 @@
module TmpPath
def run(*args)
begin
result = super(*args)
rescue Interrupt
clean_tmp_paths
raise
end
clean_tmp_paths
result
end
private
def tmp_path(extension=nil)
sock_file = Tempfile.new(['', extension])
path = sock_file.path
sock_file.close!
tmp_paths << path
path
end
def tmp_paths
@tmp_paths ||= []
end
def clean_tmp_paths
tmp_paths.each { |path| delete_tmp_path(path) }
@tmp_paths = []
end
def delete_tmp_path(path)
File.unlink(path)
rescue Errno::ENOENT
end
end

View file

@ -2,6 +2,7 @@
require_relative "helper"
require_relative "helpers/ssl"
require_relative "helpers/tmp_path"
require "puma/binder"
require "puma/puma_http11"
@ -10,6 +11,7 @@ require "puma/configuration"
class TestBinderBase < Minitest::Test
include SSLHelper
include TmpPath
def setup
@events = Puma::Events.strings

View file

@ -1,11 +1,13 @@
require_relative "helper"
require_relative "helpers/ssl"
require_relative "helpers/tmp_path"
require "puma/cli"
require "json"
class TestCLI < Minitest::Test
include SSLHelper
include TmpPath
def setup
@environment = 'production'

View file

@ -2,6 +2,7 @@ require_relative "helper"
require_relative "helpers/integration"
class TestIntegrationPumactl < TestIntegration
include TmpPath
parallelize_me!
def setup

View file

@ -1,9 +1,12 @@
require_relative "helper"
require_relative "helpers/tmp_path"
require "puma/configuration"
require 'puma/events'
class TestLauncher < Minitest::Test
include TmpPath
def test_dependencies_and_files_to_require_after_prune_is_correctly_built_for_no_extra_deps
skip_on :no_bundler

View file

@ -1,17 +1,18 @@
# frozen_string_literal: true
require_relative "helper"
require_relative "helpers/tmp_path"
class TestPumaUnixSocket < Minitest::Test
include TmpPath
App = lambda { |env| [200, {}, ["Works"]] }
PATH = tmp_path('.sock')
def setup
return unless UNIX_SKT_EXIST
@tmp_socket_path = tmp_path('.sock')
@server = Puma::Server.new App
@server.add_unix_listener PATH
@server.add_unix_listener @tmp_socket_path
@server.run
end
@ -22,7 +23,7 @@ class TestPumaUnixSocket < Minitest::Test
def test_server
skip UNIX_SKT_MSG unless UNIX_SKT_EXIST
sock = UNIXSocket.new PATH
sock = UNIXSocket.new @tmp_socket_path
sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"