eventmachine 1.0.0.beta.2-x86-mingw32 → 1.0.0.beta.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.yardopts +3 -0
  2. data/Gemfile +1 -0
  3. data/eventmachine.gemspec +1 -3
  4. data/ext/cmain.cpp +4 -4
  5. data/ext/ed.cpp +13 -16
  6. data/ext/ed.h +9 -10
  7. data/ext/em.cpp +14 -24
  8. data/ext/eventmachine.h +2 -2
  9. data/ext/extconf.rb +1 -1
  10. data/ext/rubymain.cpp +8 -6
  11. data/lib/em/connection.rb +3 -1
  12. data/lib/em/pure_ruby.rb +17 -17
  13. data/lib/em/resolver.rb +186 -0
  14. data/lib/em/spawnable.rb +3 -7
  15. data/lib/em/version.rb +1 -1
  16. data/lib/eventmachine.rb +6 -4
  17. data/lib/jeventmachine.rb +1 -1
  18. data/tasks/package.rake +4 -1
  19. data/tasks/test.rake +1 -0
  20. data/tests/em_test_helper.rb +55 -0
  21. data/tests/test_attach.rb +46 -56
  22. data/tests/test_basic.rb +74 -96
  23. data/tests/test_channel.rb +2 -4
  24. data/tests/test_connection_count.rb +1 -3
  25. data/tests/test_defer.rb +13 -44
  26. data/tests/test_deferrable.rb +19 -19
  27. data/tests/test_epoll.rb +25 -55
  28. data/tests/test_error_handler.rb +10 -7
  29. data/tests/test_exc.rb +6 -33
  30. data/tests/test_file_watch.rb +51 -35
  31. data/tests/test_futures.rb +9 -37
  32. data/tests/test_get_sock_opt.rb +27 -20
  33. data/tests/test_handler_check.rb +1 -3
  34. data/tests/test_hc.rb +24 -59
  35. data/tests/test_httpclient.rb +27 -64
  36. data/tests/test_httpclient2.rb +1 -29
  37. data/tests/test_inactivity_timeout.rb +44 -40
  38. data/tests/test_kb.rb +26 -52
  39. data/tests/test_ltp.rb +23 -67
  40. data/tests/test_ltp2.rb +1 -30
  41. data/tests/test_next_tick.rb +1 -30
  42. data/tests/test_object_protocol.rb +8 -9
  43. data/tests/test_pause.rb +45 -37
  44. data/tests/test_pending_connect_timeout.rb +42 -38
  45. data/tests/test_process_watch.rb +1 -3
  46. data/tests/test_processes.rb +92 -110
  47. data/tests/test_proxy_connection.rb +128 -104
  48. data/tests/test_pure.rb +29 -75
  49. data/tests/test_queue.rb +2 -4
  50. data/tests/test_resolver.rb +55 -0
  51. data/tests/test_running.rb +1 -29
  52. data/tests/test_sasl.rb +7 -32
  53. data/tests/test_send_file.rb +162 -196
  54. data/tests/test_servers.rb +13 -56
  55. data/tests/test_smtpclient.rb +1 -29
  56. data/tests/test_smtpserver.rb +1 -29
  57. data/tests/test_spawn.rb +2 -31
  58. data/tests/test_ssl_args.rb +9 -10
  59. data/tests/test_ssl_methods.rb +1 -3
  60. data/tests/test_ssl_verify.rb +63 -63
  61. data/tests/test_tick_loop.rb +1 -1
  62. data/tests/test_timers.rb +52 -89
  63. data/tests/test_ud.rb +1 -29
  64. metadata +20 -10
  65. data/setup.rb +0 -1585
  66. data/tests/test_errors.rb +0 -82
  67. data/tests/testem.rb +0 -31
@@ -1,144 +1,168 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
1
+ require 'em_test_helper'
4
2
 
5
3
  class TestProxyConnection < Test::Unit::TestCase
6
4
 
7
- module ProxyConnection
8
- def initialize(client, request)
9
- @client, @request = client, request
10
- end
5
+ if EM.respond_to?(:start_proxy)
6
+ module ProxyConnection
7
+ def initialize(client, request)
8
+ @client, @request = client, request
9
+ end
11
10
 
12
- def post_init
13
- EM::enable_proxy(self, @client)
14
- end
11
+ def post_init
12
+ EM::enable_proxy(self, @client)
13
+ end
15
14
 
16
- def connection_completed
17
- EM.next_tick {
18
- send_data @request
19
- }
20
- end
15
+ def connection_completed
16
+ EM.next_tick {
17
+ send_data @request
18
+ }
19
+ end
21
20
 
22
- def proxy_target_unbound
23
- $unbound_early = true
24
- EM.stop
25
- end
21
+ def proxy_target_unbound
22
+ $unbound_early = true
23
+ EM.stop
24
+ end
26
25
 
27
- def unbind
28
- @client.close_connection_after_writing
26
+ def unbind
27
+ @client.close_connection_after_writing
28
+ end
29
29
  end
30
- end
31
30
 
32
- module PartialProxyConnection
33
- def initialize(client, request, length)
34
- @client, @request, @length = client, request, length
35
- end
31
+ module PartialProxyConnection
32
+ def initialize(client, request, length)
33
+ @client, @request, @length = client, request, length
34
+ end
36
35
 
37
- def post_init
38
- EM::enable_proxy(self, @client, 0, @length)
39
- end
36
+ def post_init
37
+ EM::enable_proxy(self, @client, 0, @length)
38
+ end
40
39
 
41
- def receive_data(data)
42
- $unproxied_data = data
43
- @client.send_data(data)
44
- end
40
+ def receive_data(data)
41
+ $unproxied_data = data
42
+ @client.send_data(data)
43
+ end
45
44
 
46
- def connection_completed
47
- EM.next_tick {
48
- send_data @request
49
- }
50
- end
45
+ def connection_completed
46
+ EM.next_tick {
47
+ send_data @request
48
+ }
49
+ end
51
50
 
52
- def proxy_target_unbound
53
- $unbound_early = true
54
- EM.stop
55
- end
51
+ def proxy_target_unbound
52
+ $unbound_early = true
53
+ EM.stop
54
+ end
56
55
 
57
- def proxy_completed
58
- $proxy_completed = true
59
- end
56
+ def proxy_completed
57
+ $proxy_completed = true
58
+ end
60
59
 
61
- def unbind
62
- @client.close_connection_after_writing
60
+ def unbind
61
+ @client.close_connection_after_writing
62
+ end
63
63
  end
64
- end
65
64
 
66
- module Client
67
- def connection_completed
68
- send_data "EventMachine rocks!"
65
+ module Client
66
+ def connection_completed
67
+ send_data "EM rocks!"
68
+ end
69
+
70
+ def receive_data(data)
71
+ $client_data = data
72
+ end
73
+
74
+ def unbind
75
+ EM.stop
76
+ end
69
77
  end
70
78
 
71
- def receive_data(data)
72
- $client_data = data
79
+ module Client2
80
+ include Client
81
+ def unbind; end
73
82
  end
74
83
 
75
- def unbind
76
- EM.stop
84
+ module Server
85
+ def receive_data(data)
86
+ send_data "I know!" if data == "EM rocks!"
87
+ close_connection_after_writing
88
+ end
77
89
  end
78
- end
79
90
 
80
- module Client2
81
- include Client
82
- def unbind; end
83
- end
91
+ module ProxyServer
92
+ def initialize port
93
+ @port = port
94
+ end
84
95
 
85
- module Server
86
- def receive_data(data)
87
- send_data "I know!" if data == "EventMachine rocks!"
88
- close_connection_after_writing
96
+ def receive_data(data)
97
+ EM.connect("127.0.0.1", @port, ProxyConnection, self, data)
98
+ end
89
99
  end
90
- end
91
100
 
92
- module ProxyServer
93
- def receive_data(data)
94
- EM.connect("127.0.0.1", 54321, ProxyConnection, self, data)
101
+ module PartialProxyServer
102
+ def initialize port
103
+ @port = port
104
+ end
105
+
106
+ def receive_data(data)
107
+ EM.connect("127.0.0.1", @port, PartialProxyConnection, self, data, 1)
108
+ end
95
109
  end
96
- end
97
110
 
98
- module PartialProxyServer
99
- def receive_data(data)
100
- EM.connect("127.0.0.1", 54321, PartialProxyConnection, self, data, 1)
111
+ module EarlyClosingProxy
112
+ def initialize port
113
+ @port = port
114
+ end
115
+
116
+ def receive_data(data)
117
+ EM.connect("127.0.0.1", @port, ProxyConnection, self, data)
118
+ close_connection
119
+ end
101
120
  end
102
- end
103
121
 
104
- module EarlyClosingProxy
105
- def receive_data(data)
106
- EM.connect("127.0.0.1", 54321, ProxyConnection, self, data)
107
- close_connection
122
+ def setup
123
+ @port = next_port
124
+ @proxy_port = next_port
108
125
  end
109
- end
110
126
 
111
- def test_proxy_connection
112
- EM.run {
113
- EM.start_server("127.0.0.1", 54321, Server)
114
- EM.start_server("127.0.0.1", 12345, ProxyServer)
115
- EM.connect("127.0.0.1", 12345, Client)
116
- }
127
+ def test_proxy_connection
128
+ EM.run {
129
+ EM.start_server("127.0.0.1", @port, Server)
130
+ EM.start_server("127.0.0.1", @proxy_port, ProxyServer, @port)
131
+ EM.connect("127.0.0.1", @proxy_port, Client)
132
+ }
117
133
 
118
- assert_equal("I know!", $client_data)
119
- end
134
+ assert_equal("I know!", $client_data)
135
+ end
120
136
 
121
- def test_partial_proxy_connection
122
- EM.run {
123
- EM.start_server("127.0.0.1", 54321, Server)
124
- EM.start_server("127.0.0.1", 12345, PartialProxyServer)
125
- EM.connect("127.0.0.1", 12345, Client)
126
- }
137
+ def test_partial_proxy_connection
138
+ EM.run {
139
+ EM.start_server("127.0.0.1", @port, Server)
140
+ EM.start_server("127.0.0.1", @proxy_port, PartialProxyServer, @port)
141
+ EM.connect("127.0.0.1", @proxy_port, Client)
142
+ }
127
143
 
128
- assert_equal("I know!", $client_data)
129
- assert_equal(" know!", $unproxied_data)
130
- assert($proxy_completed)
131
- end
144
+ assert_equal("I know!", $client_data)
145
+ assert_equal(" know!", $unproxied_data)
146
+ assert($proxy_completed)
147
+ end
132
148
 
133
- def test_early_close
134
- $client_data = nil
135
- EM.run {
136
- EM.start_server("127.0.0.1", 54321, Server)
137
- EM.start_server("127.0.0.1", 12345, EarlyClosingProxy)
138
- EM.connect("127.0.0.1", 12345, Client2)
139
- }
149
+ def test_early_close
150
+ $client_data = nil
151
+ EM.run {
152
+ EM.start_server("127.0.0.1", @port, Server)
153
+ EM.start_server("127.0.0.1", @proxy_port, EarlyClosingProxy, @port)
154
+ EM.connect("127.0.0.1", @proxy_port, Client2)
155
+ }
156
+
157
+ assert($unbound_early)
158
+ end
159
+ else
160
+ warn "EM.start_proxy not implemented, skipping tests in #{__FILE__}"
140
161
 
141
- assert($unbound_early)
162
+ # Because some rubies will complain if a TestCase class has no tests
163
+ def test_em_start_proxy_not_implemented
164
+ assert !EM.respond_to?(:start_proxy)
165
+ end
142
166
  end
143
167
 
144
168
  end
@@ -1,76 +1,36 @@
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'
1
+ require 'em_test_helper'
30
2
 
31
3
  class TestPure < Test::Unit::TestCase
32
4
 
33
-
34
- Host,Port = "0.0.0.0", 9060
35
-
5
+ def setup
6
+ @port = next_port
7
+ end
36
8
 
37
9
  # These tests are intended to exercise problems that come up in the
38
10
  # pure-Ruby implementation. However, we DON'T constrain them such that
39
11
  # they only run in pure-Ruby. These tests need to work identically in
40
12
  # any implementation.
41
13
 
42
- def setup
43
- end
44
-
45
- def teardown
46
- end
47
-
48
14
  #-------------------------------------
49
15
 
50
16
  # The EM reactor needs to run down open connections and release other resources
51
17
  # when it stops running. Make sure this happens even if user code throws a Ruby
52
18
  # 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
19
  # If exception handling is incorrect, the second test will fail with a no-bind error
58
20
  # 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_raises( RuntimeError ) { run_exception }
68
- end
69
- def test_exception_2
70
- ex_class = RUBY_PLATFORM == 'java' ? NativeException : RuntimeError
71
- assert_raises( ex_class ) { run_exception }
72
- end
73
21
 
22
+ def test_exception_handling_releases_resources
23
+ exception = Class.new(StandardError)
24
+
25
+ 2.times do
26
+ assert_raises(exception) do
27
+ EM.run do
28
+ EM.start_server "127.0.0.1", @port
29
+ raise exception
30
+ end
31
+ end
32
+ end
33
+ end
74
34
 
75
35
  # Under some circumstances, the pure Ruby library would emit an Errno::ECONNREFUSED
76
36
  # exception on certain kinds of TCP connect-errors.
@@ -87,13 +47,16 @@ class TestPure < Test::Unit::TestCase
87
47
  raise "should never get here"
88
48
  end
89
49
  end
50
+
90
51
  def test_connrefused
91
- EM.run {
92
- EM.connect "0.0.0.0", 60001, TestConnrefused
93
- }
52
+ assert_nothing_raised do
53
+ EM.run {
54
+ setup_timeout(2)
55
+ EM.connect "127.0.0.1", @port, TestConnrefused
56
+ }
57
+ end
94
58
  end
95
59
 
96
-
97
60
  # Make sure connection_completed gets called as expected with TCP clients. This is the
98
61
  # opposite of test_connrefused.
99
62
  # If the test fails, it will hang because EM.stop never gets called.
@@ -104,22 +67,13 @@ class TestPure < Test::Unit::TestCase
104
67
  end
105
68
  end
106
69
  def test_connaccepted
107
- timeout = false
108
- EM.run {
109
- EM.start_server "0.0.0.0", 60002
110
- EM.connect "0.0.0.0", 60002, TestConnaccepted
111
- setup_timeout(1)
112
- }
113
- assert_equal( false, timeout )
114
- end
115
-
116
- def setup_timeout(timeout = 4)
117
- EM.schedule {
118
- start_time = EM.current_time
119
- EM.add_periodic_timer(0.01) {
120
- raise "timeout" if EM.current_time - start_time >= timeout
70
+ assert_nothing_raised do
71
+ EM.run {
72
+ EM.start_server "127.0.0.1", @port
73
+ EM.connect "127.0.0.1", @port, TestConnaccepted
74
+ setup_timeout(1)
121
75
  }
122
- }
76
+ end
123
77
  end
124
78
 
125
79
  def test_reactor_running
@@ -1,8 +1,6 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
1
+ require 'em_test_helper'
4
2
 
5
- class TestEventMachineQueue < Test::Unit::TestCase
3
+ class TestEMQueue < Test::Unit::TestCase
6
4
  def test_queue_push
7
5
  s = 0
8
6
  EM.run do
@@ -0,0 +1,55 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestBasic < Test::Unit::TestCase
4
+ def test_a
5
+ EM.run {
6
+ d = EM::DNS::Resolver.resolve "google.com"
7
+ d.errback { assert false }
8
+ d.callback { |r|
9
+ assert r
10
+ EM.stop
11
+ }
12
+ }
13
+ end
14
+
15
+ def test_bad_host
16
+ EM.run {
17
+ d = EM::DNS::Resolver.resolve "asdfasasdf"
18
+ d.callback { assert false }
19
+ d.errback { assert true; EM.stop }
20
+ }
21
+ end
22
+
23
+ def test_garbage
24
+ assert_raises( ArgumentError ) {
25
+ EM.run {
26
+ EM::DNS::Resolver.resolve 123
27
+ }
28
+ }
29
+ end
30
+
31
+ def test_a_pair
32
+ EM.run {
33
+ d = EM::DNS::Resolver.resolve "google.com"
34
+ d.errback { assert false }
35
+ d.callback { |r|
36
+ assert_equal(Array, r.class)
37
+ assert r.size > 1
38
+ EM.stop
39
+ }
40
+ }
41
+ end
42
+
43
+ def test_localhost
44
+ EM.run {
45
+ d = EM::DNS::Resolver.resolve "localhost"
46
+ d.errback { assert false }
47
+ d.callback { |r|
48
+ assert_equal("127.0.0.1", r.first)
49
+ assert_equal(Array, r.class)
50
+
51
+ EM.stop
52
+ }
53
+ }
54
+ end
55
+ end