sidekick-client 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. data/VERSION +1 -1
  2. data/lib/sidekick/client/sidekick_client.rb +0 -3
  3. data/lib/sidekick/shared/sidekick_queue_publisher.rb +1 -1
  4. data/sidekick-client.gemspec +1 -158
  5. metadata +1 -158
  6. data/lib/ext/eventmachine-0.12.10/.gitignore +0 -14
  7. data/lib/ext/eventmachine-0.12.10/README +0 -82
  8. data/lib/ext/eventmachine-0.12.10/Rakefile +0 -374
  9. data/lib/ext/eventmachine-0.12.10/docs/COPYING +0 -60
  10. data/lib/ext/eventmachine-0.12.10/docs/ChangeLog +0 -211
  11. data/lib/ext/eventmachine-0.12.10/docs/DEFERRABLES +0 -133
  12. data/lib/ext/eventmachine-0.12.10/docs/EPOLL +0 -141
  13. data/lib/ext/eventmachine-0.12.10/docs/GNU +0 -281
  14. data/lib/ext/eventmachine-0.12.10/docs/INSTALL +0 -13
  15. data/lib/ext/eventmachine-0.12.10/docs/KEYBOARD +0 -38
  16. data/lib/ext/eventmachine-0.12.10/docs/LEGAL +0 -25
  17. data/lib/ext/eventmachine-0.12.10/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
  18. data/lib/ext/eventmachine-0.12.10/docs/PURE_RUBY +0 -75
  19. data/lib/ext/eventmachine-0.12.10/docs/RELEASE_NOTES +0 -94
  20. data/lib/ext/eventmachine-0.12.10/docs/SMTP +0 -2
  21. data/lib/ext/eventmachine-0.12.10/docs/SPAWNED_PROCESSES +0 -89
  22. data/lib/ext/eventmachine-0.12.10/docs/TODO +0 -8
  23. data/lib/ext/eventmachine-0.12.10/eventmachine.gemspec +0 -40
  24. data/lib/ext/eventmachine-0.12.10/examples/ex_channel.rb +0 -43
  25. data/lib/ext/eventmachine-0.12.10/examples/ex_queue.rb +0 -2
  26. data/lib/ext/eventmachine-0.12.10/examples/helper.rb +0 -2
  27. data/lib/ext/eventmachine-0.12.10/ext/binder.cpp +0 -125
  28. data/lib/ext/eventmachine-0.12.10/ext/binder.h +0 -46
  29. data/lib/ext/eventmachine-0.12.10/ext/cmain.cpp +0 -827
  30. data/lib/ext/eventmachine-0.12.10/ext/cplusplus.cpp +0 -202
  31. data/lib/ext/eventmachine-0.12.10/ext/ed.cpp +0 -1893
  32. data/lib/ext/eventmachine-0.12.10/ext/ed.h +0 -424
  33. data/lib/ext/eventmachine-0.12.10/ext/em.cpp +0 -2282
  34. data/lib/ext/eventmachine-0.12.10/ext/em.h +0 -232
  35. data/lib/ext/eventmachine-0.12.10/ext/emwin.cpp +0 -300
  36. data/lib/ext/eventmachine-0.12.10/ext/emwin.h +0 -94
  37. data/lib/ext/eventmachine-0.12.10/ext/epoll.cpp +0 -26
  38. data/lib/ext/eventmachine-0.12.10/ext/epoll.h +0 -25
  39. data/lib/ext/eventmachine-0.12.10/ext/eventmachine.h +0 -122
  40. data/lib/ext/eventmachine-0.12.10/ext/eventmachine_cpp.h +0 -96
  41. data/lib/ext/eventmachine-0.12.10/ext/extconf.rb +0 -148
  42. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/extconf.rb +0 -83
  43. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.cpp +0 -214
  44. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.h +0 -59
  45. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/rubymain.cpp +0 -127
  46. data/lib/ext/eventmachine-0.12.10/ext/files.cpp +0 -94
  47. data/lib/ext/eventmachine-0.12.10/ext/files.h +0 -65
  48. data/lib/ext/eventmachine-0.12.10/ext/kb.cpp +0 -81
  49. data/lib/ext/eventmachine-0.12.10/ext/page.cpp +0 -107
  50. data/lib/ext/eventmachine-0.12.10/ext/page.h +0 -51
  51. data/lib/ext/eventmachine-0.12.10/ext/pipe.cpp +0 -349
  52. data/lib/ext/eventmachine-0.12.10/ext/project.h +0 -151
  53. data/lib/ext/eventmachine-0.12.10/ext/rubymain.cpp +0 -1166
  54. data/lib/ext/eventmachine-0.12.10/ext/sigs.cpp +0 -89
  55. data/lib/ext/eventmachine-0.12.10/ext/sigs.h +0 -32
  56. data/lib/ext/eventmachine-0.12.10/ext/ssl.cpp +0 -460
  57. data/lib/ext/eventmachine-0.12.10/ext/ssl.h +0 -94
  58. data/lib/ext/eventmachine-0.12.10/java/.classpath +0 -8
  59. data/lib/ext/eventmachine-0.12.10/java/.project +0 -17
  60. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactor.java +0 -570
  61. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactorException.java +0 -40
  62. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableChannel.java +0 -69
  63. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableDatagramChannel.java +0 -189
  64. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableSocketChannel.java +0 -364
  65. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Application.java +0 -194
  66. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Connection.java +0 -74
  67. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
  68. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
  69. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
  70. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Timer.java +0 -54
  71. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
  72. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
  73. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
  74. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
  75. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
  76. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
  77. data/lib/ext/eventmachine-0.12.10/lib/em/buftok.rb +0 -138
  78. data/lib/ext/eventmachine-0.12.10/lib/em/callback.rb +0 -26
  79. data/lib/ext/eventmachine-0.12.10/lib/em/channel.rb +0 -57
  80. data/lib/ext/eventmachine-0.12.10/lib/em/connection.rb +0 -564
  81. data/lib/ext/eventmachine-0.12.10/lib/em/deferrable.rb +0 -192
  82. data/lib/ext/eventmachine-0.12.10/lib/em/file_watch.rb +0 -54
  83. data/lib/ext/eventmachine-0.12.10/lib/em/future.rb +0 -61
  84. data/lib/ext/eventmachine-0.12.10/lib/em/messages.rb +0 -66
  85. data/lib/ext/eventmachine-0.12.10/lib/em/process_watch.rb +0 -44
  86. data/lib/ext/eventmachine-0.12.10/lib/em/processes.rb +0 -119
  87. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/header_and_content.rb +0 -138
  88. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient.rb +0 -263
  89. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient2.rb +0 -590
  90. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/line_and_text.rb +0 -125
  91. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/linetext2.rb +0 -161
  92. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/memcache.rb +0 -323
  93. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/object_protocol.rb +0 -45
  94. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/postgres3.rb +0 -247
  95. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/saslauth.rb +0 -175
  96. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpclient.rb +0 -357
  97. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpserver.rb +0 -547
  98. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/socks4.rb +0 -66
  99. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/stomp.rb +0 -200
  100. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/tcptest.rb +0 -53
  101. data/lib/ext/eventmachine-0.12.10/lib/em/protocols.rb +0 -36
  102. data/lib/ext/eventmachine-0.12.10/lib/em/queue.rb +0 -61
  103. data/lib/ext/eventmachine-0.12.10/lib/em/spawnable.rb +0 -85
  104. data/lib/ext/eventmachine-0.12.10/lib/em/streamer.rb +0 -130
  105. data/lib/ext/eventmachine-0.12.10/lib/em/timers.rb +0 -56
  106. data/lib/ext/eventmachine-0.12.10/lib/em/version.rb +0 -3
  107. data/lib/ext/eventmachine-0.12.10/lib/eventmachine.rb +0 -1592
  108. data/lib/ext/eventmachine-0.12.10/lib/evma/callback.rb +0 -32
  109. data/lib/ext/eventmachine-0.12.10/lib/evma/container.rb +0 -75
  110. data/lib/ext/eventmachine-0.12.10/lib/evma/factory.rb +0 -77
  111. data/lib/ext/eventmachine-0.12.10/lib/evma/protocol.rb +0 -87
  112. data/lib/ext/eventmachine-0.12.10/lib/evma/reactor.rb +0 -48
  113. data/lib/ext/eventmachine-0.12.10/lib/evma.rb +0 -32
  114. data/lib/ext/eventmachine-0.12.10/lib/jeventmachine.rb +0 -257
  115. data/lib/ext/eventmachine-0.12.10/lib/pr_eventmachine.rb +0 -1022
  116. data/lib/ext/eventmachine-0.12.10/setup.rb +0 -1585
  117. data/lib/ext/eventmachine-0.12.10/tasks/cpp.rake_example +0 -77
  118. data/lib/ext/eventmachine-0.12.10/tests/client.crt +0 -31
  119. data/lib/ext/eventmachine-0.12.10/tests/client.key +0 -51
  120. data/lib/ext/eventmachine-0.12.10/tests/test_attach.rb +0 -126
  121. data/lib/ext/eventmachine-0.12.10/tests/test_basic.rb +0 -284
  122. data/lib/ext/eventmachine-0.12.10/tests/test_channel.rb +0 -63
  123. data/lib/ext/eventmachine-0.12.10/tests/test_connection_count.rb +0 -35
  124. data/lib/ext/eventmachine-0.12.10/tests/test_defer.rb +0 -47
  125. data/lib/ext/eventmachine-0.12.10/tests/test_epoll.rb +0 -160
  126. data/lib/ext/eventmachine-0.12.10/tests/test_error_handler.rb +0 -35
  127. data/lib/ext/eventmachine-0.12.10/tests/test_errors.rb +0 -82
  128. data/lib/ext/eventmachine-0.12.10/tests/test_exc.rb +0 -55
  129. data/lib/ext/eventmachine-0.12.10/tests/test_file_watch.rb +0 -49
  130. data/lib/ext/eventmachine-0.12.10/tests/test_futures.rb +0 -198
  131. data/lib/ext/eventmachine-0.12.10/tests/test_get_sock_opt.rb +0 -30
  132. data/lib/ext/eventmachine-0.12.10/tests/test_handler_check.rb +0 -37
  133. data/lib/ext/eventmachine-0.12.10/tests/test_hc.rb +0 -218
  134. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb +0 -218
  135. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb +0 -153
  136. data/lib/ext/eventmachine-0.12.10/tests/test_inactivity_timeout.rb +0 -50
  137. data/lib/ext/eventmachine-0.12.10/tests/test_kb.rb +0 -60
  138. data/lib/ext/eventmachine-0.12.10/tests/test_ltp.rb +0 -182
  139. data/lib/ext/eventmachine-0.12.10/tests/test_ltp2.rb +0 -317
  140. data/lib/ext/eventmachine-0.12.10/tests/test_next_tick.rb +0 -133
  141. data/lib/ext/eventmachine-0.12.10/tests/test_object_protocol.rb +0 -37
  142. data/lib/ext/eventmachine-0.12.10/tests/test_pause.rb +0 -70
  143. data/lib/ext/eventmachine-0.12.10/tests/test_pending_connect_timeout.rb +0 -48
  144. data/lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb +0 -48
  145. data/lib/ext/eventmachine-0.12.10/tests/test_processes.rb +0 -128
  146. data/lib/ext/eventmachine-0.12.10/tests/test_proxy_connection.rb +0 -92
  147. data/lib/ext/eventmachine-0.12.10/tests/test_pure.rb +0 -125
  148. data/lib/ext/eventmachine-0.12.10/tests/test_queue.rb +0 -44
  149. data/lib/ext/eventmachine-0.12.10/tests/test_running.rb +0 -42
  150. data/lib/ext/eventmachine-0.12.10/tests/test_sasl.rb +0 -72
  151. data/lib/ext/eventmachine-0.12.10/tests/test_send_file.rb +0 -242
  152. data/lib/ext/eventmachine-0.12.10/tests/test_servers.rb +0 -76
  153. data/lib/ext/eventmachine-0.12.10/tests/test_smtpclient.rb +0 -83
  154. data/lib/ext/eventmachine-0.12.10/tests/test_smtpserver.rb +0 -85
  155. data/lib/ext/eventmachine-0.12.10/tests/test_spawn.rb +0 -322
  156. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_args.rb +0 -79
  157. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_methods.rb +0 -50
  158. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_verify.rb +0 -82
  159. data/lib/ext/eventmachine-0.12.10/tests/test_timers.rb +0 -162
  160. data/lib/ext/eventmachine-0.12.10/tests/test_ud.rb +0 -36
  161. data/lib/ext/eventmachine-0.12.10/tests/testem.rb +0 -31
  162. data/lib/ext/eventmachine-0.12.10/web/whatis +0 -7
@@ -1,322 +0,0 @@
1
- # $Id$
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'
32
-
33
-
34
-
35
- class TestSpawn < Test::Unit::TestCase
36
-
37
- # Spawn a process that simply stops the reactor.
38
- # Assert that the notification runs after the block that calls it.
39
- #
40
- def test_stop
41
- x = nil
42
- EM.run {
43
- s = EM.spawn {EM.stop}
44
- s.notify
45
- x = true
46
- }
47
- assert x
48
- end
49
-
50
-
51
- # Pass a parameter to a spawned process.
52
- #
53
- def test_parms
54
- val = 5
55
- EM.run {
56
- s = EM.spawn {|v| val *= v; EM.stop}
57
- s.notify 3
58
- }
59
- assert_equal( 15, val )
60
- end
61
-
62
- # Pass multiple parameters to a spawned process.
63
- #
64
- def test_multiparms
65
- val = 5
66
- EM.run {
67
- s = EM.spawn {|v1,v2| val *= (v1 + v2); EM.stop}
68
- s.notify 3,4
69
- }
70
- assert_equal( 35, val )
71
- end
72
-
73
-
74
- # This test demonstrates that a notification does not happen immediately,
75
- # but rather is scheduled sometime after the current code path completes.
76
- #
77
- def test_race
78
- x = 0
79
- EM.run {
80
- s = EM.spawn {x *= 2; EM.stop}
81
- s.notify
82
- x = 2
83
- }
84
- assert_equal( 4, x)
85
- end
86
-
87
-
88
- # Spawn a process and notify it 25 times to run fibonacci
89
- # on a pair of global variables.
90
- #
91
- def test_fibonacci
92
- x = 1
93
- y = 1
94
- EM.run {
95
- s = EM.spawn {x,y = y,x+y}
96
- 25.times {s.notify}
97
-
98
- t = EM.spawn {EM.stop}
99
- t.notify
100
- }
101
- assert_equal( 121393, x)
102
- assert_equal( 196418, y)
103
- end
104
-
105
- # This one spawns 25 distinct processes, and notifies each one once,
106
- # rather than notifying a single process 25 times.
107
- #
108
- def test_another_fibonacci
109
- x = 1
110
- y = 1
111
- EM.run {
112
- 25.times {
113
- s = EM.spawn {x,y = y,x+y}
114
- s.notify
115
- }
116
-
117
- t = EM.spawn {EM.stop}
118
- t.notify
119
- }
120
- assert_equal( 121393, x)
121
- assert_equal( 196418, y)
122
- end
123
-
124
-
125
- # Make a chain of processes that notify each other in turn
126
- # with intermediate fibonacci results. The final process in
127
- # the chain stops the loop and returns the result.
128
- #
129
- def test_fibonacci_chain
130
- a,b = nil
131
-
132
- EM.run {
133
- nextpid = EM.spawn {|x,y|
134
- a,b = x,y
135
- EM.stop
136
- }
137
-
138
- 25.times {
139
- n = nextpid
140
- nextpid = EM.spawn {|x,y| n.notify( y, x+y )}
141
- }
142
-
143
- nextpid.notify( 1, 1 )
144
- }
145
-
146
- assert_equal( 121393, a)
147
- assert_equal( 196418, b)
148
- end
149
-
150
-
151
- # EM#yield gives a spawed process to yield control to other processes
152
- # (in other words, to stop running), and to specify a different code block
153
- # that will run on its next notification.
154
- #
155
- def test_yield
156
- a = 0
157
- EM.run {
158
- n = EM.spawn {
159
- a += 10
160
- EM.yield {
161
- a += 20
162
- EM.yield {
163
- a += 30
164
- EM.stop
165
- }
166
- }
167
- }
168
- n.notify
169
- n.notify
170
- n.notify
171
- }
172
- assert_equal( 60, a )
173
- end
174
-
175
- # EM#yield_and_notify behaves like EM#yield, except that it also notifies the
176
- # yielding process. This may sound trivial, since the yield block will run very
177
- # shortly after with no action by the program, but this actually can be very useful,
178
- # because it causes the reactor core to execute once before the yielding process
179
- # gets control back. So it can be used to allow heavily-used network connections
180
- # to clear buffers, or allow other processes to process their notifications.
181
- #
182
- # Notice in this test code that only a simple notify is needed at the bottom
183
- # of the initial block. Even so, all of the yielded blocks will execute.
184
- #
185
- def test_yield_and_notify
186
- a = 0
187
- EM.run {
188
- n = EM.spawn {
189
- a += 10
190
- EM.yield_and_notify {
191
- a += 20
192
- EM.yield_and_notify {
193
- a += 30
194
- EM.stop
195
- }
196
- }
197
- }
198
- n.notify
199
- }
200
- assert_equal( 60, a )
201
- end
202
-
203
- # resume is an alias for notify.
204
- #
205
- def test_resume
206
- EM.run {
207
- n = EM.spawn {EM.stop}
208
- n.resume
209
- }
210
- assert true
211
- end
212
-
213
- # run is an idiomatic alias for notify.
214
- #
215
- def test_run
216
- EM.run {
217
- (EM.spawn {EM.stop}).run
218
- }
219
- assert true
220
- end
221
-
222
-
223
- # Clones the ping-pong example from the Erlang tutorial, in much less code.
224
- # Illustrates that a spawned block executes in the context of a SpawnableObject.
225
- # (Meaning, we can pass self as a parameter to another process that can then
226
- # notify us.)
227
- #
228
- def test_ping_pong
229
- n_pongs = 0
230
- EM.run {
231
- pong = EM.spawn {|x, ping|
232
- n_pongs += 1
233
- ping.notify( x-1 )
234
- }
235
- ping = EM.spawn {|x|
236
- if x > 0
237
- pong.notify x, self
238
- else
239
- EM.stop
240
- end
241
- }
242
- ping.notify 3
243
- }
244
- assert_equal( 3, n_pongs )
245
- end
246
-
247
- # Illustrates that you can call notify inside a notification, and it will cause
248
- # the currently-executing process to be re-notified. Of course, the new notification
249
- # won't run until sometime after the current one completes.
250
- #
251
- def test_self_notify
252
- n = 0
253
- EM.run {
254
- pid = EM.spawn {|x|
255
- if x > 0
256
- n += x
257
- notify( x-1 )
258
- else
259
- EM.stop
260
- end
261
- }
262
- pid.notify 3
263
- }
264
- assert_equal( 6, n )
265
- end
266
-
267
-
268
- # Illustrates that the block passed to #spawn executes in the context of a
269
- # SpawnedProcess object, NOT in the local context. This can often be deceptive.
270
- #
271
- class BlockScopeTest
272
- attr_reader :var
273
- def run
274
- # The following line correctly raises a NameError.
275
- # The problem is that the programmer expected the spawned block to
276
- # execute in the local context, but it doesn't.
277
- #
278
- # (EM.spawn { do_something }).notify ### NO! BAD!
279
-
280
-
281
-
282
- # The following line correctly passes self as a parameter to the
283
- # notified process.
284
- #
285
- (EM.spawn {|obj| obj.do_something }).notify(self)
286
-
287
-
288
-
289
- # Here's another way to do it. This works because "myself" is bound
290
- # in the local scope, unlike "self," so the spawned block sees it.
291
- #
292
- myself = self
293
- (EM.spawn { myself.do_something }).notify
294
-
295
-
296
-
297
- # And we end the loop.
298
- # This is a tangential point, but observe that #notify never blocks.
299
- # It merely appends a message to the internal queue of a spawned process
300
- # and returns. As it turns out, the reactor processes notifications for ALL
301
- # spawned processes in the order that #notify is called. So there is a
302
- # reasonable expectation that the process which stops the reactor will
303
- # execute after the previous ones in this method. HOWEVER, this is NOT
304
- # a documented behavior and is subject to change.
305
- #
306
- (EM.spawn {EM.stop}).notify
307
- end
308
- def do_something
309
- @var ||= 0
310
- @var += 100
311
- end
312
- end
313
-
314
- def test_block_scope
315
- bs = BlockScopeTest.new
316
- EM.run {
317
- bs.run
318
- }
319
- assert_equal( 200, bs.var )
320
- end
321
-
322
- end
@@ -1,79 +0,0 @@
1
- require "test/unit"
2
- require 'tempfile'
3
-
4
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
5
- require "eventmachine"
6
-
7
- module EventMachine
8
- def self._set_mocks
9
- class <<self
10
- alias set_tls_parms_old set_tls_parms
11
- alias start_tls_old start_tls
12
- begin
13
- old, $VERBOSE = $VERBOSE, nil
14
- def set_tls_parms *args; end
15
- def start_tls *args; end
16
- ensure
17
- $VERBOSE = old
18
- end
19
- end
20
- end
21
-
22
- def self._clear_mocks
23
- class <<self
24
- begin
25
- old, $VERBOSE = $VERBOSE, nil
26
- alias set_tls_parms set_tls_parms_old
27
- alias start_tls start_tls_old
28
- ensure
29
- $VERBOSE = old
30
- end
31
- end
32
- end
33
- end
34
-
35
-
36
-
37
- class TestSslArgs < Test::Unit::TestCase
38
- def setup
39
- EventMachine._set_mocks
40
- end
41
-
42
- def teardown
43
- EventMachine._clear_mocks
44
- end
45
-
46
- def test_tls_params_file_doesnt_exist
47
- priv_file, cert_file = 'foo_priv_key', 'bar_cert_file'
48
- [priv_file, cert_file].all? do |f|
49
- assert(!File.exists?(f), "Cert file #{f} seems to exist, and should not for the tests")
50
- end
51
-
52
- # associate_callback_target is a pain! (build!)
53
- conn = EventMachine::Connection.new('foo')
54
-
55
- assert_raises(EventMachine::FileNotFoundException) do
56
- conn.start_tls(:private_key_file => priv_file)
57
- end
58
- assert_raises(EventMachine::FileNotFoundException) do
59
- conn.start_tls(:cert_chain_file => cert_file)
60
- end
61
- assert_raises(EventMachine::FileNotFoundException) do
62
- conn.start_tls(:private_key_file => priv_file, :cert_chain_file => cert_file)
63
- end
64
- end
65
-
66
- def test_tls_params_file_does_exist
67
- priv_file = Tempfile.new('em_test')
68
- cert_file = Tempfile.new('em_test')
69
- priv_file_path = priv_file.path
70
- cert_file_path = cert_file.path
71
- conn = EventMachine::Connection.new('foo')
72
- params = {:private_key_file => priv_file_path, :cert_chain_file => cert_file_path}
73
- begin
74
- conn.start_tls params
75
- rescue Object
76
- assert(false, 'should not have raised an exception')
77
- end
78
- end
79
- end if EM.ssl?
@@ -1,50 +0,0 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
4
-
5
- class TestSSLMethods < Test::Unit::TestCase
6
-
7
- module ServerHandler
8
-
9
- def post_init
10
- start_tls
11
- end
12
-
13
- def ssl_handshake_completed
14
- $server_called_back = true
15
- $server_cert_value = get_peer_cert
16
- end
17
-
18
- end
19
-
20
- module ClientHandler
21
-
22
- def post_init
23
- start_tls
24
- end
25
-
26
- def ssl_handshake_completed
27
- $client_called_back = true
28
- $client_cert_value = get_peer_cert
29
- EM.stop_event_loop
30
- end
31
-
32
- end
33
-
34
- def test_ssl_methods
35
- $server_called_back, $client_called_back = false, false
36
- $server_cert_value, $client_cert_value = nil, nil
37
-
38
- EM.run {
39
- EM.start_server("127.0.0.1", 9999, ServerHandler)
40
- EM.connect("127.0.0.1", 9999, ClientHandler)
41
- }
42
-
43
- assert($server_called_back)
44
- assert($client_called_back)
45
-
46
- assert($server_cert_value.is_a?(NilClass))
47
- assert($client_cert_value.is_a?(String))
48
- end
49
-
50
- end if EM.ssl?
@@ -1,82 +0,0 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
4
-
5
- class TestSslVerify < Test::Unit::TestCase
6
-
7
- def setup
8
- $dir = File.dirname(File.expand_path(__FILE__)) + '/'
9
- $cert_from_file = File.read($dir+'client.crt')
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')
15
- end
16
-
17
- def ssl_handshake_completed
18
- $client_handshake_completed = true
19
- close_connection
20
- end
21
-
22
- def unbind
23
- EM.stop_event_loop
24
- end
25
- end
26
-
27
- module AcceptServer
28
- def post_init
29
- start_tls(:verify_peer => true)
30
- end
31
-
32
- def ssl_verify_peer(cert)
33
- $cert_from_server = cert
34
- true
35
- end
36
-
37
- def ssl_handshake_completed
38
- $server_handshake_completed = true
39
- end
40
- end
41
-
42
- module DenyServer
43
- def post_init
44
- start_tls(:verify_peer => true)
45
- end
46
-
47
- def ssl_verify_peer(cert)
48
- $cert_from_server = cert
49
- # Do not accept the peer. This should now cause the connection to shut down without the SSL handshake being completed.
50
- false
51
- end
52
-
53
- def ssl_handshake_completed
54
- $server_handshake_completed = true
55
- end
56
- end
57
-
58
- def test_accept_server
59
- $client_handshake_completed, $server_handshake_completed = false, false
60
- EM.run {
61
- EM.start_server("127.0.0.1", 16784, AcceptServer)
62
- EM.connect("127.0.0.1", 16784, Client).instance_variable_get("@signature")
63
- }
64
-
65
- assert_equal($cert_from_file, $cert_from_server)
66
- assert($client_handshake_completed)
67
- assert($server_handshake_completed)
68
- end
69
-
70
- def test_deny_server
71
- $client_handshake_completed, $server_handshake_completed = false, false
72
- EM.run {
73
- EM.start_server("127.0.0.1", 16784, DenyServer)
74
- EM.connect("127.0.0.1", 16784, Client)
75
- }
76
-
77
- assert_equal($cert_from_file, $cert_from_server)
78
- assert(!$client_handshake_completed)
79
- assert(!$server_handshake_completed)
80
- end
81
-
82
- end
@@ -1,162 +0,0 @@
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
-
28
- $:.unshift "../lib"
29
- require 'eventmachine'
30
- require 'test/unit'
31
-
32
- class TestTimers < Test::Unit::TestCase
33
-
34
- def test_timer_with_block
35
- x = false
36
- EventMachine.run {
37
- EventMachine::Timer.new(0.25) {
38
- x = true
39
- EventMachine.stop
40
- }
41
- }
42
- assert x
43
- end
44
-
45
- def test_timer_with_proc
46
- x = false
47
- EventMachine.run {
48
- EventMachine::Timer.new(0.25, proc {
49
- x = true
50
- EventMachine.stop
51
- })
52
- }
53
- assert x
54
- end
55
-
56
- def test_timer_cancel
57
- x = true
58
- EventMachine.run {
59
- timer = EventMachine::Timer.new(0.25, proc { x = false })
60
- timer.cancel
61
- EventMachine::Timer.new(0.5, proc {EventMachine.stop})
62
- }
63
- assert x
64
- end
65
-
66
- def test_periodic_timer
67
- x = 0
68
- EventMachine.run {
69
- EventMachine::PeriodicTimer.new(0.1) do
70
- x += 1
71
- EventMachine.stop if x == 4
72
- end
73
- }
74
- assert( x == 4 )
75
- end
76
-
77
- def test_add_periodic_timer
78
- x = 0
79
- EM.run {
80
- t = EM.add_periodic_timer(0.1) do
81
- x += 1
82
- EM.stop if x == 4
83
- end
84
- assert t.respond_to?(:cancel)
85
- }
86
- end
87
-
88
- def test_periodic_timer_cancel
89
- x = 0
90
- EventMachine.run {
91
- pt = EventMachine::PeriodicTimer.new(0.25, proc { x += 1 })
92
- pt.cancel
93
- EventMachine::Timer.new(0.5) {EventMachine.stop}
94
- }
95
- assert( x == 0 )
96
- end
97
-
98
- def test_add_periodic_timer_cancel
99
- x = 0
100
- EventMachine.run {
101
- pt = EM.add_periodic_timer(0.25) { x += 1 }
102
- EM.cancel_timer(pt)
103
- EM.add_timer(0.5) { EM.stop }
104
- }
105
- assert( x == 0 )
106
- end
107
-
108
- def test_periodic_timer_self_cancel
109
- x = 0
110
- EventMachine.run {
111
- pt = EventMachine::PeriodicTimer.new(0.1) {
112
- x += 1
113
- if x == 4
114
- pt.cancel
115
- EventMachine.stop
116
- end
117
- }
118
- }
119
- assert( x == 4 )
120
- end
121
-
122
-
123
- # This test is only applicable to compiled versions of the reactor.
124
- # Pure ruby and java versions have no built-in limit on the number of outstanding timers.
125
- #
126
- def test_timer_change_max_outstanding
127
- ten_thousand_timers = proc {
128
- 10001.times {
129
- EM.add_timer(5) {}
130
- }
131
- }
132
-
133
- EM.run {
134
- if EM.library_type == :pure_ruby
135
- ten_thousand_timers.call
136
- elsif EM.library_type == :java
137
- ten_thousand_timers.call
138
- else
139
- begin
140
- assert_raises( RuntimeError ) {
141
- ten_thousand_timers.call
142
- }
143
- rescue Object
144
- p $!
145
- assert(false, $!.message)
146
- end
147
- end
148
- EM.stop
149
- }
150
-
151
- assert(!EM.reactor_running?, 'Reactor running when it should not be.')
152
- assert( EM.get_max_timers != 10001 )
153
- EM.set_max_timers( 10001 )
154
- assert( EM.get_max_timers == 10001 )
155
-
156
- EM.run {
157
- ten_thousand_timers.call
158
- EM.stop
159
- }
160
- end
161
-
162
- end