rack-test_server 0.1.1 → 0.1.2
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: 7e0d36980685d649c8b4b1547458738f03bc93a377c7e483f130479b1b556880
|
4
|
+
data.tar.gz: adc7ecf7fa02c7d271c5774639e3883ab2f3577534ed43bc7b5383a846892c6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca07045ceff260480aa0c69f4677166a58a52e721206576a0f9df2726d220bca98af000e909234a2a7c2dbc4f15daefb0167b0476a882b2a021be3a6d04f974e
|
7
|
+
data.tar.gz: c344a1000b89d32b474f655bfa8d1595bb2b7bfc1c5b64112f35c17ceeb637ce80ed732d47ba319d29e1b2dccd4fe3f2a63c7bf161ef35ccff59529954612940
|
@@ -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 NameError
|
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.
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-30 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
|