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
data/tests/test_servers.rb
CHANGED
@@ -1,76 +1,33 @@
|
|
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'
|
1
|
+
require 'em_test_helper'
|
29
2
|
require 'socket'
|
30
|
-
require 'test/unit'
|
31
3
|
|
32
4
|
class TestServers < Test::Unit::TestCase
|
33
5
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
module NetstatHelper
|
38
|
-
GlobalUdp4Rexp = /udp.*\s+(?:\*|(?:0\.){3}0)[:.](\d+)\s/i
|
39
|
-
GlobalTcp4Rexp = /tcp.*\s+(?:\*|(?:0\.){3}0)[:.](\d+)\s/i
|
40
|
-
LocalUdpRexp = /udp.*\s+(?:127\.0\.0\.1|::1)[:.](\d+)\s/i
|
41
|
-
LocalTcpRexp = /tcp.*\s+(?:127\.0\.0\.1|::1)[:.](\d+)\s/i
|
42
|
-
def grep_netstat(pattern)
|
43
|
-
`netstat -an`.scan(/^.*$/).grep(pattern)
|
44
|
-
end
|
6
|
+
def setup
|
7
|
+
@port = next_port
|
45
8
|
end
|
46
|
-
include NetstatHelper
|
47
9
|
|
48
|
-
|
49
|
-
|
50
|
-
super
|
51
|
-
end
|
52
|
-
def post_init
|
53
|
-
# TODO,sucks that this isn't OOPy enough.
|
54
|
-
EM.stop_server @server_instance
|
55
|
-
end
|
10
|
+
def server_alive?
|
11
|
+
port_in_use?(@port)
|
56
12
|
end
|
57
13
|
|
58
14
|
def run_test_stop_server
|
59
15
|
EM.run {
|
60
|
-
sig = EM.start_server(
|
61
|
-
assert
|
16
|
+
sig = EM.start_server("127.0.0.1", @port)
|
17
|
+
assert server_alive?, "Server didn't start"
|
62
18
|
EM.stop_server sig
|
63
19
|
# Give the server some time to shutdown.
|
64
|
-
EM.add_timer(0.
|
65
|
-
assert
|
20
|
+
EM.add_timer(0.1) {
|
21
|
+
assert !server_alive?, "Server didn't stop"
|
66
22
|
EM.stop
|
67
23
|
}
|
68
24
|
}
|
69
25
|
end
|
26
|
+
|
70
27
|
def test_stop_server
|
71
|
-
assert
|
72
|
-
|
73
|
-
assert
|
28
|
+
assert !server_alive?, "Port already in use"
|
29
|
+
2.times { run_test_stop_server }
|
30
|
+
assert !server_alive?, "Servers didn't stop"
|
74
31
|
end
|
75
32
|
|
76
33
|
end
|
data/tests/test_smtpclient.rb
CHANGED
@@ -1,32 +1,4 @@
|
|
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 TestSmtpClient < Test::Unit::TestCase
|
32
4
|
|
data/tests/test_smtpserver.rb
CHANGED
@@ -1,32 +1,4 @@
|
|
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 TestSmtpServer < Test::Unit::TestCase
|
32
4
|
|
data/tests/test_spawn.rb
CHANGED
@@ -1,34 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
-
# Homepage:: http://rubyeventmachine.com
|
5
|
-
# Date:: 25 Aug 2007
|
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
|
-
|
28
|
-
|
29
|
-
$:.unshift "../lib"
|
30
|
-
require 'eventmachine'
|
31
|
-
require 'test/unit'
|
1
|
+
|
2
|
+
require 'em_test_helper'
|
32
3
|
|
33
4
|
|
34
5
|
|
data/tests/test_ssl_args.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require "test/unit"
|
2
2
|
require 'tempfile'
|
3
3
|
|
4
|
-
|
5
|
-
require "eventmachine"
|
4
|
+
require 'em_test_helper'
|
6
5
|
|
7
|
-
module
|
6
|
+
module EM
|
8
7
|
def self._set_mocks
|
9
8
|
class <<self
|
10
9
|
alias set_tls_parms_old set_tls_parms
|
@@ -36,11 +35,11 @@ end
|
|
36
35
|
|
37
36
|
class TestSslArgs < Test::Unit::TestCase
|
38
37
|
def setup
|
39
|
-
|
38
|
+
EM._set_mocks
|
40
39
|
end
|
41
40
|
|
42
41
|
def teardown
|
43
|
-
|
42
|
+
EM._clear_mocks
|
44
43
|
end
|
45
44
|
|
46
45
|
def test_tls_params_file_doesnt_exist
|
@@ -50,15 +49,15 @@ class TestSslArgs < Test::Unit::TestCase
|
|
50
49
|
end
|
51
50
|
|
52
51
|
# associate_callback_target is a pain! (build!)
|
53
|
-
conn =
|
52
|
+
conn = EM::Connection.new('foo')
|
54
53
|
|
55
|
-
assert_raises(
|
54
|
+
assert_raises(EM::FileNotFoundException) do
|
56
55
|
conn.start_tls(:private_key_file => priv_file)
|
57
56
|
end
|
58
|
-
assert_raises(
|
57
|
+
assert_raises(EM::FileNotFoundException) do
|
59
58
|
conn.start_tls(:cert_chain_file => cert_file)
|
60
59
|
end
|
61
|
-
assert_raises(
|
60
|
+
assert_raises(EM::FileNotFoundException) do
|
62
61
|
conn.start_tls(:private_key_file => priv_file, :cert_chain_file => cert_file)
|
63
62
|
end
|
64
63
|
end
|
@@ -68,7 +67,7 @@ class TestSslArgs < Test::Unit::TestCase
|
|
68
67
|
cert_file = Tempfile.new('em_test')
|
69
68
|
priv_file_path = priv_file.path
|
70
69
|
cert_file_path = cert_file.path
|
71
|
-
conn =
|
70
|
+
conn = EM::Connection.new('foo')
|
72
71
|
params = {:private_key_file => priv_file_path, :cert_chain_file => cert_file_path}
|
73
72
|
begin
|
74
73
|
conn.start_tls params
|
data/tests/test_ssl_methods.rb
CHANGED
data/tests/test_ssl_verify.rb
CHANGED
@@ -1,82 +1,82 @@
|
|
1
|
-
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
module Client
|
13
|
-
def connection_completed
|
14
|
-
start_tls(:private_key_file => $dir+'client.key', :cert_chain_file => $dir+'client.crt')
|
3
|
+
if EM.ssl?
|
4
|
+
class TestSslVerify < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
$dir = File.dirname(File.expand_path(__FILE__)) + '/'
|
7
|
+
$cert_from_file = File.read($dir+'client.crt')
|
15
8
|
end
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
module Client
|
11
|
+
def connection_completed
|
12
|
+
start_tls(:private_key_file => $dir+'client.key', :cert_chain_file => $dir+'client.crt')
|
13
|
+
end
|
21
14
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
15
|
+
def ssl_handshake_completed
|
16
|
+
$client_handshake_completed = true
|
17
|
+
close_connection
|
18
|
+
end
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
|
20
|
+
def unbind
|
21
|
+
EM.stop_event_loop
|
22
|
+
end
|
30
23
|
end
|
31
24
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
module AcceptServer
|
26
|
+
def post_init
|
27
|
+
start_tls(:verify_peer => true)
|
28
|
+
end
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
30
|
+
def ssl_verify_peer(cert)
|
31
|
+
$cert_from_server = cert
|
32
|
+
true
|
33
|
+
end
|
41
34
|
|
42
|
-
|
43
|
-
|
44
|
-
|
35
|
+
def ssl_handshake_completed
|
36
|
+
$server_handshake_completed = true
|
37
|
+
end
|
45
38
|
end
|
46
39
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
40
|
+
module DenyServer
|
41
|
+
def post_init
|
42
|
+
start_tls(:verify_peer => true)
|
43
|
+
end
|
52
44
|
|
53
|
-
|
54
|
-
|
45
|
+
def ssl_verify_peer(cert)
|
46
|
+
$cert_from_server = cert
|
47
|
+
# Do not accept the peer. This should now cause the connection to shut down without the SSL handshake being completed.
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
def ssl_handshake_completed
|
52
|
+
$server_handshake_completed = true
|
53
|
+
end
|
55
54
|
end
|
56
|
-
end
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
def test_accept_server
|
57
|
+
$client_handshake_completed, $server_handshake_completed = false, false
|
58
|
+
EM.run {
|
59
|
+
EM.start_server("127.0.0.1", 16784, AcceptServer)
|
60
|
+
EM.connect("127.0.0.1", 16784, Client).instance_variable_get("@signature")
|
61
|
+
}
|
64
62
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
assert_equal($cert_from_file, $cert_from_server)
|
64
|
+
assert($client_handshake_completed)
|
65
|
+
assert($server_handshake_completed)
|
66
|
+
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
def test_deny_server
|
69
|
+
$client_handshake_completed, $server_handshake_completed = false, false
|
70
|
+
EM.run {
|
71
|
+
EM.start_server("127.0.0.1", 16784, DenyServer)
|
72
|
+
EM.connect("127.0.0.1", 16784, Client)
|
73
|
+
}
|
76
74
|
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
assert_equal($cert_from_file, $cert_from_server)
|
76
|
+
assert(!$client_handshake_completed)
|
77
|
+
assert(!$server_handshake_completed)
|
78
|
+
end
|
80
79
|
end
|
81
|
-
|
80
|
+
else
|
81
|
+
warn "EM built without SSL support, skipping tests in #{__FILE__}"
|
82
82
|
end
|
data/tests/test_tick_loop.rb
CHANGED
data/tests/test_timers.rb
CHANGED
@@ -1,42 +1,13 @@
|
|
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
|
-
|
28
|
-
$:.unshift "../lib"
|
29
|
-
require 'eventmachine'
|
30
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
31
2
|
|
32
3
|
class TestTimers < Test::Unit::TestCase
|
33
4
|
|
34
5
|
def test_timer_with_block
|
35
6
|
x = false
|
36
|
-
|
37
|
-
|
7
|
+
EM.run {
|
8
|
+
EM::Timer.new(0) {
|
38
9
|
x = true
|
39
|
-
|
10
|
+
EM.stop
|
40
11
|
}
|
41
12
|
}
|
42
13
|
assert x
|
@@ -44,117 +15,109 @@ class TestTimers < Test::Unit::TestCase
|
|
44
15
|
|
45
16
|
def test_timer_with_proc
|
46
17
|
x = false
|
47
|
-
|
48
|
-
|
18
|
+
EM.run {
|
19
|
+
EM::Timer.new(0, proc {
|
49
20
|
x = true
|
50
|
-
|
21
|
+
EM.stop
|
51
22
|
})
|
52
23
|
}
|
53
24
|
assert x
|
54
25
|
end
|
55
26
|
|
56
27
|
def test_timer_cancel
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
28
|
+
assert_nothing_raised do
|
29
|
+
EM.run {
|
30
|
+
timer = EM::Timer.new(0.01) { flunk "Timer was not cancelled." }
|
31
|
+
timer.cancel
|
32
|
+
|
33
|
+
EM.add_timer(0.02) { EM.stop }
|
34
|
+
}
|
35
|
+
end
|
64
36
|
end
|
65
37
|
|
66
38
|
def test_periodic_timer
|
67
39
|
x = 0
|
68
|
-
|
69
|
-
|
40
|
+
EM.run {
|
41
|
+
EM::PeriodicTimer.new(0.01) do
|
70
42
|
x += 1
|
71
|
-
|
43
|
+
EM.stop if x == 4
|
72
44
|
end
|
73
45
|
}
|
74
|
-
|
46
|
+
|
47
|
+
assert_equal 4, x
|
75
48
|
end
|
76
49
|
|
77
50
|
def test_add_periodic_timer
|
78
51
|
x = 0
|
79
52
|
EM.run {
|
80
|
-
t = EM.add_periodic_timer(0.
|
53
|
+
t = EM.add_periodic_timer(0.01) do
|
81
54
|
x += 1
|
82
55
|
EM.stop if x == 4
|
83
56
|
end
|
84
57
|
assert t.respond_to?(:cancel)
|
85
58
|
}
|
59
|
+
assert_equal 4, x
|
86
60
|
end
|
87
61
|
|
88
62
|
def test_periodic_timer_cancel
|
89
63
|
x = 0
|
90
|
-
|
91
|
-
pt =
|
64
|
+
EM.run {
|
65
|
+
pt = EM::PeriodicTimer.new(0.01) { x += 1 }
|
92
66
|
pt.cancel
|
93
|
-
|
67
|
+
EM::Timer.new(0.02) { EM.stop }
|
94
68
|
}
|
95
|
-
|
69
|
+
assert_equal 0, x
|
96
70
|
end
|
97
71
|
|
98
72
|
def test_add_periodic_timer_cancel
|
99
73
|
x = 0
|
100
|
-
|
101
|
-
pt = EM.add_periodic_timer(0.
|
74
|
+
EM.run {
|
75
|
+
pt = EM.add_periodic_timer(0.01) { x += 1 }
|
102
76
|
EM.cancel_timer(pt)
|
103
|
-
EM.add_timer(0.
|
77
|
+
EM.add_timer(0.02) { EM.stop }
|
104
78
|
}
|
105
|
-
|
79
|
+
assert_equal 0, x
|
106
80
|
end
|
107
81
|
|
108
82
|
def test_periodic_timer_self_cancel
|
109
83
|
x = 0
|
110
|
-
|
111
|
-
pt =
|
84
|
+
EM.run {
|
85
|
+
pt = EM::PeriodicTimer.new(0) {
|
112
86
|
x += 1
|
113
87
|
if x == 4
|
114
88
|
pt.cancel
|
115
|
-
|
89
|
+
EM.stop
|
116
90
|
end
|
117
91
|
}
|
118
92
|
}
|
119
|
-
|
93
|
+
assert_equal 4, x
|
120
94
|
end
|
121
95
|
|
122
96
|
|
123
97
|
# This test is only applicable to compiled versions of the reactor.
|
124
98
|
# Pure ruby and java versions have no built-in limit on the number of outstanding timers.
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
99
|
+
unless [:pure_ruby, :java].include? EM.library_type
|
100
|
+
def test_timer_change_max_outstanding
|
101
|
+
defaults = EM.get_max_timers
|
102
|
+
EM.set_max_timers(100)
|
103
|
+
|
104
|
+
one_hundred_one_timers = lambda do
|
105
|
+
101.times { EM.add_timer(0.01) {} }
|
106
|
+
EM.stop
|
107
|
+
end
|
131
108
|
|
132
|
-
|
133
|
-
|
134
|
-
one_hundred_one_timers.call
|
135
|
-
elsif EM.library_type == :java
|
136
|
-
one_hundred_one_timers.call
|
137
|
-
else
|
138
|
-
begin
|
139
|
-
assert_raises( RuntimeError ) {
|
140
|
-
one_hundred_one_timers.call
|
141
|
-
}
|
142
|
-
rescue Object
|
143
|
-
p $!
|
144
|
-
assert(false, $!.message)
|
145
|
-
end
|
109
|
+
assert_raises(RuntimeError) do
|
110
|
+
EM.run( &one_hundred_one_timers )
|
146
111
|
end
|
147
|
-
EM.stop
|
148
|
-
}
|
149
112
|
|
150
|
-
|
113
|
+
EM.set_max_timers( 101 )
|
151
114
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
115
|
+
assert_nothing_raised do
|
116
|
+
EM.run( &one_hundred_one_timers )
|
117
|
+
end
|
118
|
+
ensure
|
119
|
+
EM.set_max_timers(defaults)
|
120
|
+
end
|
158
121
|
end
|
159
122
|
|
160
123
|
end
|