root/trunk/tests/test_pure.rb

Revision 788, 3.6 kB (checked in by raggi, 9 months ago)

Merge of branches/raggi
Most notable work and patches by Aman Gupta, Roger Pack, and James Tucker.
Patches / Tickets also submitted by: Jeremy Evans, aanand, darix, mmmurf,
danielaquino, macournoyer.

  • Moved docs into docs/ dir
  • Major refactor of rakefile, added generic rakefile helpers in tasks
  • Added example CPP build rakefile in tasks/cpp.rake
  • Moved rake tests out to tasks/tests.rake
  • Added svn ignores where appropriate
  • Fixed jruby build on older java platforms
  • Gem now builds from Rakefile rather than directly via extconf
  • Gem unified for jruby, C++ and pure ruby.
  • Correction for pure C++ build, removing ruby dependency
  • Fix for CYGWIN builds on ipv6
  • Major refactor for extconf.rb
  • Working mingw builds
  • extconf optionally uses pkg_config over manual configuration
  • extconf builds for 1.9 on any system that has 1.9
  • extconf no longer links pthread explicitly
  • looks for kqueue on all *nix systems
  • better error output on std::runtime_error, now says where it came from
  • Fixed some tests on jruby
  • Added test for general send_data flaw, required for a bugfix in jruby build
  • Added timeout to epoll tests
  • Added fixes for java reactor ruby api
  • Small addition of some docs in httpclient.rb and httpcli2.rb
  • Some refactor and fixes in smtpserver.rb
  • Added parenthesis where possible to avoid excess ruby warnings
  • Refactor of $eventmachine_library logic for accuracy and maintenance, jruby
  • EM::start_server now supports unix sockets
  • EM::connect now supports unix sockets
  • EM::defer @threadqueue now handled more gracefully
  • Added better messages on exceptions raised
  • Fix edge case in timer fires
  • Explicitly require buftok.rb
  • Add protocols to autoload, rather than require them all immediately
  • Fix a bug in pr_eventmachine for outbound_q
  • Refactors to take some of the use of defer out of tests.
  • Fixes in EM.defer under start/stop conditions. Reduced scope of threads.
  • Property svn:keywords set to Id
Line 
1 # $Id$
2 #
3 # Author:: Francis Cianfrocca (gmail: blackhedd)
4 # Homepage::  http://rubyeventmachine.com
5 # Date:: 8 April 2006
6 #
7 # See EventMachine and EventMachine::Connection for documentation and
8 # usage examples.
9 #
10 #----------------------------------------------------------------------------
11 #
12 # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13 # Gmail: blackhedd
14 #
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of either: 1) the GNU General Public License
17 # as published by the Free Software Foundation; either version 2 of the
18 # License, or (at your option) any later version; or 2) Ruby's License.
19 #
20 # See the file COPYING for complete licensing information.
21 #
22 #---------------------------------------------------------------------------
23 #
24 #
25 #
26
27 $:.unshift "../lib"
28 require 'eventmachine'
29 require 'test/unit'
30
31 class TestPure < Test::Unit::TestCase
32
33
34   Host,Port = "0.0.0.0", 9060
35
36
37   # These tests are intended to exercise problems that come up in the
38   # pure-Ruby implementation. However, we DON'T constrain them such that
39   # they only run in pure-Ruby. These tests need to work identically in
40   # any implementation.
41
42   def setup
43   end
44
45   def teardown
46   end
47
48   #-------------------------------------
49
50   # The EM reactor needs to run down open connections and release other resources
51   # when it stops running. Make sure this happens even if user code throws a Ruby
52   # exception.
53   # One way to see this is to run identical tests that open a TCP server and throw
54   # an exception. (We do this twice because an exception aborts a test. We make the
55   # two tests identical except for the method name because we can't predict the order
56   # in which the test harness will run them.)
57   # If exception handling is incorrect, the second test will fail with a no-bind error
58   # because the TCP server opened in the first test will not have been closed.
59   #
60   def run_exception
61       EM.run {
62         EM.start_server Host, Port
63         raise "an exception"
64       }
65   end
66   def test_exception_1
67     assert_raise( RuntimeError ) { run_exception }
68   end
69   def test_exception_2
70                 ex_class = RUBY_PLATFORM == 'java' ? NativeException : RuntimeError
71     assert_raise( ex_class ) { run_exception }
72   end
73
74
75
76   # Under some circumstances, the pure Ruby library would emit an Errno::ECONNREFUSED
77   # exception on certain kinds of TCP connect-errors.
78   # It's always been something of an open question whether EM should throw an exception
79   # in these cases but the defined answer has always been to catch it the unbind method.
80   # With a connect failure, the latter will always fire, but connection_completed will
81   # never fire. So even though the point is arguable, it's incorrect for the pure Ruby
82   # version to throw an exception.
83   module TestConnrefused
84     def unbind
85       EM.stop
86     end
87     def connection_completed
88       raise "should never get here"
89     end
90   end
91   def test_connrefused
92     EM.run {
93       EM.connect "0.0.0.0", 60001, TestConnrefused
94     }
95   end
96
97
98   # Make sure connection_completed gets called as expected with TCP clients. This is the
99   # opposite of test_connrefused.
100   # If the test fails, it will hang because EM.stop never gets called.
101   #
102   module TestConnaccepted
103     def connection_completed
104       EM.stop
105     end
106   end
107   def test_connaccepted
108     timeout = false
109     EM.run {
110       EM.start_server "0.0.0.0", 60002
111       EM.connect "0.0.0.0", 60002, TestConnaccepted
112       EM::Timer.new(1) {timeout = true; EM.stop}
113     }
114     assert_equal( false, timeout )
115   end
116
117
118
119   def test_reactor_running
120     a = false
121     EM.run {
122       a = EM.reactor_running?
123       EM.next_tick {EM.stop}
124     }
125     assert a
126   end
127
128
129 end
Note: See TracBrowser for help on using the browser.