rack-test_server 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 653b29f266cfb099925a570ce646dda069edb77aaf015c29c632621fdcc7a59e
|
4
|
+
data.tar.gz: 3a5d8d458454ebc735346f9718e2629371474138d5f9b99e591bc3729ec5a574
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e185fe7663d9d12870dff5497fbc6cf4642e8ea8c5aec36a003040ea4525bfb45955cdad72eb47935cb78af3f4fc2bcc0ad651e5130cc3e6ecf240dda9e6d4de
|
7
|
+
data.tar.gz: a95c03aa4ff2f15af918b778cc97e38b62c47065076fb391344b862a9753719e2a413f7738681817ebd6c224ae8be58ec2a887031b20e6a01d919cdb5b2783c9
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative './signal_trap_interceptor'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class TestServer
|
5
|
+
module PumaSignalTrapInterceptor
|
6
|
+
def setup_signals
|
7
|
+
# Disable SIGINT handler in Puma.
|
8
|
+
# https://github.com/puma/puma/blob/v5.5.0/lib/puma/launcher.rb#L485
|
9
|
+
SignalTrapInterceptor.enable
|
10
|
+
super
|
11
|
+
SignalTrapInterceptor.disable
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'puma'
|
19
|
+
Puma::Launcher.prepend(Rack::TestServer::PumaSignalTrapInterceptor)
|
20
|
+
rescue LoadError
|
21
|
+
# Just ignore if Puma is absent.
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rack
|
2
|
+
class TestServer
|
3
|
+
module SignalTrapInterceptor
|
4
|
+
class << self
|
5
|
+
def enable
|
6
|
+
define_method(:trap) do |sig, &handler|
|
7
|
+
if sig == :INT || sig == 'SIGINT'
|
8
|
+
puts "[NOTE] `trap(#{sig})` is ignored called from #{caller_locations.first}"
|
9
|
+
else
|
10
|
+
super(sig, &handler)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def disable
|
16
|
+
remove_method(:trap)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rack/server'
|
24
|
+
|
25
|
+
# Disable SIGINT handler in Rack::Server.
|
26
|
+
# https://github.com/rack/rack/blob/2.2.3/lib/rack/server.rb#L319
|
27
|
+
Rack::Server.prepend(Rack::TestServer::SignalTrapInterceptor)
|
28
|
+
|
29
|
+
# Mainly inteded to disable SIGINT handler in Puma.
|
30
|
+
# https://github.com/puma/puma/blob/v5.5.0/lib/puma/launcher.rb#L485
|
31
|
+
Signal.singleton_class.prepend(Rack::TestServer::SignalTrapInterceptor)
|
data/lib/rack/test_server.rb
CHANGED
@@ -4,6 +4,8 @@ require 'net/http'
|
|
4
4
|
require 'rack'
|
5
5
|
require 'timeout'
|
6
6
|
require 'rack/test_server/version'
|
7
|
+
require 'rack/test_server/puma_signal_trap_interceptor'
|
8
|
+
require 'rack/test_server/signal_trap_interceptor'
|
7
9
|
|
8
10
|
module Rack
|
9
11
|
# An utility class for launching HTTP server with Rack::Server#start
|
@@ -44,7 +46,12 @@ module Rack
|
|
44
46
|
#
|
45
47
|
# @note This method will block the thread, and in most cases {#start_async} is suitable.
|
46
48
|
def start
|
49
|
+
# Disable SIGINT handler in Rack::Server.
|
50
|
+
# https://github.com/rack/rack/blob/2.2.3/lib/rack/server.rb#L319
|
51
|
+
SignalTrapInterceptor.enable
|
47
52
|
@server.start do |server|
|
53
|
+
SignalTrapInterceptor.disable
|
54
|
+
|
48
55
|
# server can be a Puma::Launcher, Webrick::Server, Thin::Server
|
49
56
|
# They all happen to have 'stop' method for greaceful shutdown.
|
50
57
|
# Remember the method as Proc here for stopping server manually.
|
@@ -76,11 +83,7 @@ module Rack
|
|
76
83
|
def ready?
|
77
84
|
Net::HTTP.get(URI("#{base_url}/__ping"))
|
78
85
|
true
|
79
|
-
rescue Errno::EADDRNOTAVAIL
|
80
|
-
false
|
81
|
-
rescue Errno::ECONNREFUSED
|
82
|
-
false
|
83
|
-
rescue Errno::EINVAL
|
86
|
+
rescue Errno::EADDRNOTAVAIL, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EINVAL
|
84
87
|
false
|
85
88
|
end
|
86
89
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-test_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -124,6 +124,8 @@ files:
|
|
124
124
|
- bin/console
|
125
125
|
- bin/setup
|
126
126
|
- lib/rack/test_server.rb
|
127
|
+
- lib/rack/test_server/puma_signal_trap_interceptor.rb
|
128
|
+
- lib/rack/test_server/signal_trap_interceptor.rb
|
127
129
|
- lib/rack/test_server/version.rb
|
128
130
|
- rack-test_server.gemspec
|
129
131
|
homepage: https://github.com/YusukeIwaki/rack-test_server
|