Skip to content

Commit

Permalink
socket_manager_spec: add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Shizuo Fujita <[email protected]>
  • Loading branch information
Watson1978 committed Oct 15, 2024
1 parent 4a5b1a4 commit 03bc031
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/serverengine/socket_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def initialize(path, start: true)
end

attr_reader :path
attr_reader :tcp_sockets, :udp_sockets # for tests

def new_client
Client.new(@path)
Expand Down
35 changes: 35 additions & 0 deletions spec/socket_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
expect(server.path).to be_between(49152, 65535)
end
end

context 'Server.take_over_another_server' do
it 'not supported' do
server = SocketManager::Server.open(server_path)
expect { SocketManager::Server.take_over_another_server(server_path) }.to raise_error(NotImplementedError)
ensure
server.close
end
end
else
context 'Server.generate_path' do
it 'returns socket path under /tmp' do
Expand All @@ -76,6 +85,32 @@
expect(server.path).to include('/tmp/SERVERENGINE_SOCKETMANAGER_')
end
end

context 'Server.take_over_another_server' do
it 'should take over listen sockets to another server' do
server = SocketManager::Server.open(server_path)

client = ServerEngine::SocketManager::Client.new(server_path)
tcp1 = client.listen_tcp('127.0.0.1', 55551)
udp1 = client.listen_udp('127.0.0.1', 55561)
udp2 = client.listen_udp('127.0.0.1', 55562)

another_server = SocketManager::Server.take_over_another_server(server_path)

expect(another_server.tcp_sockets.size).to eq(1)
expect(another_server.tcp_sockets['localhost:55551'].addr).to eq(['AF_INET', 55551, '127.0.0.1', '127.0.0.1'])

expect(another_server.udp_sockets.size).to eq(2)
expect(another_server.udp_sockets['localhost:55561'].addr).to eq(['AF_INET', 55561, '127.0.0.1', '127.0.0.1'])
expect(another_server.udp_sockets['localhost:55562'].addr).to eq(['AF_INET', 55562, '127.0.0.1', '127.0.0.1'])
ensure
tcp1.close
udp1.close
udp2.close
server.close
another_server.close
end
end
end

context 'with thread' do
Expand Down

0 comments on commit 03bc031

Please sign in to comment.