Project

General

Profile

Backport #670 ยป test_crashes_os_x.rb

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

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

    
7
require 'socket'
8

    
9
class TCPSocket
10
 attr_accessor :wrote
11
end
12

    
13
no_files = 0
14

    
15
server_ports = []
16
clients = []
17

    
18
deplete_fds = []
19
2000.times { deplete_fds << File.new('abc', 'r')}
20
#print 'got', deplete_fds.length
21
begin
22
while true
23
  another_server = TCPServer.new 'localhost', nil
24
  port = another_server.addr[1]
25
  clients << TCPSocket.new('localhost', port)
26
  server_ports << another_server.accept
27
end
28
rescue Exception => e
29
 print 'got', clients.length, e
30
end
31
print 'continuing'
32

    
33
for client in clients
34
 what_to_write = rand(100000).to_s
35
 client.write what_to_write
36
 client.wrote = what_to_write
37
end
38

    
39
for server_port in server_ports
40
  print 'accepting, receiving'
41
  received = server_port.recv 1024
42
  server_port.write received
43
end
44
print 'herey'
45
for client in clients
46
 received = client.recv(1024)
47
 raise 'got back weird data' unless received == client.wrote
48
end
49
print 'success'
50