Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/unit/test_children.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def test_dump_load
@children = assert_roundtrip(@children)

pipe = Pitchfork.socketpair.last
GC.start
service = Worker.new(nil, service: true)
@children.register_service(service)
@children.update(Message::ServiceSpawned.new(48, 1, 0, pipe))
Expand All @@ -281,6 +282,14 @@ def test_dump_load

def assert_roundtrip(children)
data = children.dump
# The loaded children need their own descriptors in this process.
data.each do |worker|
next unless worker[:monitor_fd]

socket = IO.for_fd(worker[:monitor_fd], autoclose: false).dup
socket.autoclose = false
worker[:monitor_fd] = socket.fileno
end
cloned_children = Children.load(data)
assert_equal(data.to_set, cloned_children.dump.to_set)
cloned_children
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_socket_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def test_bind_listen_unix_idempotent
test_bind_listen_unix
a = bind_listen(@unix_listener)
assert_equal a.fileno, @unix_listener.fileno
# The listener owns the descriptor; the cast is a borrowed view.
unix_server = server_cast(@unix_listener)
unix_server.autoclose = false
assert UNIXServer === unix_server
a = bind_listen(unix_server)
assert_equal a.fileno, unix_server.fileno
Expand All @@ -92,6 +94,7 @@ def test_bind_listen_tcp_idempotent
a = bind_listen(@tcp_listener)
assert_equal a.fileno, @tcp_listener.fileno
tcp_server = server_cast(@tcp_listener)
tcp_server.autoclose = false
assert TCPServer === tcp_server
a = bind_listen(tcp_server)
assert_equal a.fileno, tcp_server.fileno
Expand Down Expand Up @@ -127,9 +130,12 @@ def test_bind_listen_unix_rebind
def test_server_cast
test_bind_listen_unix
test_bind_listen_tcp
# Both temporary views borrow the listener's descriptor.
unix_listener_socket = Socket.for_fd(@unix_listener.fileno)
unix_listener_socket.autoclose = false
assert Socket === unix_listener_socket
@unix_server = server_cast(unix_listener_socket)
@unix_server.autoclose = false
assert_equal @unix_listener.fileno, @unix_server.fileno
assert UNIXServer === @unix_server
assert_equal(@unix_server.path, @unix_listener.path,
Expand All @@ -138,8 +144,10 @@ def test_server_cast
assert_equal @unix_listener_path, sock_name(@unix_server)

tcp_listener_socket = Socket.for_fd(@tcp_listener.fileno)
tcp_listener_socket.autoclose = false
assert Socket === tcp_listener_socket
@tcp_server = server_cast(tcp_listener_socket)
@tcp_server.autoclose = false
assert_equal @tcp_listener.fileno, @tcp_server.fileno
assert TCPServer === @tcp_server
assert_equal @tcp_listener_name, sock_name(@tcp_server)
Expand Down
2 changes: 2 additions & 0 deletions test/unit/test_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def test_dump_load
state = worker.dump
assert_equal(expected, state)

# A restart replaces the process image before reloading the descriptor.
worker.monitor.to_io.autoclose = false
cloned_worker = Worker.load(state)
assert_equal worker.monitor.class, cloned_worker.monitor.class
assert_equal worker.monitor.fileno, cloned_worker.monitor.fileno
Expand Down
Loading