Project

General

Profile

Backport #670 » test_crashes_os_x.rb

rogerdpack (Roger Pack), 10/21/2008 08:01 AM

 
# This test crashes OS X if run after increasing the file size limit [i.e. run
# touch abc # necessary
# then
# ulimit -n 10000
# then this file

require 'socket'

class TCPSocket
attr_accessor :wrote
end

no_files = 0

server_ports = []
clients = []

deplete_fds = []
2000.times { deplete_fds << File.new('abc', 'r')}
#print 'got', deplete_fds.length
begin
while true
another_server = TCPServer.new 'localhost', nil
port = another_server.addr[1]
clients << TCPSocket.new('localhost', port)
server_ports << another_server.accept
end
rescue Exception => e
print 'got', clients.length, e
end
print 'continuing'

for client in clients
what_to_write = rand(100000).to_s
client.write what_to_write
client.wrote = what_to_write
end

for server_port in server_ports
print 'accepting, receiving'
received = server_port.recv 1024
server_port.write received
end
print 'herey'
for client in clients
received = client.recv(1024)
raise 'got back weird data' unless received == client.wrote
end
print 'success'

(1-1/5)