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.
Files changed (174) hide show
  1. data/.gitignore +7 -0
  2. data/.yardopts +7 -0
  3. data/Gemfile +3 -0
  4. data/README.md +109 -0
  5. data/Rakefile +14 -368
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +521 -0
  8. data/docs/old/DEFERRABLES +246 -0
  9. data/docs/{KEYBOARD → old/KEYBOARD} +15 -11
  10. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  11. data/docs/old/SMTP +4 -0
  12. data/docs/old/SPAWNED_PROCESSES +148 -0
  13. data/eventmachine.gemspec +20 -26
  14. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  15. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  16. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  17. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  18. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  19. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  20. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  21. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  22. data/examples/{ex_channel.rb → old/ex_channel.rb} +3 -3
  23. data/examples/old/ex_tick_loop_array.rb +15 -0
  24. data/examples/old/ex_tick_loop_counter.rb +32 -0
  25. data/ext/binder.cpp +0 -1
  26. data/ext/cmain.cpp +40 -29
  27. data/ext/ed.cpp +189 -134
  28. data/ext/ed.h +34 -40
  29. data/ext/em.cpp +388 -340
  30. data/ext/em.h +29 -32
  31. data/ext/eventmachine.h +7 -6
  32. data/ext/extconf.rb +57 -48
  33. data/ext/fastfilereader/extconf.rb +5 -3
  34. data/ext/fastfilereader/mapper.cpp +1 -1
  35. data/ext/fastfilereader/rubymain.cpp +0 -1
  36. data/ext/kb.cpp +1 -3
  37. data/ext/pipe.cpp +9 -11
  38. data/ext/project.h +12 -8
  39. data/ext/rubymain.cpp +158 -112
  40. data/java/src/com/rubyeventmachine/EmReactor.java +3 -2
  41. data/lib/em/buftok.rb +35 -63
  42. data/lib/em/callback.rb +43 -11
  43. data/lib/em/channel.rb +22 -15
  44. data/lib/em/completion.rb +303 -0
  45. data/lib/em/connection.rb +341 -208
  46. data/lib/em/deferrable/pool.rb +2 -0
  47. data/lib/em/deferrable.rb +20 -2
  48. data/lib/em/file_watch.rb +37 -18
  49. data/lib/em/iterator.rb +270 -0
  50. data/lib/em/pool.rb +146 -0
  51. data/lib/em/process_watch.rb +5 -4
  52. data/lib/em/processes.rb +8 -4
  53. data/lib/em/protocols/httpclient.rb +27 -11
  54. data/lib/em/protocols/httpclient2.rb +15 -5
  55. data/lib/em/protocols/line_protocol.rb +29 -0
  56. data/lib/em/protocols/memcache.rb +17 -9
  57. data/lib/em/protocols/object_protocol.rb +2 -1
  58. data/lib/em/protocols/postgres3.rb +2 -1
  59. data/lib/em/protocols/smtpclient.rb +19 -11
  60. data/lib/em/protocols/smtpserver.rb +101 -8
  61. data/lib/em/protocols/stomp.rb +9 -7
  62. data/lib/em/protocols/tcptest.rb +3 -2
  63. data/lib/em/protocols.rb +1 -1
  64. data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +188 -205
  65. data/lib/em/queue.rb +23 -13
  66. data/lib/em/resolver.rb +192 -0
  67. data/lib/em/spawnable.rb +9 -10
  68. data/lib/em/streamer.rb +34 -46
  69. data/lib/em/threaded_resource.rb +90 -0
  70. data/lib/em/tick_loop.rb +85 -0
  71. data/lib/em/timers.rb +8 -3
  72. data/lib/em/version.rb +1 -1
  73. data/lib/eventmachine.rb +582 -686
  74. data/lib/jeventmachine.rb +25 -3
  75. data/tasks/package.rake +98 -0
  76. data/tasks/test.rake +8 -0
  77. data/tests/em_test_helper.rb +64 -0
  78. data/tests/test_attach.rb +56 -56
  79. data/tests/test_basic.rb +111 -168
  80. data/tests/test_channel.rb +5 -6
  81. data/tests/test_completion.rb +177 -0
  82. data/tests/test_connection_count.rb +1 -3
  83. data/tests/test_defer.rb +3 -32
  84. data/tests/test_deferrable.rb +35 -0
  85. data/tests/test_epoll.rb +27 -57
  86. data/tests/test_error_handler.rb +10 -7
  87. data/tests/test_exc.rb +6 -33
  88. data/tests/test_file_watch.rb +51 -35
  89. data/tests/test_futures.rb +10 -38
  90. data/tests/test_get_sock_opt.rb +27 -20
  91. data/tests/test_handler_check.rb +1 -3
  92. data/tests/test_hc.rb +49 -112
  93. data/tests/test_httpclient.rb +34 -62
  94. data/tests/test_httpclient2.rb +14 -39
  95. data/tests/test_inactivity_timeout.rb +44 -40
  96. data/tests/test_kb.rb +26 -52
  97. data/tests/test_ltp.rb +27 -71
  98. data/tests/test_ltp2.rb +1 -30
  99. data/tests/test_next_tick.rb +2 -31
  100. data/tests/test_object_protocol.rb +8 -9
  101. data/tests/test_pause.rb +45 -37
  102. data/tests/test_pending_connect_timeout.rb +42 -38
  103. data/tests/test_pool.rb +128 -0
  104. data/tests/test_process_watch.rb +37 -37
  105. data/tests/test_processes.rb +92 -110
  106. data/tests/test_proxy_connection.rb +137 -61
  107. data/tests/test_pure.rb +30 -67
  108. data/tests/test_queue.rb +10 -4
  109. data/tests/test_resolver.rb +55 -0
  110. data/tests/test_running.rb +1 -29
  111. data/tests/test_sasl.rb +8 -33
  112. data/tests/test_send_file.rb +163 -188
  113. data/tests/test_servers.rb +12 -55
  114. data/tests/test_shutdown_hooks.rb +23 -0
  115. data/tests/test_smtpclient.rb +1 -29
  116. data/tests/test_smtpserver.rb +1 -29
  117. data/tests/test_spawn.rb +2 -31
  118. data/tests/test_ssl_args.rb +9 -10
  119. data/tests/test_ssl_methods.rb +1 -3
  120. data/tests/test_ssl_verify.rb +63 -63
  121. data/tests/test_threaded_resource.rb +53 -0
  122. data/tests/test_tick_loop.rb +59 -0
  123. data/tests/test_timers.rb +52 -91
  124. data/tests/test_ud.rb +1 -29
  125. data/tests/test_unbind_reason.rb +31 -0
  126. metadata +113 -70
  127. data/README +0 -82
  128. data/docs/DEFERRABLES +0 -133
  129. data/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
  130. data/docs/SMTP +0 -2
  131. data/docs/SPAWNED_PROCESSES +0 -89
  132. data/ext/cplusplus.cpp +0 -202
  133. data/ext/emwin.cpp +0 -300
  134. data/ext/emwin.h +0 -94
  135. data/ext/epoll.cpp +0 -26
  136. data/ext/epoll.h +0 -25
  137. data/ext/eventmachine_cpp.h +0 -96
  138. data/ext/files.cpp +0 -94
  139. data/ext/files.h +0 -65
  140. data/ext/sigs.cpp +0 -89
  141. data/ext/sigs.h +0 -32
  142. data/java/src/com/rubyeventmachine/application/Application.java +0 -194
  143. data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
  144. data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
  145. data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
  146. data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
  147. data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
  148. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
  149. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
  150. data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
  151. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
  152. data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
  153. data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
  154. data/lib/evma/callback.rb +0 -32
  155. data/lib/evma/container.rb +0 -75
  156. data/lib/evma/factory.rb +0 -77
  157. data/lib/evma/protocol.rb +0 -87
  158. data/lib/evma/reactor.rb +0 -48
  159. data/lib/evma.rb +0 -32
  160. data/setup.rb +0 -1585
  161. data/tests/test_errors.rb +0 -82
  162. data/tests/testem.rb +0 -31
  163. data/web/whatis +0 -7
  164. /data/{docs/GNU → GNU} +0 -0
  165. /data/{docs/COPYING → LICENSE} +0 -0
  166. /data/docs/{ChangeLog → old/ChangeLog} +0 -0
  167. /data/docs/{EPOLL → old/EPOLL} +0 -0
  168. /data/docs/{INSTALL → old/INSTALL} +0 -0
  169. /data/docs/{LEGAL → old/LEGAL} +0 -0
  170. /data/docs/{PURE_RUBY → old/PURE_RUBY} +0 -0
  171. /data/docs/{RELEASE_NOTES → old/RELEASE_NOTES} +0 -0
  172. /data/docs/{TODO → old/TODO} +0 -0
  173. /data/examples/{ex_queue.rb → old/ex_queue.rb} +0 -0
  174. /data/examples/{helper.rb → old/helper.rb} +0 -0
data/tests/test_epoll.rb CHANGED
@@ -1,35 +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
- # 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
- # We can set the rlimit/nofile of a process but we can only set it
60
- # higher if we're running as root.
61
- # On most systems, the default value is 1024.
62
- # Java doesn't (currently) implement this.
63
- def test_rlimit
64
- unless RUBY_PLATFORM =~ /java/ or EM.set_descriptor_table_size >= 1024
65
- a = EM.set_descriptor_table_size
66
- assert( a <= 1024 )
67
- a = EM.set_descriptor_table_size( 1024 )
68
- assert( a == 1024 )
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
- s = EM.set_descriptor_table_size 60000
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 test_defer
94
- n = 0
95
- work_proc = proc {n += 1}
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", 9500
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", 9500, TestDatagramServer
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
- s = EM.set_descriptor_table_size 60000
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.
@@ -1,10 +1,13 @@
1
- $:.unshift "../lib"
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, RuntimeError
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 RuntimeError do
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
- # $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
- $:.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 EventMachine#run.
5
+ # Read the commentary in EM#run.
33
6
  # This test exercises the ensure block in #run that makes sure
34
- # EventMachine#release_machine gets called even if an exception is
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 EventMachine#run will fail with a C++ exception
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
- EventMachine.run {
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
- EventMachine.run {
22
+ EM.run {
50
23
  raise "some exception"
51
24
  }
52
25
  }
@@ -1,49 +1,65 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
1
+ require 'em_test_helper'
2
+ require 'tempfile'
4
3
 
5
4
  class TestFileWatch < Test::Unit::TestCase
6
- module FileWatcher
7
- def file_modified
8
- $modified = true
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
- def file_deleted
11
- $deleted = true
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
- def unbind
14
- $unbind = true
15
- EM.stop
27
+
28
+ def setup
29
+ EM.kqueue = true if EM.kqueue?
16
30
  end
17
- end
18
31
 
19
- def setup
20
- EM.kqueue = true if EM.kqueue?
21
- end
32
+ def teardown
33
+ EM.kqueue = false if EM.kqueue?
34
+ end
22
35
 
23
- def teardown
24
- EM.kqueue = false if EM.kqueue?
25
- end
36
+ def test_events
37
+ EM.run{
38
+ file = Tempfile.new('em-watch')
39
+ $tmp_path = file.path
26
40
 
27
- def test_events
28
- EM.run{
29
- require 'tempfile'
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
- # watch it
34
- watch = EM.watch_file(file.path, FileWatcher)
35
- $path = watch.path
45
+ # modify it
46
+ File.open(file.path, 'w'){ |f| f.puts 'hi' }
36
47
 
37
- # modify it
38
- File.open(file.path, 'w'){ |f| f.puts 'hi' }
48
+ # delete it
49
+ EM.add_timer(0.01){ file.close; file.delete }
50
+ }
39
51
 
40
- # delete it
41
- EM.add_timer(0.25){ file.close; file.delete }
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
- assert_equal($path, $tmp_path)
45
- assert($modified)
46
- assert($deleted)
47
- assert($unbind)
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
@@ -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 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, EventMachine::Deferrable.future(100) )
12
+ assert_equal(100, EM::Deferrable.future(100) )
41
13
 
42
14
  p1 = proc { 100 + 1 }
43
- assert_equal(101, EventMachine::Deferrable.future(p1) )
15
+ assert_equal(101, EM::Deferrable.future(p1) )
44
16
  end
45
17
 
46
18
  class MyFuture
47
- include EventMachine::Deferrable
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 EventMachine::Deferrable
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
- EventMachine::Deferrable.future my_future, proc {|v| value=v}
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
- EventMachine::Deferrable.future MyErrorFuture.new, nil, proc {|v| value=v}
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
- EventMachine::Deferrable.future MyFuture.new do |v|
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 EventMachine::Deferrable
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(1)
165
+ d.timeout(0.01)
194
166
  }
195
167
  assert_equal( 2, n )
196
168
  end
@@ -1,30 +1,37 @@
1
- $:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
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
- def setup
9
- assert(!EM.reactor_running?)
10
- end
6
+ if EM.respond_to? :get_sock_opt
7
+ def setup
8
+ assert(!EM.reactor_running?)
9
+ end
11
10
 
12
- def teardown
13
- assert(!EM.reactor_running?)
14
- end
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
- def test_get_sock_opt
19
- test = self
20
- EM.run do
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
@@ -1,6 +1,4 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
1
+ require 'em_test_helper'
4
2
 
5
3
  class TestHandlerCheck < Test::Unit::TestCase
6
4