diff options
Diffstat (limited to 'spec/rubyspec/library/socket')
15 files changed, 31 insertions, 34 deletions
diff --git a/spec/rubyspec/library/socket/fixtures/classes.rb b/spec/rubyspec/library/socket/fixtures/classes.rb index ddb2396731..f154330b9d 100644 --- a/spec/rubyspec/library/socket/fixtures/classes.rb +++ b/spec/rubyspec/library/socket/fixtures/classes.rb @@ -51,7 +51,18 @@ module SocketSpecs end def self.socket_path - tmp("unix_server_spec.socket", false) + path = tmp("unix.sock", false) + # Check for too long unix socket path (max 108 bytes including \0 => 107) + # Note that Linux accepts not null-terminated paths but the man page advises against it. + if path.bytesize > 107 + path = "/tmp/unix_server_spec.socket" + end + rm_socket(path) + path + end + + def self.rm_socket(path) + File.delete(path) if File.exist?(path) end # TCPServer echo server accepting one connection diff --git a/spec/rubyspec/library/socket/unixserver/accept_nonblock_spec.rb b/spec/rubyspec/library/socket/unixserver/accept_nonblock_spec.rb index bad9139eea..b94e91e879 100644 --- a/spec/rubyspec/library/socket/unixserver/accept_nonblock_spec.rb +++ b/spec/rubyspec/library/socket/unixserver/accept_nonblock_spec.rb @@ -6,8 +6,6 @@ describe "UNIXServer#accept_nonblock" do platform_is_not :windows do before :each do @path = SocketSpecs.socket_path - rm_r @path - @server = UNIXServer.open(@path) @client = UNIXSocket.open(@path) @@ -19,7 +17,7 @@ describe "UNIXServer#accept_nonblock" do @socket.close @client.close @server.close - rm_r @path + SocketSpecs.rm_socket @path end it "accepts a connection in a non-blocking way" do diff --git a/spec/rubyspec/library/socket/unixserver/accept_spec.rb b/spec/rubyspec/library/socket/unixserver/accept_spec.rb index 6ce1f2c6db..15459f5043 100644 --- a/spec/rubyspec/library/socket/unixserver/accept_spec.rb +++ b/spec/rubyspec/library/socket/unixserver/accept_spec.rb @@ -5,16 +5,15 @@ platform_is_not :windows do describe "UNIXServer#accept" do before :each do @path = SocketSpecs.socket_path - rm_r @path end after :each do - rm_r @path + SocketSpecs.rm_socket @path end it "accepts what is written by the client" do - server = UNIXServer.open(SocketSpecs.socket_path) - client = UNIXSocket.open(SocketSpecs.socket_path) + server = UNIXServer.open(@path) + client = UNIXSocket.open(@path) client.send('hello', 0) diff --git a/spec/rubyspec/library/socket/unixserver/for_fd_spec.rb b/spec/rubyspec/library/socket/unixserver/for_fd_spec.rb index bf8aa41d40..c3cfd86a1c 100644 --- a/spec/rubyspec/library/socket/unixserver/for_fd_spec.rb +++ b/spec/rubyspec/library/socket/unixserver/for_fd_spec.rb @@ -4,13 +4,13 @@ require File.expand_path('../../fixtures/classes', __FILE__) platform_is_not :windows do describe "UNIXServer#for_fd" do before :each do - @unix_path = tmp("unix_socket") + @unix_path = SocketSpecs.socket_path @unix = UNIXServer.new(@unix_path) end after :each do @unix.close if @unix - rm_r @unix_path + SocketSpecs.rm_socket @unix_path end it "can calculate the path" do diff --git a/spec/rubyspec/library/socket/unixserver/open_spec.rb b/spec/rubyspec/library/socket/unixserver/open_spec.rb index 4401d9dda8..47c76eb9b4 100644 --- a/spec/rubyspec/library/socket/unixserver/open_spec.rb +++ b/spec/rubyspec/library/socket/unixserver/open_spec.rb @@ -6,14 +6,13 @@ describe "UNIXServer.open" do platform_is_not :windows do before :each do - @path = tmp("unixserver_spec") - rm_r @path + @path = SocketSpecs.socket_path end after :each do @server.close if @server @server = nil - rm_r @path + SocketSpecs.rm_socket @path end it "yields the new UNIXServer object to the block, if given" do diff --git a/spec/rubyspec/library/socket/unixserver/shared/new.rb b/spec/rubyspec/library/socket/unixserver/shared/new.rb index 9b0798b828..2018140caa 100644 --- a/spec/rubyspec/library/socket/unixserver/shared/new.rb +++ b/spec/rubyspec/library/socket/unixserver/shared/new.rb @@ -5,14 +5,13 @@ require 'tempfile' describe :unixserver_new, shared: true do platform_is_not :windows do before :each do - @path = tmp("unixserver_spec") - rm_r @path + @path = SocketSpecs.socket_path end after :each do @server.close if @server @server = nil - rm_r @path + SocketSpecs.rm_socket @path end it "creates a new UNIXServer" do diff --git a/spec/rubyspec/library/socket/unixsocket/addr_spec.rb b/spec/rubyspec/library/socket/unixsocket/addr_spec.rb index 893a910e92..34c62e083f 100644 --- a/spec/rubyspec/library/socket/unixsocket/addr_spec.rb +++ b/spec/rubyspec/library/socket/unixsocket/addr_spec.rb @@ -6,8 +6,6 @@ describe "UNIXSocket#addr" do platform_is_not :windows do before :each do @path = SocketSpecs.socket_path - rm_r @path - @server = UNIXServer.open(@path) @client = UNIXSocket.open(@path) end @@ -15,7 +13,7 @@ describe "UNIXSocket#addr" do after :each do @client.close @server.close - rm_r @path + SocketSpecs.rm_socket @path end it "returns the address family of this socket in an array" do diff --git a/spec/rubyspec/library/socket/unixsocket/open_spec.rb b/spec/rubyspec/library/socket/unixsocket/open_spec.rb index eb8ffbaf22..5b9b19ee33 100644 --- a/spec/rubyspec/library/socket/unixsocket/open_spec.rb +++ b/spec/rubyspec/library/socket/unixsocket/open_spec.rb @@ -14,7 +14,7 @@ describe "UNIXSocket.open" do after :each do @server.close - rm_r @path + SocketSpecs.rm_socket @path end it "opens a unix socket on the specified file and yields it to the block" do diff --git a/spec/rubyspec/library/socket/unixsocket/partially_closable_spec.rb b/spec/rubyspec/library/socket/unixsocket/partially_closable_spec.rb index 1123a23541..f43274db2e 100644 --- a/spec/rubyspec/library/socket/unixsocket/partially_closable_spec.rb +++ b/spec/rubyspec/library/socket/unixsocket/partially_closable_spec.rb @@ -7,7 +7,6 @@ platform_is_not :windows do before :each do @path = SocketSpecs.socket_path - rm_r @path @server = UNIXServer.open(@path) @s1 = UNIXSocket.new(@path) @s2 = @server.accept @@ -17,7 +16,7 @@ platform_is_not :windows do @server.close @s1.close @s2.close - rm_r @path + SocketSpecs.rm_socket @path end it_should_behave_like "partially closable sockets" diff --git a/spec/rubyspec/library/socket/unixsocket/path_spec.rb b/spec/rubyspec/library/socket/unixsocket/path_spec.rb index a9186854da..a2beaffeea 100644 --- a/spec/rubyspec/library/socket/unixsocket/path_spec.rb +++ b/spec/rubyspec/library/socket/unixsocket/path_spec.rb @@ -6,8 +6,6 @@ describe "UNIXSocket#path" do platform_is_not :windows do before :each do @path = SocketSpecs.socket_path - rm_r @path - @server = UNIXServer.open(@path) @client = UNIXSocket.open(@path) end @@ -15,7 +13,7 @@ describe "UNIXSocket#path" do after :each do @client.close @server.close - rm_r @path + SocketSpecs.rm_socket @path end it "returns the path of the socket if it's a server" do diff --git a/spec/rubyspec/library/socket/unixsocket/peeraddr_spec.rb b/spec/rubyspec/library/socket/unixsocket/peeraddr_spec.rb index cd224540ef..14dccf7917 100644 --- a/spec/rubyspec/library/socket/unixsocket/peeraddr_spec.rb +++ b/spec/rubyspec/library/socket/unixsocket/peeraddr_spec.rb @@ -6,8 +6,6 @@ describe "UNIXSocket#peeraddr" do platform_is_not :windows do before :each do @path = SocketSpecs.socket_path - rm_r @path - @server = UNIXServer.open(@path) @client = UNIXSocket.open(@path) end @@ -15,7 +13,7 @@ describe "UNIXSocket#peeraddr" do after :each do @client.close @server.close - rm_r @path + SocketSpecs.rm_socket @path end it "returns the address familly and path of the server end of the connection" do diff --git a/spec/rubyspec/library/socket/unixsocket/recv_io_spec.rb b/spec/rubyspec/library/socket/unixsocket/recv_io_spec.rb index 9fc4470572..c7a8946ceb 100644 --- a/spec/rubyspec/library/socket/unixsocket/recv_io_spec.rb +++ b/spec/rubyspec/library/socket/unixsocket/recv_io_spec.rb @@ -20,7 +20,7 @@ describe "UNIXSocket#recv_io" do @file.close @client.close @server.close - rm_r @path + SocketSpecs.rm_socket @path end it "reads an IO object across the socket" do diff --git a/spec/rubyspec/library/socket/unixsocket/recvfrom_spec.rb b/spec/rubyspec/library/socket/unixsocket/recvfrom_spec.rb index 7ac002607c..78e272bfe2 100644 --- a/spec/rubyspec/library/socket/unixsocket/recvfrom_spec.rb +++ b/spec/rubyspec/library/socket/unixsocket/recvfrom_spec.rb @@ -6,8 +6,6 @@ describe "UNIXSocket#recvfrom" do platform_is_not :windows do before :each do @path = SocketSpecs.socket_path - rm_r @path - @server = UNIXServer.open(@path) @client = UNIXSocket.open(@path) end @@ -15,7 +13,7 @@ describe "UNIXSocket#recvfrom" do after :each do @client.close @server.close - rm_r @path + SocketSpecs.rm_socket @path end it "receives len bytes from sock" do diff --git a/spec/rubyspec/library/socket/unixsocket/send_io_spec.rb b/spec/rubyspec/library/socket/unixsocket/send_io_spec.rb index fb6ce9ba17..ec8d6b2314 100644 --- a/spec/rubyspec/library/socket/unixsocket/send_io_spec.rb +++ b/spec/rubyspec/library/socket/unixsocket/send_io_spec.rb @@ -20,7 +20,7 @@ describe "UNIXSocket#send_io" do @file.close @client.close @server.close - rm_r @path + SocketSpecs.rm_socket @path end it "sends the fd for an IO object across the socket" do diff --git a/spec/rubyspec/library/socket/unixsocket/shared/new.rb b/spec/rubyspec/library/socket/unixsocket/shared/new.rb index 9d8fb809d2..76c0d07b83 100644 --- a/spec/rubyspec/library/socket/unixsocket/shared/new.rb +++ b/spec/rubyspec/library/socket/unixsocket/shared/new.rb @@ -11,7 +11,7 @@ describe :unixsocket_new, shared: true do after :each do @client.close if @client @server.close - rm_r @path + SocketSpecs.rm_socket @path end it "opens a unix socket on the specified file" do |