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.
- data/.yardopts +3 -0
- data/Gemfile +1 -0
- data/eventmachine.gemspec +1 -3
- data/ext/cmain.cpp +4 -4
- data/ext/ed.cpp +13 -16
- data/ext/ed.h +9 -10
- data/ext/em.cpp +14 -24
- data/ext/eventmachine.h +2 -2
- data/ext/extconf.rb +1 -1
- data/ext/rubymain.cpp +8 -6
- data/lib/em/connection.rb +3 -1
- data/lib/em/pure_ruby.rb +17 -17
- data/lib/em/resolver.rb +186 -0
- data/lib/em/spawnable.rb +3 -7
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +6 -4
- data/lib/jeventmachine.rb +1 -1
- data/tasks/package.rake +4 -1
- data/tasks/test.rake +1 -0
- data/tests/em_test_helper.rb +55 -0
- data/tests/test_attach.rb +46 -56
- data/tests/test_basic.rb +74 -96
- data/tests/test_channel.rb +2 -4
- data/tests/test_connection_count.rb +1 -3
- data/tests/test_defer.rb +13 -44
- data/tests/test_deferrable.rb +19 -19
- data/tests/test_epoll.rb +25 -55
- data/tests/test_error_handler.rb +10 -7
- data/tests/test_exc.rb +6 -33
- data/tests/test_file_watch.rb +51 -35
- data/tests/test_futures.rb +9 -37
- data/tests/test_get_sock_opt.rb +27 -20
- data/tests/test_handler_check.rb +1 -3
- data/tests/test_hc.rb +24 -59
- data/tests/test_httpclient.rb +27 -64
- data/tests/test_httpclient2.rb +1 -29
- data/tests/test_inactivity_timeout.rb +44 -40
- data/tests/test_kb.rb +26 -52
- data/tests/test_ltp.rb +23 -67
- data/tests/test_ltp2.rb +1 -30
- data/tests/test_next_tick.rb +1 -30
- data/tests/test_object_protocol.rb +8 -9
- data/tests/test_pause.rb +45 -37
- data/tests/test_pending_connect_timeout.rb +42 -38
- data/tests/test_process_watch.rb +1 -3
- data/tests/test_processes.rb +92 -110
- data/tests/test_proxy_connection.rb +128 -104
- data/tests/test_pure.rb +29 -75
- data/tests/test_queue.rb +2 -4
- data/tests/test_resolver.rb +55 -0
- data/tests/test_running.rb +1 -29
- data/tests/test_sasl.rb +7 -32
- data/tests/test_send_file.rb +162 -196
- data/tests/test_servers.rb +13 -56
- data/tests/test_smtpclient.rb +1 -29
- data/tests/test_smtpserver.rb +1 -29
- data/tests/test_spawn.rb +2 -31
- data/tests/test_ssl_args.rb +9 -10
- data/tests/test_ssl_methods.rb +1 -3
- data/tests/test_ssl_verify.rb +63 -63
- data/tests/test_tick_loop.rb +1 -1
- data/tests/test_timers.rb +52 -89
- data/tests/test_ud.rb +1 -29
- metadata +20 -10
- data/setup.rb +0 -1585
- data/tests/test_errors.rb +0 -82
- data/tests/testem.rb +0 -31
@@ -1,144 +1,168 @@
|
|
1
|
-
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
4
2
|
|
5
3
|
class TestProxyConnection < Test::Unit::TestCase
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def post_init
|
12
|
+
EM::enable_proxy(self, @client)
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
def connection_completed
|
16
|
+
EM.next_tick {
|
17
|
+
send_data @request
|
18
|
+
}
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
def proxy_target_unbound
|
22
|
+
$unbound_early = true
|
23
|
+
EM.stop
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
26
|
+
def unbind
|
27
|
+
@client.close_connection_after_writing
|
28
|
+
end
|
29
29
|
end
|
30
|
-
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
module PartialProxyConnection
|
32
|
+
def initialize(client, request, length)
|
33
|
+
@client, @request, @length = client, request, length
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def post_init
|
37
|
+
EM::enable_proxy(self, @client, 0, @length)
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def receive_data(data)
|
41
|
+
$unproxied_data = data
|
42
|
+
@client.send_data(data)
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
def connection_completed
|
46
|
+
EM.next_tick {
|
47
|
+
send_data @request
|
48
|
+
}
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
def proxy_target_unbound
|
52
|
+
$unbound_early = true
|
53
|
+
EM.stop
|
54
|
+
end
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
def proxy_completed
|
57
|
+
$proxy_completed = true
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
60
|
+
def unbind
|
61
|
+
@client.close_connection_after_writing
|
62
|
+
end
|
63
63
|
end
|
64
|
-
end
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
72
|
-
|
79
|
+
module Client2
|
80
|
+
include Client
|
81
|
+
def unbind; end
|
73
82
|
end
|
74
83
|
|
75
|
-
|
76
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
91
|
+
module ProxyServer
|
92
|
+
def initialize port
|
93
|
+
@port = port
|
94
|
+
end
|
84
95
|
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
105
|
-
|
106
|
-
|
107
|
-
close_connection
|
122
|
+
def setup
|
123
|
+
@port = next_port
|
124
|
+
@proxy_port = next_port
|
108
125
|
end
|
109
|
-
end
|
110
126
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
119
|
-
|
134
|
+
assert_equal("I know!", $client_data)
|
135
|
+
end
|
120
136
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
144
|
+
assert_equal("I know!", $client_data)
|
145
|
+
assert_equal(" know!", $unproxied_data)
|
146
|
+
assert($proxy_completed)
|
147
|
+
end
|
132
148
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
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
|
data/tests/test_pure.rb
CHANGED
@@ -1,76 +1,36 @@
|
|
1
|
-
|
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
|
-
|
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
|
-
|
92
|
-
EM.
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
data/tests/test_queue.rb
CHANGED
@@ -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
|