eventmachine 1.0.0.beta.2-x86-mswin32-60 → 1.0.0.beta.3-x86-mswin32-60

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
data/tests/test_basic.rb CHANGED
@@ -1,42 +1,18 @@
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 File.expand_path(File.dirname(__FILE__) + "/../lib")
28
- require 'eventmachine'
1
+ require 'em_test_helper'
29
2
  require 'socket'
30
- require 'test/unit'
31
3
 
32
4
  class TestBasic < Test::Unit::TestCase
5
+ def setup
6
+ @port = next_port
7
+ end
8
+
33
9
  def test_connection_class_cache
34
10
  mod = Module.new
35
11
  a, b = nil, nil
36
12
  EM.run {
37
- EM.start_server '127.0.0.1', 9999, mod
38
- a = EM.connect '127.0.0.1', 9999, mod
39
- b = EM.connect '127.0.0.1', 9999, mod
13
+ EM.start_server '127.0.0.1', @port, mod
14
+ a = EM.connect '127.0.0.1', @port, mod
15
+ b = EM.connect '127.0.0.1', @port, mod
40
16
  EM.stop
41
17
  }
42
18
  assert_equal a.class, b.class
@@ -47,23 +23,29 @@ class TestBasic < Test::Unit::TestCase
47
23
 
48
24
 
49
25
  def test_em
50
- EventMachine.run {
51
- EventMachine.add_timer 0 do
52
- EventMachine.stop
53
- end
54
- }
26
+ assert_nothing_raised do
27
+ EM.run {
28
+ setup_timeout
29
+ EM.add_timer 0 do
30
+ EM.stop
31
+ end
32
+ }
33
+ end
55
34
  end
56
35
 
57
36
  #-------------------------------------
58
37
 
59
38
  def test_timer
60
- n = 0
61
- EventMachine.run {
62
- EventMachine.add_periodic_timer(0.1) {
63
- n += 1
64
- EventMachine.stop if n == 2
39
+ assert_nothing_raised do
40
+ EM.run {
41
+ setup_timeout
42
+ n = 0
43
+ EM.add_periodic_timer(0.1) {
44
+ n += 1
45
+ EM.stop if n == 2
46
+ }
65
47
  }
66
- }
48
+ end
67
49
  end
68
50
 
69
51
  #-------------------------------------
@@ -71,22 +53,24 @@ class TestBasic < Test::Unit::TestCase
71
53
  # This test once threw an already-running exception.
72
54
  module Trivial
73
55
  def post_init
74
- EventMachine.stop
56
+ EM.stop
75
57
  end
76
58
  end
77
59
 
78
60
  def test_server
79
- EventMachine.run {
80
- EventMachine.start_server "localhost", 9000, Trivial
81
- EventMachine.connect "localhost", 9000
82
- }
83
- assert( true ) # make sure it halts
61
+ assert_nothing_raised do
62
+ EM.run {
63
+ setup_timeout
64
+ EM.start_server "127.0.0.1", @port, Trivial
65
+ EM.connect "127.0.0.1", @port
66
+ }
67
+ end
84
68
  end
85
69
 
86
70
  #--------------------------------------
87
71
 
88
- # EventMachine#run_block starts the reactor loop, runs the supplied block, and then STOPS
89
- # the loop automatically. Contrast with EventMachine#run, which keeps running the reactor
72
+ # EM#run_block starts the reactor loop, runs the supplied block, and then STOPS
73
+ # the loop automatically. Contrast with EM#run, which keeps running the reactor
90
74
  # even after the supplied block completes.
91
75
  def test_run_block
92
76
  assert !EM.reactor_running?
@@ -96,9 +80,6 @@ class TestBasic < Test::Unit::TestCase
96
80
  assert !EM.reactor_running?
97
81
  end
98
82
 
99
- TestHost = "127.0.0.1"
100
- TestPort = 9070
101
-
102
83
  class UnbindError < EM::Connection
103
84
  ERR = Class.new(StandardError)
104
85
  def initialize *args
@@ -115,8 +96,8 @@ class TestBasic < Test::Unit::TestCase
115
96
  def test_unbind_error
116
97
  assert_raises( UnbindError::ERR ) {
117
98
  EM.run {
118
- EM.start_server TestHost, TestPort
119
- EM.connect TestHost, TestPort, UnbindError
99
+ EM.start_server "127.0.0.1", @port
100
+ EM.connect "127.0.0.1", @port, UnbindError
120
101
  }
121
102
  }
122
103
  end
@@ -136,22 +117,13 @@ class TestBasic < Test::Unit::TestCase
136
117
  end
137
118
  end
138
119
 
139
- def setup_timeout(timeout = 4)
140
- EM.schedule {
141
- start_time = EM.current_time
142
- EM.add_periodic_timer(0.01) {
143
- raise "timeout" if EM.current_time - start_time >= timeout
144
- }
145
- }
146
- end
147
-
148
120
  # From ticket #50
149
121
  def test_byte_range_send
150
122
  $received = ''
151
123
  $sent = (0..255).to_a.pack('C*')
152
124
  EM::run {
153
- EM::start_server TestHost, TestPort, BrsTestSrv
154
- EM::connect TestHost, TestPort, BrsTestCli
125
+ EM::start_server "127.0.0.1", @port, BrsTestSrv
126
+ EM::connect "127.0.0.1", @port, BrsTestCli
155
127
 
156
128
  setup_timeout
157
129
  }
@@ -161,22 +133,27 @@ class TestBasic < Test::Unit::TestCase
161
133
  def test_bind_connect
162
134
  local_ip = UDPSocket.open {|s| s.connect('google.com', 80); s.addr.last }
163
135
 
164
- bind_port = rand(33333)+1025
136
+ bind_port = next_port
165
137
 
166
- test = self
167
- EM.run do
168
- EM.start_server(TestHost, TestPort, Module.new do
169
- define_method :post_init do
170
- begin
171
- test.assert_equal bind_port, Socket.unpack_sockaddr_in(get_peername).first
172
- test.assert_equal local_ip, Socket.unpack_sockaddr_in(get_peername).last
173
- ensure
174
- EM.stop_event_loop
175
- end
138
+ port, ip = nil
139
+ bound_server = Module.new do
140
+ define_method :post_init do
141
+ begin
142
+ port, ip = Socket.unpack_sockaddr_in(get_peername)
143
+ ensure
144
+ EM.stop
176
145
  end
177
- end)
178
- EM.bind_connect local_ip, bind_port, TestHost, TestPort
146
+ end
179
147
  end
148
+
149
+ EM.run do
150
+ setup_timeout
151
+ EM.start_server "127.0.0.1", @port, bound_server
152
+ EM.bind_connect local_ip, bind_port, "127.0.0.1", @port
153
+ end
154
+
155
+ assert_equal bind_port, port
156
+ assert_equal local_ip, ip
180
157
  end
181
158
 
182
159
  def test_reactor_thread?
@@ -196,21 +173,24 @@ class TestBasic < Test::Unit::TestCase
196
173
 
197
174
  def test_schedule_from_thread
198
175
  x = false
199
- assert !x
200
176
  EM.run do
201
177
  Thread.new { EM.schedule { x = true; EM.stop } }.join
202
178
  end
203
179
  assert x
204
180
  end
205
181
 
206
- def test_set_heartbeat_interval
207
- interval = 0.5
208
- EM.run {
209
- EM.set_heartbeat_interval interval
210
- $interval = EM.get_heartbeat_interval
211
- EM.stop
212
- }
213
- assert_equal(interval, $interval)
182
+ if EM.respond_to? :set_heartbeat_interval
183
+ def test_set_heartbeat_interval
184
+ interval = 0.5
185
+ EM.run {
186
+ EM.set_heartbeat_interval interval
187
+ $interval = EM.get_heartbeat_interval
188
+ EM.stop
189
+ }
190
+ assert_equal(interval, $interval)
191
+ end
192
+ else
193
+ warn "EM.set_heartbeat_interval not implemented, skipping a test in #{__FILE__}"
214
194
  end
215
195
 
216
196
  module PostInitRaiser
@@ -221,11 +201,10 @@ class TestBasic < Test::Unit::TestCase
221
201
  end
222
202
 
223
203
  def test_bubble_errors_from_post_init
224
- localhost, port = '127.0.0.1', 9000
225
204
  assert_raises(PostInitRaiser::ERR) do
226
205
  EM.run do
227
- EM.start_server localhost, port
228
- EM.connect localhost, port, PostInitRaiser
206
+ EM.start_server "127.0.0.1", @port
207
+ EM.connect "127.0.0.1", @port, PostInitRaiser
229
208
  end
230
209
  end
231
210
  end
@@ -238,12 +217,11 @@ class TestBasic < Test::Unit::TestCase
238
217
  end
239
218
 
240
219
  def test_bubble_errors_from_initialize
241
- localhost, port = '127.0.0.1', 9000
242
220
  assert_raises(InitializeRaiser::ERR) do
243
221
  EM.run do
244
- EM.start_server localhost, port
245
- EM.connect localhost, port, InitializeRaiser
222
+ EM.start_server "127.0.0.1", @port
223
+ EM.connect "127.0.0.1", @port, InitializeRaiser
246
224
  end
247
225
  end
248
226
  end
249
- end
227
+ end
@@ -1,8 +1,6 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
1
+ require 'em_test_helper'
4
2
 
5
- class TestEventMachineChannel < Test::Unit::TestCase
3
+ class TestEMChannel < Test::Unit::TestCase
6
4
  def test_channel_subscribe
7
5
  s = 0
8
6
  EM.run do
@@ -1,6 +1,4 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
1
+ require 'em_test_helper'
4
2
 
5
3
  class TestConnectionCount < Test::Unit::TestCase
6
4
  def test_idle_connection_count
data/tests/test_defer.rb CHANGED
@@ -1,49 +1,18 @@
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
- #
1
+ require 'em_test_helper'
26
2
 
27
- $:.unshift "../lib"
28
- require 'eventmachine'
29
- require 'test/unit'
3
+ class TestDefer < Test::Unit::TestCase
30
4
 
31
- unless RUBY_VERSION >= '1.9.0'
32
- class TestDeferUsage < Test::Unit::TestCase
33
-
34
- def test_defers
35
- n = 0
36
- n_times = 20
37
- EM.run {
38
- n_times.times {
39
- work_proc = proc { n += 1 }
40
- callback = proc { EM.stop if n == n_times }
41
- EM.defer work_proc, callback
42
- }
5
+ def test_defers
6
+ n = 0
7
+ n_times = 20
8
+ EM.run {
9
+ n_times.times {
10
+ work_proc = proc { n += 1 }
11
+ callback = proc { EM.stop if n == n_times }
12
+ EM.defer work_proc, callback
43
13
  }
44
- assert_equal( n, n_times )
45
- end
46
-
14
+ }
15
+ assert_equal( n, n_times )
47
16
  end
48
- end
49
17
 
18
+ end
@@ -1,6 +1,4 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
1
+ require 'em_test_helper'
4
2
 
5
3
  class TestDeferrable < Test::Unit::TestCase
6
4
  class Later
@@ -8,28 +6,30 @@ class TestDeferrable < Test::Unit::TestCase
8
6
  end
9
7
 
10
8
  def test_timeout_without_args
11
- $args = "unset"
12
-
13
- EM.run {
14
- df = Later.new
15
- df.timeout(0.2)
16
- df.errback { $args = "none" }
17
- EM.add_timer(0.5) { EM.stop }
18
- }
19
-
20
- assert_equal("none", $args)
9
+ assert_nothing_raised do
10
+ EM.run {
11
+ df = Later.new
12
+ df.timeout(0)
13
+ df.errback { EM.stop }
14
+ EM.add_timer(0.01) { flunk "Deferrable was not timed out." }
15
+ }
16
+ end
21
17
  end
22
18
 
23
19
  def test_timeout_with_args
24
- $args = "unset"
20
+ args = nil
25
21
 
26
22
  EM.run {
27
23
  df = Later.new
28
- df.timeout(0.2, :timeout, :foo)
29
- df.errback { |type, name| $args = [type, name] }
30
- EM.add_timer(0.5) { EM.stop }
24
+ df.timeout(0, :timeout, :foo)
25
+ df.errback do |type, name|
26
+ args = [type, name]
27
+ EM.stop
28
+ end
29
+
30
+ EM.add_timer(0.01) { flunk "Deferrable was not timed out." }
31
31
  }
32
32
 
33
- assert_equal([:timeout, :foo], $args)
33
+ assert_equal [:timeout, :foo], args
34
34
  end
35
- end
35
+ end
data/tests/test_epoll.rb CHANGED
@@ -1,35 +1,4 @@
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
- # TODO, and I know this doesn't belong here, but if a datagram calls
27
- # send_data outside of a receive_data, there is no return address, and
28
- # the result is a very confusing error message.
29
- #
30
-
31
- require 'eventmachine'
32
- require 'test/unit'
1
+ require 'em_test_helper'
33
2
 
34
3
 
35
4
  class TestEpoll < Test::Unit::TestCase
@@ -56,16 +25,19 @@ class TestEpoll < Test::Unit::TestCase
56
25
  end
57
26
 
58
27
 
59
- # We can set the rlimit/nofile of a process but we can only set it
60
- # higher if we're running as root.
61
- # On most systems, the default value is 1024.
62
- # Java doesn't (currently) implement this.
63
- def test_rlimit
64
- unless RUBY_PLATFORM =~ /java/ or EM.set_descriptor_table_size >= 1024
65
- a = EM.set_descriptor_table_size
66
- assert( a <= 1024 )
67
- a = EM.set_descriptor_table_size( 1024 )
68
- assert( a == 1024 )
28
+ if windows? || jruby?
29
+ warn "EM.set_descriptor_table_size not implemented, skipping test in #{__FILE__}"
30
+ else
31
+ # We can set the rlimit/nofile of a process but we can only set it
32
+ # higher if we're running as root.
33
+ # On most systems, the default value is 1024.
34
+ def test_rlimit
35
+ unless EM.set_descriptor_table_size >= 1024
36
+ a = EM.set_descriptor_table_size
37
+ assert( a <= 1024 )
38
+ a = EM.set_descriptor_table_size( 1024 )
39
+ assert( a == 1024 )
40
+ end
69
41
  end
70
42
  end
71
43
 
@@ -90,16 +62,9 @@ class TestEpoll < Test::Unit::TestCase
90
62
  assert_equal(100, $max)
91
63
  end
92
64
 
93
- def test_defer
94
- n = 0
95
- work_proc = proc {n += 1}
96
- callback_proc = proc {EM.stop}
97
- EM.run {
98
- EM.defer work_proc, callback_proc
99
- }
100
- assert_equal( 1, n )
101
- end unless RUBY_VERSION >= '1.9.0'
102
-
65
+ def setup
66
+ @port = next_port
67
+ end
103
68
 
104
69
  module TestDatagramServer
105
70
  def receive_data dgm
@@ -108,9 +73,14 @@ class TestEpoll < Test::Unit::TestCase
108
73
  end
109
74
  end
110
75
  module TestDatagramClient
76
+ def initialize port
77
+ @port = port
78
+ end
79
+
111
80
  def post_init
112
- send_datagram "1234567890", "127.0.0.1", 9500
81
+ send_datagram "1234567890", "127.0.0.1", @port
113
82
  end
83
+
114
84
  def receive_data dgm
115
85
  $out = dgm
116
86
  EM.stop
@@ -120,8 +90,8 @@ class TestEpoll < Test::Unit::TestCase
120
90
  def test_datagrams
121
91
  $in = $out = ""
122
92
  EM.run {
123
- EM.open_datagram_socket "127.0.0.1", 9500, TestDatagramServer
124
- EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient
93
+ EM.open_datagram_socket "127.0.0.1", @port, TestDatagramServer
94
+ EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient, @port
125
95
  }
126
96
  assert_equal( "1234567890", $in )
127
97
  assert_equal( "abcdefghij", $out )