rspec-httpd 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rspec/httpd.rb +1 -0
- data/lib/rspec/httpd/server.rb +13 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df631d1591425ab8d6221ecdf8d3e77c571d825a3bd42b875bf732414c171533
|
4
|
+
data.tar.gz: 1443d91ac725578992ba6506cf3cfca8b0c95a002e38e0a0aecbf95aab2f8593
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dd5412f5b2acb94b439b7fb40874deb8add05673056e52022551b12ff53733913fcdfc8ffd43e1cc3d9db107f2786730f550090b39fc9db2afaf9fa3219283e
|
7
|
+
data.tar.gz: a4209b8cfedbbbd80d0d7eae762753718ce9d20431f889b955cae48abadabc5cf09892555cde3b5b7c70a942a14767e6ed93204906fa6a7b6be2e1aa8e88959a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.7
|
data/lib/rspec/httpd.rb
CHANGED
data/lib/rspec/httpd/server.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# rubocop:disable Lint/HandleExceptions
|
2
2
|
# rubocop:disable Metrics/AbcSize
|
3
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
4
|
-
# rubocop:disable Metrics/MethodLength
|
5
3
|
|
6
4
|
require "socket"
|
7
5
|
require "timeout"
|
@@ -70,35 +68,32 @@ module RSpec::Httpd
|
|
70
68
|
pid = spawn(command, pgroup: true)
|
71
69
|
pgid = Process.getpgid(pid)
|
72
70
|
|
71
|
+
# Install an at_exit handler. This will kill the server. The command
|
72
|
+
# argument is passed in for logging only.
|
73
73
|
at_exit do
|
74
|
-
|
75
|
-
|
76
|
-
Process.kill("TERM", -pgid)
|
77
|
-
sleep 0.2
|
78
|
-
rescue Errno::ESRCH
|
79
|
-
end
|
80
|
-
|
81
|
-
if port_open?(host, port)
|
82
|
-
begin
|
83
|
-
logger.debug "Killing server in pgid #{pgid}: #{command}"
|
84
|
-
Process.kill("KILL", -pgid)
|
85
|
-
rescue Errno::ESRCH, Errno::EPERM
|
86
|
-
end
|
87
|
-
end
|
74
|
+
kill_server "TERM", pgid, command: command, sleep: 0.2 if port_open?(host, port)
|
75
|
+
kill_server "KILL", pgid, command: command, sleep: 0.2 if port_open?(host, port)
|
88
76
|
|
89
77
|
logger.warn "Cannot stop server at pid #{pid}: #{command}" if port_open?(host, port)
|
90
|
-
exit 0
|
91
78
|
end
|
92
79
|
|
93
80
|
unless wait_for_server(host: host, port: port, pid: pid, timeout: MAX_STARTUP_TIME)
|
94
81
|
logger.error "server didn't start at http://#{host}:#{port} pid #{pid}: #{command}"
|
95
|
-
exit 1
|
82
|
+
exit! 1
|
96
83
|
end
|
97
84
|
|
98
85
|
logger.info "Started server at pid #{pid}: #{command}"
|
99
86
|
pid
|
100
87
|
end
|
101
88
|
|
89
|
+
def kill_server(signal, pgid, command:, sleep: nil)
|
90
|
+
logger.debug "Kill server in pgid #{pgid} w/#{signal}: #{command}"
|
91
|
+
|
92
|
+
Process.kill(signal, -pgid)
|
93
|
+
Kernel.sleep(sleep) if sleep
|
94
|
+
rescue Errno::ESRCH, Errno::EPERM
|
95
|
+
end
|
96
|
+
|
102
97
|
def wait_for_server(host:, port:, pid: nil, timeout:)
|
103
98
|
while timeout > 0
|
104
99
|
sleep 0.1
|