sensu-em 2.4.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +12 -0
- data/.yardopts +7 -0
- data/CHANGELOG.md +33 -0
- data/GNU +281 -0
- data/Gemfile +2 -0
- data/LICENSE +60 -0
- data/README.md +109 -0
- data/Rakefile +20 -0
- data/docs/DocumentationGuidesIndex.md +27 -0
- data/docs/GettingStarted.md +521 -0
- data/docs/old/ChangeLog +211 -0
- data/docs/old/DEFERRABLES +246 -0
- data/docs/old/EPOLL +141 -0
- data/docs/old/INSTALL +13 -0
- data/docs/old/KEYBOARD +42 -0
- data/docs/old/LEGAL +25 -0
- data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
- data/docs/old/PURE_RUBY +75 -0
- data/docs/old/RELEASE_NOTES +94 -0
- data/docs/old/SMTP +4 -0
- data/docs/old/SPAWNED_PROCESSES +148 -0
- data/docs/old/TODO +8 -0
- data/eventmachine.gemspec +37 -0
- data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
- data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
- data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
- data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
- data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
- data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
- data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
- data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
- data/examples/old/ex_channel.rb +43 -0
- data/examples/old/ex_queue.rb +2 -0
- data/examples/old/ex_tick_loop_array.rb +15 -0
- data/examples/old/ex_tick_loop_counter.rb +32 -0
- data/examples/old/helper.rb +2 -0
- data/ext/binder.cpp +124 -0
- data/ext/binder.h +46 -0
- data/ext/cmain.cpp +887 -0
- data/ext/ed.cpp +1992 -0
- data/ext/ed.h +424 -0
- data/ext/em.cpp +2352 -0
- data/ext/em.h +253 -0
- data/ext/eventmachine.h +128 -0
- data/ext/extconf.rb +179 -0
- data/ext/fastfilereader/extconf.rb +103 -0
- data/ext/fastfilereader/mapper.cpp +214 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/kb.cpp +79 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +347 -0
- data/ext/project.h +161 -0
- data/ext/rubymain.cpp +1318 -0
- data/ext/ssl.cpp +476 -0
- data/ext/ssl.h +95 -0
- data/java/.classpath +6 -0
- data/java/.gitignore +1 -0
- data/java/.project +17 -0
- data/java/src/com/rubyeventmachine/DatagramPacket.java +13 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +531 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventCallback.java +7 -0
- data/java/src/com/rubyeventmachine/EventCode.java +26 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +130 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +179 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +405 -0
- data/java/src/com/rubyeventmachine/SslBox.java +311 -0
- data/lib/em/buftok.rb +110 -0
- data/lib/em/callback.rb +58 -0
- data/lib/em/channel.rb +64 -0
- data/lib/em/completion.rb +304 -0
- data/lib/em/connection.rb +716 -0
- data/lib/em/deferrable.rb +210 -0
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/file_watch.rb +73 -0
- data/lib/em/future.rb +61 -0
- data/lib/em/iterator.rb +231 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/pool.rb +151 -0
- data/lib/em/process_watch.rb +45 -0
- data/lib/em/processes.rb +123 -0
- data/lib/em/protocols.rb +37 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +279 -0
- data/lib/em/protocols/httpclient2.rb +600 -0
- data/lib/em/protocols/line_and_text.rb +125 -0
- data/lib/em/protocols/line_protocol.rb +29 -0
- data/lib/em/protocols/linetext2.rb +161 -0
- data/lib/em/protocols/memcache.rb +331 -0
- data/lib/em/protocols/object_protocol.rb +46 -0
- data/lib/em/protocols/postgres3.rb +246 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +365 -0
- data/lib/em/protocols/smtpserver.rb +643 -0
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/protocols/stomp.rb +205 -0
- data/lib/em/protocols/tcptest.rb +54 -0
- data/lib/em/pure_ruby.rb +1017 -0
- data/lib/em/queue.rb +71 -0
- data/lib/em/resolver.rb +209 -0
- data/lib/em/spawnable.rb +84 -0
- data/lib/em/streamer.rb +118 -0
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +61 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1553 -0
- data/lib/fastfilereaderext.rb +2 -0
- data/lib/jeventmachine.rb +321 -0
- data/lib/rubyeventmachine.rb +2 -0
- data/rakelib/cpp.rake_example +77 -0
- data/rakelib/package.rake +98 -0
- data/rakelib/test.rake +8 -0
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/em_test_helper.rb +64 -0
- data/tests/server.crt +36 -0
- data/tests/server.key +51 -0
- data/tests/test_attach.rb +150 -0
- data/tests/test_basic.rb +294 -0
- data/tests/test_channel.rb +62 -0
- data/tests/test_completion.rb +177 -0
- data/tests/test_connection_count.rb +53 -0
- data/tests/test_defer.rb +18 -0
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +145 -0
- data/tests/test_error_handler.rb +38 -0
- data/tests/test_exc.rb +28 -0
- data/tests/test_file_watch.rb +65 -0
- data/tests/test_futures.rb +170 -0
- data/tests/test_get_sock_opt.rb +37 -0
- data/tests/test_handler_check.rb +35 -0
- data/tests/test_hc.rb +155 -0
- data/tests/test_httpclient.rb +190 -0
- data/tests/test_httpclient2.rb +133 -0
- data/tests/test_idle_connection.rb +25 -0
- data/tests/test_inactivity_timeout.rb +54 -0
- data/tests/test_iterator.rb +97 -0
- data/tests/test_kb.rb +34 -0
- data/tests/test_line_protocol.rb +33 -0
- data/tests/test_ltp.rb +138 -0
- data/tests/test_ltp2.rb +288 -0
- data/tests/test_next_tick.rb +104 -0
- data/tests/test_object_protocol.rb +36 -0
- data/tests/test_pause.rb +102 -0
- data/tests/test_pending_connect_timeout.rb +52 -0
- data/tests/test_pool.rb +194 -0
- data/tests/test_process_watch.rb +48 -0
- data/tests/test_processes.rb +128 -0
- data/tests/test_proxy_connection.rb +180 -0
- data/tests/test_pure.rb +88 -0
- data/tests/test_queue.rb +50 -0
- data/tests/test_resolver.rb +55 -0
- data/tests/test_running.rb +14 -0
- data/tests/test_sasl.rb +47 -0
- data/tests/test_send_file.rb +217 -0
- data/tests/test_servers.rb +33 -0
- data/tests/test_set_sock_opt.rb +37 -0
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +55 -0
- data/tests/test_smtpserver.rb +57 -0
- data/tests/test_spawn.rb +293 -0
- data/tests/test_ssl_args.rb +78 -0
- data/tests/test_ssl_echo_data.rb +60 -0
- data/tests/test_ssl_methods.rb +56 -0
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_stomp.rb +37 -0
- data/tests/test_system.rb +42 -0
- data/tests/test_threaded_resource.rb +53 -0
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +123 -0
- data/tests/test_ud.rb +8 -0
- data/tests/test_unbind_reason.rb +48 -0
- metadata +300 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestSSLMethods < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
$dir = File.dirname(File.expand_path(__FILE__)) + '/'
|
6
|
+
$client_cert_from_file = File.read($dir+'client.crt')
|
7
|
+
$server_cert_from_file = File.read($dir+'server.crt')
|
8
|
+
end
|
9
|
+
|
10
|
+
module ServerHandler
|
11
|
+
|
12
|
+
def post_init
|
13
|
+
start_tls(:private_key_file => $dir+'server.key', :cert_chain_file => $dir+'server.crt', :verify_peer => true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ssl_handshake_completed
|
17
|
+
$server_called_back = true
|
18
|
+
$client_cert_value = get_peer_cert
|
19
|
+
end
|
20
|
+
|
21
|
+
def ssl_verify_peer cert
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClientHandler
|
27
|
+
|
28
|
+
def post_init
|
29
|
+
start_tls(:private_key_file => $dir+'client.key', :cert_chain_file => $dir+'client.crt')
|
30
|
+
end
|
31
|
+
|
32
|
+
def ssl_handshake_completed
|
33
|
+
$client_called_back = true
|
34
|
+
$server_cert_value = get_peer_cert
|
35
|
+
EM.stop_event_loop
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_ssl_methods
|
41
|
+
$server_called_back, $client_called_back = false, false
|
42
|
+
$server_cert_value, $client_cert_value = nil, nil
|
43
|
+
|
44
|
+
EM.run {
|
45
|
+
EM.start_server("127.0.0.1", 9999, ServerHandler)
|
46
|
+
EM.connect("127.0.0.1", 9999, ClientHandler)
|
47
|
+
}
|
48
|
+
|
49
|
+
assert($server_called_back)
|
50
|
+
assert($client_called_back)
|
51
|
+
|
52
|
+
assert_equal($server_cert_from_file, $server_cert_value.gsub("\r", ""))
|
53
|
+
assert_equal($client_cert_from_file, $client_cert_value.gsub("\r", ""))
|
54
|
+
end
|
55
|
+
|
56
|
+
end if EM.ssl?
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
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')
|
8
|
+
end
|
9
|
+
|
10
|
+
module Client
|
11
|
+
def connection_completed
|
12
|
+
start_tls(:private_key_file => $dir+'client.key', :cert_chain_file => $dir+'client.crt')
|
13
|
+
end
|
14
|
+
|
15
|
+
def ssl_handshake_completed
|
16
|
+
$client_handshake_completed = true
|
17
|
+
close_connection
|
18
|
+
end
|
19
|
+
|
20
|
+
def unbind
|
21
|
+
EM.stop_event_loop
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module AcceptServer
|
26
|
+
def post_init
|
27
|
+
start_tls(:private_key_file => $dir+'server.key', :cert_chain_file => $dir+'server.crt', :verify_peer => true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def ssl_verify_peer(cert)
|
31
|
+
$cert_from_server = cert
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def ssl_handshake_completed
|
36
|
+
$server_handshake_completed = true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module DenyServer
|
41
|
+
def post_init
|
42
|
+
start_tls(:private_key_file => $dir+'server.key', :cert_chain_file => $dir+'server.crt', :verify_peer => true)
|
43
|
+
end
|
44
|
+
|
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
|
54
|
+
end
|
55
|
+
|
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
|
+
}
|
62
|
+
|
63
|
+
assert_equal($cert_from_file, $cert_from_server.gsub("\r", ""))
|
64
|
+
assert($client_handshake_completed)
|
65
|
+
assert($server_handshake_completed)
|
66
|
+
end
|
67
|
+
|
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
|
+
}
|
74
|
+
|
75
|
+
assert_equal($cert_from_file, $cert_from_server.gsub("\r", ""))
|
76
|
+
assert(!$client_handshake_completed)
|
77
|
+
assert(!$server_handshake_completed)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
else
|
81
|
+
warn "EM built without SSL support, skipping tests in #{__FILE__}"
|
82
|
+
end
|
data/tests/test_stomp.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestStomp < Test::Unit::TestCase
|
4
|
+
CONTENT_LENGTH_REGEX = /^content-length: (\d+)$/
|
5
|
+
|
6
|
+
def bytesize(str)
|
7
|
+
str = str.to_s
|
8
|
+
size = str.bytesize if str.respond_to?(:bytesize) # bytesize added in 1.9
|
9
|
+
size || str.size
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_content_length_in_bytes
|
13
|
+
connection = Object.new
|
14
|
+
connection.instance_eval do
|
15
|
+
extend EM::P::Stomp
|
16
|
+
|
17
|
+
def last_sent_content_length
|
18
|
+
@sent && Integer(@sent[CONTENT_LENGTH_REGEX, 1])
|
19
|
+
end
|
20
|
+
|
21
|
+
def send_data(string)
|
22
|
+
@sent = string
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
queue = "queue"
|
27
|
+
failure_message = "header content-length is not the byte size of last sent body"
|
28
|
+
|
29
|
+
body = "test"
|
30
|
+
connection.send queue, body
|
31
|
+
assert_equal bytesize(body), connection.last_sent_content_length, failure_message
|
32
|
+
|
33
|
+
body = "test\u221A"
|
34
|
+
connection.send queue, body
|
35
|
+
assert_equal bytesize(body), connection.last_sent_content_length, failure_message
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'em_test_helper'
|
3
|
+
|
4
|
+
class TestSystem < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@filename = File.expand_path("../я манал dump.txt", __FILE__)
|
7
|
+
@test_data = 'a' * 100
|
8
|
+
File.open(@filename, 'w'){|f| f.write(@test_data)}
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_system
|
12
|
+
result = nil
|
13
|
+
status = nil
|
14
|
+
EM.run {
|
15
|
+
EM.system('cat', @filename){|out, state|
|
16
|
+
result = out
|
17
|
+
status = state.exitstatus
|
18
|
+
EM.stop
|
19
|
+
}
|
20
|
+
}
|
21
|
+
assert_equal(0, status)
|
22
|
+
assert_equal(@test_data, result)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_system_with_string
|
26
|
+
result = nil
|
27
|
+
status = nil
|
28
|
+
EM.run {
|
29
|
+
EM.system("cat '#@filename'"){|out, state|
|
30
|
+
result = out
|
31
|
+
status = state.exitstatus
|
32
|
+
EM.stop
|
33
|
+
}
|
34
|
+
}
|
35
|
+
assert_equal(0, status)
|
36
|
+
assert_equal(@test_data, result)
|
37
|
+
end
|
38
|
+
|
39
|
+
def teardown
|
40
|
+
File.unlink(@filename)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class TestThreadedResource < Test::Unit::TestCase
|
2
|
+
def object
|
3
|
+
@object ||= {}
|
4
|
+
end
|
5
|
+
|
6
|
+
def resource
|
7
|
+
@resource = EM::ThreadedResource.new do
|
8
|
+
object
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
resource.shutdown
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_dispatch_completion
|
17
|
+
EM.run do
|
18
|
+
completion = resource.dispatch do |o|
|
19
|
+
o[:foo] = :bar
|
20
|
+
:foo
|
21
|
+
end
|
22
|
+
completion.callback do |result|
|
23
|
+
assert_equal :foo, result
|
24
|
+
EM.stop
|
25
|
+
end
|
26
|
+
end
|
27
|
+
assert_equal :bar, object[:foo]
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_dispatch_failure
|
31
|
+
completion = resource.dispatch do |o|
|
32
|
+
raise 'boom'
|
33
|
+
end
|
34
|
+
completion.errback do |error|
|
35
|
+
assert_kind_of RuntimeError, error
|
36
|
+
assert_equal 'boom', error.message
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_dispatch_threading
|
41
|
+
main = Thread.current
|
42
|
+
resource.dispatch do |o|
|
43
|
+
o[:dispatch_thread] = Thread.current
|
44
|
+
end
|
45
|
+
assert_not_equal main, object[:dispatch_thread]
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_shutdown
|
49
|
+
# This test should get improved sometime. The method returning thread is
|
50
|
+
# NOT an api that will be maintained.
|
51
|
+
assert !resource.shutdown.alive?
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require 'em_test_helper'
|
3
|
+
|
4
|
+
class TestEmTickLoop < Test::Unit::TestCase
|
5
|
+
def test_em_tick_loop
|
6
|
+
i = 0
|
7
|
+
EM.tick_loop { i += 1; EM.stop if i == 10 }
|
8
|
+
EM.run { EM.add_timer(1) { EM.stop } }
|
9
|
+
assert_equal i, 10
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_tick_loop_on_stop
|
13
|
+
t = nil
|
14
|
+
tick_loop = EM.tick_loop { :stop }
|
15
|
+
tick_loop.on_stop { t = true }
|
16
|
+
EM.run { EM.next_tick { EM.stop } }
|
17
|
+
assert t
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_start_twice
|
21
|
+
i = 0
|
22
|
+
s = 0
|
23
|
+
tick_loop = EM.tick_loop { i += 1; :stop }
|
24
|
+
tick_loop.on_stop { s += 1; EM.stop }
|
25
|
+
EM.run { EM.next_tick { EM.stop } }
|
26
|
+
assert_equal 1, i
|
27
|
+
assert_equal 1, s
|
28
|
+
tick_loop.start
|
29
|
+
EM.run { EM.next_tick { EM.stop } }
|
30
|
+
assert_equal 2, i
|
31
|
+
assert_equal 1, s # stop callbacks are only called once
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_stop
|
35
|
+
i, s = 0, 0
|
36
|
+
tick_loop = EM.tick_loop { i += 1 }
|
37
|
+
tick_loop.on_stop { s += 1 }
|
38
|
+
EM.run { EM.next_tick { tick_loop.stop; EM.next_tick { EM.stop } } }
|
39
|
+
assert tick_loop.stopped?
|
40
|
+
assert_equal 1, i
|
41
|
+
assert_equal 1, s
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_immediate_stops
|
45
|
+
s = 0
|
46
|
+
tick_loop = EM::TickLoop.new { }
|
47
|
+
tick_loop.on_stop { s += 1 }
|
48
|
+
tick_loop.on_stop { s += 1 }
|
49
|
+
assert_equal 2, s
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_stopped
|
53
|
+
tick_loop = EM::TickLoop.new { }
|
54
|
+
assert tick_loop.stopped?
|
55
|
+
tick_loop.start
|
56
|
+
assert !tick_loop.stopped?
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestTimers < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_timer_with_block
|
6
|
+
x = false
|
7
|
+
EM.run {
|
8
|
+
EM::Timer.new(0) {
|
9
|
+
x = true
|
10
|
+
EM.stop
|
11
|
+
}
|
12
|
+
}
|
13
|
+
assert x
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_timer_with_proc
|
17
|
+
x = false
|
18
|
+
EM.run {
|
19
|
+
EM::Timer.new(0, proc {
|
20
|
+
x = true
|
21
|
+
EM.stop
|
22
|
+
})
|
23
|
+
}
|
24
|
+
assert x
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_timer_cancel
|
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
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_periodic_timer
|
39
|
+
x = 0
|
40
|
+
EM.run {
|
41
|
+
EM::PeriodicTimer.new(0.01) do
|
42
|
+
x += 1
|
43
|
+
EM.stop if x == 4
|
44
|
+
end
|
45
|
+
}
|
46
|
+
|
47
|
+
assert_equal 4, x
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_add_periodic_timer
|
51
|
+
x = 0
|
52
|
+
EM.run {
|
53
|
+
t = EM.add_periodic_timer(0.01) do
|
54
|
+
x += 1
|
55
|
+
EM.stop if x == 4
|
56
|
+
end
|
57
|
+
assert t.respond_to?(:cancel)
|
58
|
+
}
|
59
|
+
assert_equal 4, x
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_periodic_timer_cancel
|
63
|
+
x = 0
|
64
|
+
EM.run {
|
65
|
+
pt = EM::PeriodicTimer.new(0.01) { x += 1 }
|
66
|
+
pt.cancel
|
67
|
+
EM::Timer.new(0.02) { EM.stop }
|
68
|
+
}
|
69
|
+
assert_equal 0, x
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_add_periodic_timer_cancel
|
73
|
+
x = 0
|
74
|
+
EM.run {
|
75
|
+
pt = EM.add_periodic_timer(0.01) { x += 1 }
|
76
|
+
EM.cancel_timer(pt)
|
77
|
+
EM.add_timer(0.02) { EM.stop }
|
78
|
+
}
|
79
|
+
assert_equal 0, x
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_periodic_timer_self_cancel
|
83
|
+
x = 0
|
84
|
+
EM.run {
|
85
|
+
pt = EM::PeriodicTimer.new(0) {
|
86
|
+
x += 1
|
87
|
+
if x == 4
|
88
|
+
pt.cancel
|
89
|
+
EM.stop
|
90
|
+
end
|
91
|
+
}
|
92
|
+
}
|
93
|
+
assert_equal 4, x
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
# This test is only applicable to compiled versions of the reactor.
|
98
|
+
# Pure ruby and java versions have no built-in limit on the number of outstanding timers.
|
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
|
108
|
+
|
109
|
+
assert_raises(RuntimeError) do
|
110
|
+
EM.run( &one_hundred_one_timers )
|
111
|
+
end
|
112
|
+
|
113
|
+
EM.set_max_timers( 101 )
|
114
|
+
|
115
|
+
assert_nothing_raised do
|
116
|
+
EM.run( &one_hundred_one_timers )
|
117
|
+
end
|
118
|
+
ensure
|
119
|
+
EM.set_max_timers(defaults)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|