Repository navigation
Expand file tree
/
Copy pathclose_on_fork_test.rb
More file actions
59 lines (47 loc) · 1.78 KB
/
Copy pathclose_on_fork_test.rb
File metadata and controls
59 lines (47 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
require "oj"
require "test_helper"
class CloseOnForkTest < Minitest::Test
include HTTPHelpers
include HTTPX
def test_close_on_fork_after_fork_callback
skip("MRI feature") unless Process.respond_to?(:fork)
GC.start # cleanup instances created by other tests
http = HTTPX.plugin(SessionWithPool).with(persistent: true, close_on_fork: true)
uri = URI(build_uri("/get"))
response = http.get(uri)
verify_status(response, 200)
assert http.connections.size == 1
assert http.connections.none? { |c| c.state == :closed }, "should have no closed connections"
HTTPX::Session.after_fork
assert http.connections.size == 1
assert http.connections.one? { |c| c.state == :closed }, "should have a closed connection"
end
def test_close_on_fork_automatic_after_fork_callback
skip("MRI 3.1 feature") unless Process.respond_to?(:_fork)
GC.start # cleanup instances created by other tests
http = HTTPX.plugin(SessionWithPool).with(persistent: true, close_on_fork: true)
uri = URI(build_uri("/get"))
response = http.get(uri)
verify_status(response, 200)
assert http.connections.size == 1
assert http.connections.none? { |c| c.state == :closed }, "should have no closed connections"
pid = fork do
assert http.connections.one? { |c| c.state == :closed }, "should have no closed connections"
exit!(0)
end
assert http.connections.none? { |c| c.state == :closed }, "should have no closed connections"
_, status = Process.waitpid2(pid)
assert_predicate(status, :success?)
end
private
def scheme
"https://"
end
def request(verb = "GET", uri = "http://google.com", **args)
Request.new(verb, uri, Options.new, **args)
end
def response(*args)
Response.new(*args)
end
end