Ticket #33: test_handles_uncaught_exception.rb

File test_handles_uncaught_exception.rb, 1.5 kB (added by rogerdpack, 4 months ago)
Line 
1 # this error occurs when you have several sockets, like 3
2 # they are all 'closed' but their descriptors are in the middle of being collected
3 # THEN the program terminates, which causes the EM thread to jump to its finalizer.
4
5 $:.unshift "../lib"
6 require 'eventmachine'
7 require 'test/unit'
8
9 a = TCPServer.new('localhost', 6000)
10 Thread.new { a.accept }
11
12 module SlowClosers
13   @@total_closed = 0
14
15   def post_init
16     @@total_closed += 1
17     raise LocalJumpError.new() if @@total_closed == 2
18   end
19
20   def unbind
21     @@total_closed += 1
22     raise LocalJumpError.new() if @@total_closed == 2
23   end
24
25 end
26
27 class DeathEnd < Test::Unit::TestCase
28
29    def setup
30         SlowClosers.class_eval("@@total_closed = 0")
31    end
32
33    def test_ends_well_multi_thread # note that ideally it should try it with kqueue, epoll, and normal.  I'm not sure if all the tests should just be re-run with those settings or what
34       begin
35       passed = false
36         EM::run {
37             print "here3\n"
38                 3.times {EM::connect '127.0.0.1', 6000, SlowClosers}
39                 print "here5\n"
40         }
41       rescue LocalJumpError
42         # we should get here--if it errs it will err with a 'HARD' c-style error
43         print "here2\n"
44         passed = true
45       end
46         print "here\n"
47       flunk unless passed
48    end
49
50    # another test with possibility would be one that encourage the ConnectionUnbound caused if they
51    # do a connection or add_timer or start_server from another thread.  Not sure if we want to care about that one [though we should, really]. 
52
53 end
54