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
@@ -1,32 +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
-
27
- $:.unshift "../lib"
28
- require 'eventmachine'
29
- require 'test/unit'
1
+ require 'em_test_helper'
30
2
 
31
3
  class TestRunning < Test::Unit::TestCase
32
4
  def test_running
data/tests/test_sasl.rb CHANGED
@@ -1,32 +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
-
27
- $:.unshift "../lib"
28
- require 'eventmachine'
29
- require 'test/unit'
1
+ require 'em_test_helper'
30
2
 
31
3
 
32
4
  class TestSASL < Test::Unit::TestCase
@@ -35,7 +7,6 @@ class TestSASL < Test::Unit::TestCase
35
7
  # we'll use TCP so this test will work on Windows. As far as the
36
8
  # protocol handlers are concerned, there's no difference.
37
9
 
38
- Host,Port = "127.0.0.1",9560
39
10
  TestUser,TestPsw = "someone", "password"
40
11
 
41
12
  class SaslServer < EM::Connection
@@ -49,12 +20,16 @@ class TestSASL < Test::Unit::TestCase
49
20
  include EM::Protocols::SASLauthclient
50
21
  end
51
22
 
23
+ def setup
24
+ @port = next_port
25
+ end
26
+
52
27
  def test_sasl
53
28
  resp = nil
54
29
  EM.run {
55
- EM.start_server( Host, Port, SaslServer )
30
+ EM.start_server( "127.0.0.1", @port, SaslServer )
56
31
 
57
- c = EM.connect( Host, Port, SaslClient )
32
+ c = EM.connect( "127.0.0.1", @port, SaslClient )
58
33
  d = c.validate?( TestUser, TestPsw )
59
34
  d.timeout 1
60
35
  d.callback {
@@ -1,251 +1,217 @@
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 'socket'
30
- require 'test/unit'
1
+ require 'em_test_helper'
2
+ require 'tempfile'
31
3
 
32
4
  class TestSendFile < Test::Unit::TestCase
33
5
 
34
- module TestModule
35
- def post_init
36
- send_file_data TestFilename
37
- close_connection_after_writing
38
- end
39
- end
6
+ if EM.respond_to?(:send_file_data)
7
+ module TestModule
8
+ def initialize filename
9
+ @filename = filename
10
+ end
40
11
 
41
- module TestClient
42
- def data_to(&blk)
43
- @data_to = blk
44
- end
45
-
46
- def receive_data(data)
47
- @data_to.call(data) if @data_to
48
- end
49
-
50
- def unbind
51
- EM.stop
12
+ def post_init
13
+ send_file_data @filename
14
+ close_connection_after_writing
15
+ end
52
16
  end
53
- end
54
-
55
- TestHost = "0.0.0.0"
56
- TestPort = 9055
57
- TestFilename = "./xxxxxx"
58
-
59
- def setup
60
- end
61
17
 
62
- def teardown
63
- File.unlink( TestFilename ) if File.exist?( TestFilename )
64
- end
65
-
66
- def setup_timeout(timeout = 4)
67
- EM.schedule {
68
- start_time = EM.current_time
69
- EM.add_periodic_timer(0.01) {
70
- raise "timeout" if EM.current_time - start_time >= timeout
71
- }
72
- }
73
- end
74
-
75
- def test_send_file
76
- File.open( TestFilename, "w" ) {|f|
77
- f << ("A" * 5000)
78
- }
79
-
80
- data = ''
18
+ module TestClient
19
+ def data_to(&blk)
20
+ @data_to = blk
21
+ end
81
22
 
82
- EM.run {
83
- EM.start_server TestHost, TestPort, TestModule
84
- setup_timeout
23
+ def receive_data(data)
24
+ @data_to.call(data) if @data_to
25
+ end
85
26
 
86
- EM.connect TestHost, TestPort, TestClient do |c|
87
- c.data_to { |d| data << d }
27
+ def unbind
28
+ EM.stop
88
29
  end
89
- }
30
+ end
90
31
 
91
- assert_equal( "A" * 5000, data )
92
- File.unlink TestFilename
93
- end
32
+ def setup
33
+ @file = Tempfile.new("em_test_file")
34
+ @filename = @file.path
35
+ @port = next_port
36
+ end
94
37
 
95
- # EventMachine::Connection#send_file_data has a strict upper limit on the filesize it will work with.
96
- def test_send_large_file
97
- File.open( TestFilename, "w" ) {|f|
98
- f << ("A" * 1000000)
99
- }
38
+ def test_send_file
39
+ File.open( @filename, "w" ) {|f|
40
+ f << ("A" * 5000)
41
+ }
100
42
 
101
- data = ''
43
+ data = ''
102
44
 
103
- ex_class = RUBY_PLATFORM == 'java' ? NativeException : RuntimeError
104
- assert_raises( ex_class ) {
105
45
  EM.run {
106
- EM.start_server TestHost, TestPort, TestModule
46
+ EM.start_server "127.0.0.1", @port, TestModule, @filename
107
47
  setup_timeout
108
- EM.connect TestHost, TestPort, TestClient do |c|
48
+
49
+ EM.connect "127.0.0.1", @port, TestClient do |c|
109
50
  c.data_to { |d| data << d }
110
51
  end
111
52
  }
112
- }
113
-
114
- File.unlink TestFilename
115
- end
116
53
 
54
+ assert_equal( "A" * 5000, data )
55
+ end
117
56
 
118
- module StreamTestModule
119
- def post_init
120
- EM::Deferrable.future( stream_file_data(TestFilename)) {
121
- close_connection_after_writing
57
+ # EM::Connection#send_file_data has a strict upper limit on the filesize it will work with.
58
+ def test_send_large_file
59
+ File.open( @filename, "w" ) {|f|
60
+ f << ("A" * 1000000)
122
61
  }
123
- end
124
- end
125
62
 
126
- module ChunkStreamTestModule
127
- def post_init
128
- EM::Deferrable.future( stream_file_data(TestFilename, :http_chunks=>true)) {
129
- close_connection_after_writing
63
+ data = ''
64
+
65
+ assert_raises(RuntimeError) {
66
+ EM.run {
67
+ EM.start_server "127.0.0.1", @port, TestModule, @filename
68
+ setup_timeout
69
+ EM.connect "127.0.0.1", @port, TestClient do |c|
70
+ c.data_to { |d| data << d }
71
+ end
72
+ }
130
73
  }
131
74
  end
132
- end
133
75
 
134
- def test_stream_file_data
135
- File.open( TestFilename, "w" ) {|f|
136
- f << ("A" * 1000)
137
- }
76
+ module StreamTestModule
77
+ def initialize filename
78
+ @filename = filename
79
+ end
138
80
 
139
- data = ''
81
+ def post_init
82
+ EM::Deferrable.future( stream_file_data(@filename)) {
83
+ close_connection_after_writing
84
+ }
85
+ end
86
+ end
140
87
 
141
- EM.run {
142
- EM.start_server TestHost, TestPort, StreamTestModule
143
- setup_timeout
144
- EM.connect TestHost, TestPort, TestClient do |c|
145
- c.data_to { |d| data << d }
88
+ module ChunkStreamTestModule
89
+ def initialize filename
90
+ @filename = filename
146
91
  end
147
- }
148
92
 
149
- assert_equal( "A" * 1000, data )
93
+ def post_init
94
+ EM::Deferrable.future( stream_file_data(@filename, :http_chunks=>true)) {
95
+ close_connection_after_writing
96
+ }
97
+ end
98
+ end
150
99
 
151
- File.unlink TestFilename
152
- end
100
+ def test_stream_file_data
101
+ File.open( @filename, "w" ) {|f|
102
+ f << ("A" * 1000)
103
+ }
153
104
 
154
- def test_stream_chunked_file_data
155
- File.open( TestFilename, "w" ) {|f|
156
- f << ("A" * 1000)
157
- }
105
+ data = ''
158
106
 
159
- data = ''
107
+ EM.run {
108
+ EM.start_server "127.0.0.1", @port, StreamTestModule, @filename
109
+ setup_timeout
110
+ EM.connect "127.0.0.1", @port, TestClient do |c|
111
+ c.data_to { |d| data << d }
112
+ end
113
+ }
160
114
 
161
- EM.run {
162
- EM.start_server TestHost, TestPort, ChunkStreamTestModule
163
- setup_timeout
164
- EM.connect TestHost, TestPort, TestClient do |c|
165
- c.data_to { |d| data << d }
166
- end
167
- }
115
+ assert_equal( "A" * 1000, data )
116
+ end
168
117
 
169
- assert_equal( "3e8\r\n#{"A" * 1000}\r\n0\r\n\r\n", data )
118
+ def test_stream_chunked_file_data
119
+ File.open( @filename, "w" ) {|f|
120
+ f << ("A" * 1000)
121
+ }
170
122
 
171
- File.unlink TestFilename
172
- end
123
+ data = ''
173
124
 
174
- module BadFileTestModule
175
- def post_init
176
- de = stream_file_data( TestFilename+"..." )
177
- de.errback {|msg|
178
- send_data msg
179
- close_connection_after_writing
125
+ EM.run {
126
+ EM.start_server "127.0.0.1", @port, ChunkStreamTestModule, @filename
127
+ setup_timeout
128
+ EM.connect "127.0.0.1", @port, TestClient do |c|
129
+ c.data_to { |d| data << d }
130
+ end
180
131
  }
132
+
133
+ assert_equal( "3e8\r\n#{"A" * 1000}\r\n0\r\n\r\n", data )
181
134
  end
182
- end
183
- def test_stream_bad_file
184
- data = ''
185
- EM.run {
186
- EM.start_server TestHost, TestPort, BadFileTestModule
187
- setup_timeout
188
- EM.connect TestHost, TestPort, TestClient do |c|
189
- c.data_to { |d| data << d }
135
+
136
+ module BadFileTestModule
137
+ def initialize filename
138
+ @filename = filename
190
139
  end
191
- }
192
140
 
193
- assert_equal( "file not found", data )
194
- end
141
+ def post_init
142
+ de = stream_file_data( @filename+".wrong" )
143
+ de.errback {|msg|
144
+ send_data msg
145
+ close_connection_after_writing
146
+ }
147
+ end
148
+ end
149
+ def test_stream_bad_file
150
+ data = ''
151
+ EM.run {
152
+ EM.start_server "127.0.0.1", @port, BadFileTestModule, @filename
153
+ setup_timeout(5)
154
+ EM.connect "127.0.0.1", @port, TestClient do |c|
155
+ c.data_to { |d| data << d }
156
+ end
157
+ }
195
158
 
196
- def test_stream_large_file_data
197
- begin
198
- require 'fastfilereaderext'
199
- rescue LoadError
200
- return
159
+ assert_equal( "file not found", data )
201
160
  end
202
- File.open( TestFilename, "w" ) {|f|
203
- f << ("A" * 10000)
204
- }
161
+ else
162
+ warn "EM.send_file_data not implemented, skipping tests in #{__FILE__}"
205
163
 
206
- data = ''
164
+ # Because some rubies will complain if a TestCase class has no tests
165
+ def test_em_send_file_data_not_implemented
166
+ assert !EM.respond_to?(:send_file_data)
167
+ end
168
+ end
207
169
 
208
- EM.run {
209
- EM.start_server TestHost, TestPort, StreamTestModule
210
- setup_timeout
211
- EM.connect TestHost, TestPort, TestClient do |c|
212
- c.data_to { |d| data << d }
213
- end
214
- }
170
+ begin
171
+ require 'fastfilereaderext'
172
+
173
+ def test_stream_large_file_data
174
+ File.open( @filename, "w" ) {|f|
175
+ f << ("A" * 10000)
176
+ }
215
177
 
216
- assert_equal( "A" * 10000, data )
178
+ data = ''
217
179
 
218
- File.unlink TestFilename
219
- end
180
+ EM.run {
181
+ EM.start_server "127.0.0.1", @port, StreamTestModule, @filename
182
+ setup_timeout
183
+ EM.connect "127.0.0.1", @port, TestClient do |c|
184
+ c.data_to { |d| data << d }
185
+ end
186
+ }
220
187
 
221
- def test_stream_large_chunked_file_data
222
- begin
223
- require 'fastfilereaderext'
224
- rescue LoadError
225
- return
188
+ assert_equal( "A" * 10000, data )
226
189
  end
227
- File.open( TestFilename, "w" ) {|f|
228
- f << ("A" * 100000)
229
- }
230
190
 
231
- data = ''
191
+ def test_stream_large_chunked_file_data
192
+ File.open( @filename, "w" ) {|f|
193
+ f << ("A" * 100000)
194
+ }
232
195
 
233
- EM.run {
234
- EM.start_server TestHost, TestPort, ChunkStreamTestModule
235
- setup_timeout
236
- EM.connect TestHost, TestPort, TestClient do |c|
237
- c.data_to { |d| data << d }
238
- end
239
- }
196
+ data = ''
240
197
 
241
- expected = [
242
- "4000\r\n#{"A" * 16384}\r\n" * 6,
243
- "6a0\r\n#{"A" * 0x6a0}\r\n",
244
- "0\r\n\r\n"
245
- ].join
246
- assert_equal( expected, data )
198
+ EM.run {
199
+ EM.start_server "127.0.0.1", @port, ChunkStreamTestModule, @filename
200
+ setup_timeout
201
+ EM.connect "127.0.0.1", @port, TestClient do |c|
202
+ c.data_to { |d| data << d }
203
+ end
204
+ }
247
205
 
248
- File.unlink TestFilename
206
+ expected = [
207
+ "4000\r\n#{"A" * 16384}\r\n" * 6,
208
+ "6a0\r\n#{"A" * 0x6a0}\r\n",
209
+ "0\r\n\r\n"
210
+ ].join
211
+ assert_equal( expected, data )
212
+ end
213
+ rescue LoadError
214
+ warn "require 'fastfilereaderext' failed, skipping tests in #{__FILE__}"
249
215
  end
250
216
 
251
217
  end