eventmachine-maglev- 0.12.10 → 1.0.0.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.yardopts +7 -0
- data/Gemfile +3 -0
- data/README.md +109 -0
- data/Rakefile +14 -368
- data/docs/DocumentationGuidesIndex.md +27 -0
- data/docs/GettingStarted.md +521 -0
- data/docs/old/DEFERRABLES +246 -0
- data/docs/{KEYBOARD → old/KEYBOARD} +15 -11
- data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
- data/docs/old/SMTP +4 -0
- data/docs/old/SPAWNED_PROCESSES +148 -0
- data/eventmachine.gemspec +20 -26
- 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/{ex_channel.rb → old/ex_channel.rb} +3 -3
- data/examples/old/ex_tick_loop_array.rb +15 -0
- data/examples/old/ex_tick_loop_counter.rb +32 -0
- data/ext/binder.cpp +0 -1
- data/ext/cmain.cpp +40 -29
- data/ext/ed.cpp +189 -134
- data/ext/ed.h +34 -40
- data/ext/em.cpp +388 -340
- data/ext/em.h +29 -32
- data/ext/eventmachine.h +7 -6
- data/ext/extconf.rb +57 -48
- data/ext/fastfilereader/extconf.rb +5 -3
- data/ext/fastfilereader/mapper.cpp +1 -1
- data/ext/fastfilereader/rubymain.cpp +0 -1
- data/ext/kb.cpp +1 -3
- data/ext/pipe.cpp +9 -11
- data/ext/project.h +12 -8
- data/ext/rubymain.cpp +158 -112
- data/java/src/com/rubyeventmachine/EmReactor.java +3 -2
- data/lib/em/buftok.rb +35 -63
- data/lib/em/callback.rb +43 -11
- data/lib/em/channel.rb +22 -15
- data/lib/em/completion.rb +303 -0
- data/lib/em/connection.rb +341 -208
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/deferrable.rb +20 -2
- data/lib/em/file_watch.rb +37 -18
- data/lib/em/iterator.rb +270 -0
- data/lib/em/pool.rb +146 -0
- data/lib/em/process_watch.rb +5 -4
- data/lib/em/processes.rb +8 -4
- data/lib/em/protocols/httpclient.rb +27 -11
- data/lib/em/protocols/httpclient2.rb +15 -5
- data/lib/em/protocols/line_protocol.rb +29 -0
- data/lib/em/protocols/memcache.rb +17 -9
- data/lib/em/protocols/object_protocol.rb +2 -1
- data/lib/em/protocols/postgres3.rb +2 -1
- data/lib/em/protocols/smtpclient.rb +19 -11
- data/lib/em/protocols/smtpserver.rb +101 -8
- data/lib/em/protocols/stomp.rb +9 -7
- data/lib/em/protocols/tcptest.rb +3 -2
- data/lib/em/protocols.rb +1 -1
- data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +188 -205
- data/lib/em/queue.rb +23 -13
- data/lib/em/resolver.rb +192 -0
- data/lib/em/spawnable.rb +9 -10
- data/lib/em/streamer.rb +34 -46
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +8 -3
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +582 -686
- data/lib/jeventmachine.rb +25 -3
- data/tasks/package.rake +98 -0
- data/tasks/test.rake +8 -0
- data/tests/em_test_helper.rb +64 -0
- data/tests/test_attach.rb +56 -56
- data/tests/test_basic.rb +111 -168
- data/tests/test_channel.rb +5 -6
- data/tests/test_completion.rb +177 -0
- data/tests/test_connection_count.rb +1 -3
- data/tests/test_defer.rb +3 -32
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +27 -57
- 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 +10 -38
- data/tests/test_get_sock_opt.rb +27 -20
- data/tests/test_handler_check.rb +1 -3
- data/tests/test_hc.rb +49 -112
- data/tests/test_httpclient.rb +34 -62
- data/tests/test_httpclient2.rb +14 -39
- data/tests/test_inactivity_timeout.rb +44 -40
- data/tests/test_kb.rb +26 -52
- data/tests/test_ltp.rb +27 -71
- data/tests/test_ltp2.rb +1 -30
- data/tests/test_next_tick.rb +2 -31
- 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_pool.rb +128 -0
- data/tests/test_process_watch.rb +37 -37
- data/tests/test_processes.rb +92 -110
- data/tests/test_proxy_connection.rb +137 -61
- data/tests/test_pure.rb +30 -67
- data/tests/test_queue.rb +10 -4
- data/tests/test_resolver.rb +55 -0
- data/tests/test_running.rb +1 -29
- data/tests/test_sasl.rb +8 -33
- data/tests/test_send_file.rb +163 -188
- data/tests/test_servers.rb +12 -55
- data/tests/test_shutdown_hooks.rb +23 -0
- 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_threaded_resource.rb +53 -0
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +52 -91
- data/tests/test_ud.rb +1 -29
- data/tests/test_unbind_reason.rb +31 -0
- metadata +113 -70
- data/README +0 -82
- data/docs/DEFERRABLES +0 -133
- data/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
- data/docs/SMTP +0 -2
- data/docs/SPAWNED_PROCESSES +0 -89
- data/ext/cplusplus.cpp +0 -202
- data/ext/emwin.cpp +0 -300
- data/ext/emwin.h +0 -94
- data/ext/epoll.cpp +0 -26
- data/ext/epoll.h +0 -25
- data/ext/eventmachine_cpp.h +0 -96
- data/ext/files.cpp +0 -94
- data/ext/files.h +0 -65
- data/ext/sigs.cpp +0 -89
- data/ext/sigs.h +0 -32
- data/java/src/com/rubyeventmachine/application/Application.java +0 -194
- data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
- data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
- data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
- data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
- data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
- data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
- data/lib/evma/callback.rb +0 -32
- data/lib/evma/container.rb +0 -75
- data/lib/evma/factory.rb +0 -77
- data/lib/evma/protocol.rb +0 -87
- data/lib/evma/reactor.rb +0 -48
- data/lib/evma.rb +0 -32
- data/setup.rb +0 -1585
- data/tests/test_errors.rb +0 -82
- data/tests/testem.rb +0 -31
- data/web/whatis +0 -7
- /data/{docs/GNU → GNU} +0 -0
- /data/{docs/COPYING → LICENSE} +0 -0
- /data/docs/{ChangeLog → old/ChangeLog} +0 -0
- /data/docs/{EPOLL → old/EPOLL} +0 -0
- /data/docs/{INSTALL → old/INSTALL} +0 -0
- /data/docs/{LEGAL → old/LEGAL} +0 -0
- /data/docs/{PURE_RUBY → old/PURE_RUBY} +0 -0
- /data/docs/{RELEASE_NOTES → old/RELEASE_NOTES} +0 -0
- /data/docs/{TODO → old/TODO} +0 -0
- /data/examples/{ex_queue.rb → old/ex_queue.rb} +0 -0
- /data/examples/{helper.rb → old/helper.rb} +0 -0
data/tests/test_epoll.rb
CHANGED
@@ -1,35 +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
|
-
# 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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
|
@@ -77,7 +49,7 @@ class TestEpoll < Test::Unit::TestCase
|
|
77
49
|
# XXX this test causes all sort of weird issues on OSX (when run as part of the suite)
|
78
50
|
def _test_descriptors
|
79
51
|
EM.epoll
|
80
|
-
|
52
|
+
EM.set_descriptor_table_size 60000
|
81
53
|
EM.run {
|
82
54
|
EM.start_server "127.0.0.1", 9800, TestEchoServer
|
83
55
|
$n = 0
|
@@ -90,16 +62,9 @@ class TestEpoll < Test::Unit::TestCase
|
|
90
62
|
assert_equal(100, $max)
|
91
63
|
end
|
92
64
|
|
93
|
-
def
|
94
|
-
|
95
|
-
|
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",
|
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",
|
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 )
|
@@ -131,7 +101,7 @@ class TestEpoll < Test::Unit::TestCase
|
|
131
101
|
def _test_unix_domain
|
132
102
|
fn = "/tmp/xxx.chain"
|
133
103
|
EM.epoll
|
134
|
-
|
104
|
+
EM.set_descriptor_table_size 60000
|
135
105
|
EM.run {
|
136
106
|
# The pure-Ruby version won't let us open the socket if the node already exists.
|
137
107
|
# Not sure, that actually may be correct and the compiled version is wrong.
|
data/tests/test_error_handler.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
4
2
|
|
5
3
|
class TestErrorHandler < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@exception = Class.new(StandardError)
|
6
|
+
end
|
7
|
+
|
6
8
|
def test_error_handler
|
7
9
|
error = nil
|
10
|
+
|
8
11
|
EM.error_handler{ |e|
|
9
12
|
error = e
|
10
13
|
EM.error_handler(nil)
|
@@ -14,20 +17,20 @@ class TestErrorHandler < Test::Unit::TestCase
|
|
14
17
|
assert_nothing_raised do
|
15
18
|
EM.run{
|
16
19
|
EM.add_timer(0){
|
17
|
-
raise 'test'
|
20
|
+
raise @exception, 'test'
|
18
21
|
}
|
19
22
|
}
|
20
23
|
end
|
21
24
|
|
22
|
-
assert_equal error.class,
|
25
|
+
assert_equal error.class, @exception
|
23
26
|
assert_equal error.message, 'test'
|
24
27
|
end
|
25
28
|
|
26
29
|
def test_without_error_handler
|
27
|
-
assert_raise
|
30
|
+
assert_raise @exception do
|
28
31
|
EM.run{
|
29
32
|
EM.add_timer(0){
|
30
|
-
raise 'test'
|
33
|
+
raise @exception, 'test'
|
31
34
|
}
|
32
35
|
}
|
33
36
|
end
|
data/tests/test_exc.rb
CHANGED
@@ -1,44 +1,17 @@
|
|
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
|
-
$:.unshift "../lib"
|
27
|
-
require 'eventmachine'
|
28
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
29
2
|
|
30
3
|
class TestSomeExceptions < Test::Unit::TestCase
|
31
4
|
|
32
|
-
# Read the commentary in
|
5
|
+
# Read the commentary in EM#run.
|
33
6
|
# This test exercises the ensure block in #run that makes sure
|
34
|
-
#
|
7
|
+
# EM#release_machine gets called even if an exception is
|
35
8
|
# thrown within the user code. Without the ensured call to release_machine,
|
36
|
-
# the second call to
|
9
|
+
# the second call to EM#run will fail with a C++ exception
|
37
10
|
# because the machine wasn't cleaned up properly.
|
38
11
|
|
39
12
|
def test_a
|
40
13
|
assert_raises(RuntimeError) {
|
41
|
-
|
14
|
+
EM.run {
|
42
15
|
raise "some exception"
|
43
16
|
}
|
44
17
|
}
|
@@ -46,7 +19,7 @@ class TestSomeExceptions < Test::Unit::TestCase
|
|
46
19
|
|
47
20
|
def test_b
|
48
21
|
assert_raises(RuntimeError) {
|
49
|
-
|
22
|
+
EM.run {
|
50
23
|
raise "some exception"
|
51
24
|
}
|
52
25
|
}
|
data/tests/test_file_watch.rb
CHANGED
@@ -1,49 +1,65 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
2
|
+
require 'tempfile'
|
4
3
|
|
5
4
|
class TestFileWatch < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def
|
8
|
-
|
5
|
+
if windows?
|
6
|
+
def test_watch_file_raises_unsupported_error
|
7
|
+
assert_raises(EM::Unsupported) do
|
8
|
+
EM.run do
|
9
|
+
file = Tempfile.new("fake_file")
|
10
|
+
EM.watch_file(file.path)
|
11
|
+
end
|
12
|
+
end
|
9
13
|
end
|
10
|
-
|
11
|
-
|
14
|
+
elsif EM.respond_to? :watch_filename
|
15
|
+
module FileWatcher
|
16
|
+
def file_modified
|
17
|
+
$modified = true
|
18
|
+
end
|
19
|
+
def file_deleted
|
20
|
+
$deleted = true
|
21
|
+
end
|
22
|
+
def unbind
|
23
|
+
$unbind = true
|
24
|
+
EM.stop
|
25
|
+
end
|
12
26
|
end
|
13
|
-
|
14
|
-
|
15
|
-
EM.
|
27
|
+
|
28
|
+
def setup
|
29
|
+
EM.kqueue = true if EM.kqueue?
|
16
30
|
end
|
17
|
-
end
|
18
31
|
|
19
|
-
|
20
|
-
|
21
|
-
|
32
|
+
def teardown
|
33
|
+
EM.kqueue = false if EM.kqueue?
|
34
|
+
end
|
22
35
|
|
23
|
-
|
24
|
-
|
25
|
-
|
36
|
+
def test_events
|
37
|
+
EM.run{
|
38
|
+
file = Tempfile.new('em-watch')
|
39
|
+
$tmp_path = file.path
|
26
40
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
file = Tempfile.new('em-watch')
|
31
|
-
$tmp_path = file.path
|
41
|
+
# watch it
|
42
|
+
watch = EM.watch_file(file.path, FileWatcher)
|
43
|
+
$path = watch.path
|
32
44
|
|
33
|
-
|
34
|
-
|
35
|
-
$path = watch.path
|
45
|
+
# modify it
|
46
|
+
File.open(file.path, 'w'){ |f| f.puts 'hi' }
|
36
47
|
|
37
|
-
|
38
|
-
|
48
|
+
# delete it
|
49
|
+
EM.add_timer(0.01){ file.close; file.delete }
|
50
|
+
}
|
39
51
|
|
40
|
-
|
41
|
-
|
42
|
-
|
52
|
+
assert_equal($path, $tmp_path)
|
53
|
+
assert($modified)
|
54
|
+
assert($deleted)
|
55
|
+
assert($unbind)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
warn "EM.watch_file not implemented, skipping tests in #{__FILE__}"
|
43
59
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
60
|
+
# Because some rubies will complain if a TestCase class has no tests
|
61
|
+
def test_em_watch_file_unsupported
|
62
|
+
assert true
|
63
|
+
end
|
48
64
|
end
|
49
65
|
end
|
data/tests/test_futures.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 TestFutures < Test::Unit::TestCase
|
32
4
|
|
@@ -37,14 +9,14 @@ class TestFutures < Test::Unit::TestCase
|
|
37
9
|
end
|
38
10
|
|
39
11
|
def test_future
|
40
|
-
assert_equal(100,
|
12
|
+
assert_equal(100, EM::Deferrable.future(100) )
|
41
13
|
|
42
14
|
p1 = proc { 100 + 1 }
|
43
|
-
assert_equal(101,
|
15
|
+
assert_equal(101, EM::Deferrable.future(p1) )
|
44
16
|
end
|
45
17
|
|
46
18
|
class MyFuture
|
47
|
-
include
|
19
|
+
include EM::Deferrable
|
48
20
|
def initialize *args
|
49
21
|
super
|
50
22
|
set_deferred_status :succeeded, 40
|
@@ -52,7 +24,7 @@ class TestFutures < Test::Unit::TestCase
|
|
52
24
|
end
|
53
25
|
|
54
26
|
class MyErrorFuture
|
55
|
-
include
|
27
|
+
include EM::Deferrable
|
56
28
|
def initialize *args
|
57
29
|
super
|
58
30
|
set_deferred_status :failed, 41
|
@@ -67,7 +39,7 @@ class TestFutures < Test::Unit::TestCase
|
|
67
39
|
end
|
68
40
|
|
69
41
|
value = nil
|
70
|
-
|
42
|
+
EM::Deferrable.future my_future, proc {|v| value=v}
|
71
43
|
assert_equal( 40, value )
|
72
44
|
end
|
73
45
|
|
@@ -76,7 +48,7 @@ class TestFutures < Test::Unit::TestCase
|
|
76
48
|
# Call future with two additional arguments and they will be treated as a callback
|
77
49
|
# and an errback.
|
78
50
|
value = nil
|
79
|
-
|
51
|
+
EM::Deferrable.future MyErrorFuture.new, nil, proc {|v| value=v}
|
80
52
|
assert_equal( 41, value )
|
81
53
|
end
|
82
54
|
|
@@ -85,7 +57,7 @@ class TestFutures < Test::Unit::TestCase
|
|
85
57
|
# Call future with no additional arguments but with a block, and the block will be
|
86
58
|
# treated as a callback.
|
87
59
|
value = nil
|
88
|
-
|
60
|
+
EM::Deferrable.future MyFuture.new do |v|
|
89
61
|
value=v
|
90
62
|
end
|
91
63
|
assert_equal( 40, value )
|
@@ -93,7 +65,7 @@ class TestFutures < Test::Unit::TestCase
|
|
93
65
|
|
94
66
|
|
95
67
|
class RecursiveCallback
|
96
|
-
include
|
68
|
+
include EM::Deferrable
|
97
69
|
end
|
98
70
|
|
99
71
|
# A Deferrable callback can call #set_deferred_status to change the values
|
@@ -190,7 +162,7 @@ class TestFutures < Test::Unit::TestCase
|
|
190
162
|
d = EM::DefaultDeferrable.new
|
191
163
|
d.callback {n = 1; EM.stop}
|
192
164
|
d.errback {n = 2; EM.stop}
|
193
|
-
d.timeout(
|
165
|
+
d.timeout(0.01)
|
194
166
|
}
|
195
167
|
assert_equal( 2, n )
|
196
168
|
end
|
data/tests/test_get_sock_opt.rb
CHANGED
@@ -1,30 +1,37 @@
|
|
1
|
-
|
2
|
-
require 'eventmachine'
|
1
|
+
require 'em_test_helper'
|
3
2
|
require 'socket'
|
4
|
-
require 'test/unit'
|
5
3
|
|
6
4
|
class TestGetSockOpt < Test::Unit::TestCase
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
if EM.respond_to? :get_sock_opt
|
7
|
+
def setup
|
8
|
+
assert(!EM.reactor_running?)
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def teardown
|
12
|
+
assert(!EM.reactor_running?)
|
13
|
+
end
|
14
|
+
|
15
|
+
#-------------------------------------
|
15
16
|
|
16
|
-
|
17
|
+
def test_get_sock_opt
|
18
|
+
test = self
|
19
|
+
EM.run do
|
20
|
+
EM.connect 'google.com', 80, Module.new {
|
21
|
+
define_method :connection_completed do
|
22
|
+
val = get_sock_opt Socket::SOL_SOCKET, Socket::SO_ERROR
|
23
|
+
test.assert_equal "\0\0\0\0", val
|
24
|
+
EM.stop
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
else
|
30
|
+
warn "EM.get_sock_opt not implemented, skipping tests in #{__FILE__}"
|
17
31
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
EM.connect 'google.com', 80, Module.new {
|
22
|
-
define_method :connection_completed do
|
23
|
-
val = get_sock_opt Socket::SOL_SOCKET, Socket::SO_ERROR
|
24
|
-
test.assert_equal "\0\0\0\0", val
|
25
|
-
EM.stop
|
26
|
-
end
|
27
|
-
}
|
32
|
+
# Because some rubies will complain if a TestCase class has no tests
|
33
|
+
def test_em_get_sock_opt_unsupported
|
34
|
+
assert true
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|