faye 0.8.8 → 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of faye might be problematic. Click here for more details.
- data/History.txt +16 -10
- data/README.rdoc +1 -1
- data/lib/faye-browser-min.js +1 -1
- data/lib/faye-browser-min.js.map +2 -2
- data/lib/faye-browser.js +302 -287
- data/lib/faye.rb +21 -21
- data/lib/faye/adapters/rack_adapter.rb +50 -48
- data/lib/faye/adapters/static_server.rb +22 -22
- data/lib/faye/engines/connection.rb +13 -13
- data/lib/faye/engines/memory.rb +21 -21
- data/lib/faye/engines/proxy.rb +23 -23
- data/lib/faye/error.rb +6 -6
- data/lib/faye/mixins/logging.rb +12 -12
- data/lib/faye/mixins/publisher.rb +6 -6
- data/lib/faye/mixins/timeouts.rb +1 -1
- data/lib/faye/protocol/channel.rb +24 -24
- data/lib/faye/protocol/client.rb +71 -73
- data/lib/faye/protocol/extensible.rb +7 -7
- data/lib/faye/protocol/grammar.rb +13 -13
- data/lib/faye/protocol/server.rb +57 -57
- data/lib/faye/protocol/socket.rb +4 -4
- data/lib/faye/protocol/subscription.rb +4 -4
- data/lib/faye/transport/http.rb +13 -13
- data/lib/faye/transport/local.rb +5 -5
- data/lib/faye/transport/transport.rb +25 -25
- data/lib/faye/transport/web_socket.rb +34 -30
- data/lib/faye/util/namespace.rb +4 -4
- data/spec/browser.html +5 -5
- data/spec/javascript/channel_spec.js +3 -3
- data/spec/javascript/client_spec.js +104 -98
- data/spec/javascript/engine/memory_spec.js +1 -1
- data/spec/javascript/engine_spec.js +70 -70
- data/spec/javascript/faye_spec.js +6 -6
- data/spec/javascript/grammar_spec.js +12 -12
- data/spec/javascript/node_adapter_spec.js +46 -46
- data/spec/javascript/publisher_spec.js +4 -4
- data/spec/javascript/server/connect_spec.js +21 -21
- data/spec/javascript/server/disconnect_spec.js +15 -15
- data/spec/javascript/server/extensions_spec.js +6 -6
- data/spec/javascript/server/handshake_spec.js +18 -18
- data/spec/javascript/server/integration_spec.js +23 -23
- data/spec/javascript/server/publish_spec.js +9 -9
- data/spec/javascript/server/subscribe_spec.js +30 -30
- data/spec/javascript/server/unsubscribe_spec.js +30 -30
- data/spec/javascript/server_spec.js +15 -15
- data/spec/javascript/transport_spec.js +32 -27
- data/spec/node.js +2 -2
- data/spec/ruby/channel_spec.rb +2 -2
- data/spec/ruby/client_spec.rb +100 -92
- data/spec/ruby/engine_examples.rb +51 -51
- data/spec/ruby/faye_spec.rb +5 -5
- data/spec/ruby/grammar_spec.rb +12 -12
- data/spec/ruby/publisher_spec.rb +4 -4
- data/spec/ruby/rack_adapter_spec.rb +34 -34
- data/spec/ruby/server/connect_spec.rb +22 -22
- data/spec/ruby/server/disconnect_spec.rb +16 -16
- data/spec/ruby/server/extensions_spec.rb +8 -8
- data/spec/ruby/server/handshake_spec.rb +20 -20
- data/spec/ruby/server/integration_spec.rb +22 -24
- data/spec/ruby/server/publish_spec.rb +9 -9
- data/spec/ruby/server/subscribe_spec.rb +31 -31
- data/spec/ruby/server/unsubscribe_spec.rb +31 -31
- data/spec/ruby/server_spec.rb +17 -17
- data/spec/ruby/transport_spec.rb +23 -23
- data/spec/testswarm +23 -10
- data/spec/thin_proxy.rb +5 -5
- metadata +90 -59
@@ -23,7 +23,7 @@ EngineSteps = EM::RSpec.async_steps do
|
|
23
23
|
resume.call
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def connect(name, engine, &resume)
|
28
28
|
engine.connect(@clients[name]) do |m|
|
29
29
|
m.each do |message|
|
@@ -33,38 +33,38 @@ EngineSteps = EM::RSpec.async_steps do
|
|
33
33
|
end
|
34
34
|
EM.add_timer(0.01, &resume)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def destroy_client(name, &resume)
|
38
38
|
engine.destroy_client(@clients[name], &resume)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def check_client_id(name, pattern, &resume)
|
42
42
|
@clients[name].should =~ pattern
|
43
43
|
resume.call
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def check_num_clients(n, &resume)
|
47
47
|
ids = Set.new
|
48
48
|
@clients.each { |name,id| ids.add(id) }
|
49
49
|
ids.size.should == n
|
50
50
|
resume.call
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def check_client_exists(name, exists, &resume)
|
54
54
|
engine.client_exists(@clients[name]) do |actual|
|
55
55
|
actual.should == exists
|
56
56
|
resume.call
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def subscribe(name, channel, &resume)
|
61
61
|
engine.subscribe(@clients[name], channel, &resume)
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def unsubscribe(name, channel, &resume)
|
65
65
|
engine.unsubscribe(@clients[name], channel, &resume)
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def publish(messages, &resume)
|
69
69
|
messages = [messages].flatten
|
70
70
|
messages.each do |message|
|
@@ -73,7 +73,7 @@ EngineSteps = EM::RSpec.async_steps do
|
|
73
73
|
end
|
74
74
|
EM.add_timer(0.01, &resume)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def publish_by(name, message, &resume)
|
78
78
|
message = {"clientId" => @clients[name], "id" => Faye::Engine.random}.merge(message)
|
79
79
|
engine.publish(message)
|
@@ -84,12 +84,12 @@ EngineSteps = EM::RSpec.async_steps do
|
|
84
84
|
engine.ping(@clients[name])
|
85
85
|
resume.call
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def clock_tick(time, &resume)
|
89
89
|
clock.tick(time)
|
90
90
|
resume.call
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
def expect_event(name, event, args, &resume)
|
94
94
|
params = [@clients[name]] + args
|
95
95
|
handler = lambda { |*a| }
|
@@ -110,12 +110,12 @@ EngineSteps = EM::RSpec.async_steps do
|
|
110
110
|
@inboxes[name].should == messages
|
111
111
|
resume.call
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
def expect_no_message(name, &resume)
|
115
115
|
@inboxes[name].should == []
|
116
116
|
resume.call
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
def check_different_messages(a, b, &resume)
|
120
120
|
@inboxes[a].first.should_not be_equal(@inboxes[b].first)
|
121
121
|
resume.call
|
@@ -126,15 +126,15 @@ describe "Pub/sub engines" do
|
|
126
126
|
shared_examples_for "faye engine" do
|
127
127
|
include EncodingHelper
|
128
128
|
include EngineSteps
|
129
|
-
|
129
|
+
|
130
130
|
def create_engine
|
131
131
|
opts = options.merge(engine_opts)
|
132
132
|
Faye::Engine::Proxy.new(opts)
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
let(:options) { {:timeout => 1} }
|
136
136
|
let(:engine) { create_engine }
|
137
|
-
|
137
|
+
|
138
138
|
before do
|
139
139
|
Faye.stub(:logger)
|
140
140
|
Faye::Engine.ensure_reactor_running!
|
@@ -142,13 +142,13 @@ describe "Pub/sub engines" do
|
|
142
142
|
create_client :bob
|
143
143
|
create_client :carol
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
describe :create_client do
|
147
147
|
it "returns a client id" do
|
148
148
|
create_client :dave
|
149
149
|
check_client_id :dave, /^[a-z0-9]+$/
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
it "returns a different id every time" do
|
153
153
|
1.upto(7) { |i| create_client "client#{i}" }
|
154
154
|
check_num_clients 10
|
@@ -159,12 +159,12 @@ describe "Pub/sub engines" do
|
|
159
159
|
create_client :dave
|
160
160
|
end
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
describe :client_exists do
|
164
164
|
it "returns true if the client id exists" do
|
165
165
|
check_client_exists :alice, true
|
166
166
|
end
|
167
|
-
|
167
|
+
|
168
168
|
it "returns false if the client id does not exist" do
|
169
169
|
check_client_exists :anything, false
|
170
170
|
end
|
@@ -175,7 +175,7 @@ describe "Pub/sub engines" do
|
|
175
175
|
clock_tick 2
|
176
176
|
check_client_exists :alice, false
|
177
177
|
end
|
178
|
-
|
178
|
+
|
179
179
|
it "prolongs the life of a client" do
|
180
180
|
clock_tick 1
|
181
181
|
ping :alice
|
@@ -191,7 +191,7 @@ describe "Pub/sub engines" do
|
|
191
191
|
destroy_client :alice
|
192
192
|
check_client_exists :alice, false
|
193
193
|
end
|
194
|
-
|
194
|
+
|
195
195
|
it "publishes an event" do
|
196
196
|
expect_event :alice, :disconnect, []
|
197
197
|
destroy_client :alice
|
@@ -202,7 +202,7 @@ describe "Pub/sub engines" do
|
|
202
202
|
@message = {"channel" => "/messages/foo", "data" => "ok"}
|
203
203
|
subscribe :alice, "/messages/foo"
|
204
204
|
end
|
205
|
-
|
205
|
+
|
206
206
|
it "stops the client receiving messages" do
|
207
207
|
connect :alice, engine
|
208
208
|
destroy_client :alice
|
@@ -222,10 +222,10 @@ describe "Pub/sub engines" do
|
|
222
222
|
expect_event :alice, :subscribe, ["/messages/foo"]
|
223
223
|
subscribe :alice, "/messages/foo"
|
224
224
|
end
|
225
|
-
|
225
|
+
|
226
226
|
describe "when the client is subscribed to the channel" do
|
227
227
|
before { subscribe :alice, "/messages/foo" }
|
228
|
-
|
228
|
+
|
229
229
|
it "does not publish an event" do
|
230
230
|
expect_no_event :alice, :subscribe, ["/messages/foo"]
|
231
231
|
subscribe :alice, "/messages/foo"
|
@@ -235,7 +235,7 @@ describe "Pub/sub engines" do
|
|
235
235
|
|
236
236
|
describe :unsubscribe do
|
237
237
|
before { subscribe :alice, "/messages/bar" }
|
238
|
-
|
238
|
+
|
239
239
|
it "does not publish an event" do
|
240
240
|
expect_no_event :alice, :unsubscribe, ["/messages/foo"]
|
241
241
|
unsubscribe :alice, "/messages/foo"
|
@@ -250,7 +250,7 @@ describe "Pub/sub engines" do
|
|
250
250
|
end
|
251
251
|
end
|
252
252
|
end
|
253
|
-
|
253
|
+
|
254
254
|
describe :publish do
|
255
255
|
before do
|
256
256
|
@message = {"channel" => "/messages/foo", "data" => "ok", "blank" => nil}
|
@@ -258,7 +258,7 @@ describe "Pub/sub engines" do
|
|
258
258
|
connect :bob, engine
|
259
259
|
connect :carol, engine
|
260
260
|
end
|
261
|
-
|
261
|
+
|
262
262
|
describe "with no subscriptions" do
|
263
263
|
it "delivers no messages" do
|
264
264
|
publish @message
|
@@ -277,15 +277,15 @@ describe "Pub/sub engines" do
|
|
277
277
|
publish @message
|
278
278
|
end
|
279
279
|
end
|
280
|
-
|
280
|
+
|
281
281
|
describe "with a subscriber" do
|
282
282
|
before { subscribe :alice, "/messages/foo" }
|
283
|
-
|
283
|
+
|
284
284
|
it "delivers messages to the subscribed client" do
|
285
285
|
publish @message
|
286
286
|
expect_message :alice, [@message]
|
287
287
|
end
|
288
|
-
|
288
|
+
|
289
289
|
it "delivers multibyte messages correctly" do
|
290
290
|
@message["data"] = encode "Apple = "
|
291
291
|
publish @message
|
@@ -297,13 +297,13 @@ describe "Pub/sub engines" do
|
|
297
297
|
publish_by :bob, @message
|
298
298
|
end
|
299
299
|
end
|
300
|
-
|
300
|
+
|
301
301
|
describe "with a subscriber that is removed" do
|
302
302
|
before do
|
303
303
|
subscribe :alice, "/messages/foo"
|
304
304
|
unsubscribe :alice, "/messages/foo"
|
305
305
|
end
|
306
|
-
|
306
|
+
|
307
307
|
it "does not deliver messages to unsubscribed clients" do
|
308
308
|
publish @message
|
309
309
|
expect_no_message :alice
|
@@ -316,14 +316,14 @@ describe "Pub/sub engines" do
|
|
316
316
|
publish_by :bob, @message
|
317
317
|
end
|
318
318
|
end
|
319
|
-
|
319
|
+
|
320
320
|
describe "with multiple subscribers" do
|
321
321
|
before do
|
322
322
|
subscribe :alice, "/messages/foo"
|
323
323
|
subscribe :bob, "/messages/bar"
|
324
324
|
subscribe :carol, "/messages/foo"
|
325
325
|
end
|
326
|
-
|
326
|
+
|
327
327
|
it "delivers messages to the subscribed clients" do
|
328
328
|
publish @message
|
329
329
|
expect_message :alice, [@message]
|
@@ -331,14 +331,14 @@ describe "Pub/sub engines" do
|
|
331
331
|
expect_message :carol, [@message]
|
332
332
|
end
|
333
333
|
end
|
334
|
-
|
334
|
+
|
335
335
|
describe "with a single wildcard" do
|
336
336
|
before do
|
337
337
|
subscribe :alice, "/messages/*"
|
338
338
|
subscribe :bob, "/messages/bar"
|
339
339
|
subscribe :carol, "/*"
|
340
340
|
end
|
341
|
-
|
341
|
+
|
342
342
|
it "delivers messages to matching subscriptions" do
|
343
343
|
publish @message
|
344
344
|
expect_message :alice, [@message]
|
@@ -346,38 +346,38 @@ describe "Pub/sub engines" do
|
|
346
346
|
expect_no_message :carol
|
347
347
|
end
|
348
348
|
end
|
349
|
-
|
349
|
+
|
350
350
|
describe "with a double wildcard" do
|
351
351
|
before do
|
352
352
|
subscribe :alice, "/messages/**"
|
353
353
|
subscribe :bob, "/messages/bar"
|
354
354
|
subscribe :carol, "/**"
|
355
355
|
end
|
356
|
-
|
356
|
+
|
357
357
|
it "delivers messages to matching subscriptions" do
|
358
358
|
publish @message
|
359
359
|
expect_message :alice, [@message]
|
360
360
|
expect_no_message :bob
|
361
361
|
expect_message :carol, [@message]
|
362
362
|
end
|
363
|
-
|
363
|
+
|
364
364
|
it "delivers a unique copy of the message to each client" do
|
365
365
|
publish @message
|
366
366
|
check_different_messages :alice, :carol
|
367
367
|
end
|
368
368
|
end
|
369
|
-
|
369
|
+
|
370
370
|
describe "with multiple matching subscriptions for the same client" do
|
371
371
|
before do
|
372
372
|
subscribe :alice, "/messages/foo"
|
373
373
|
subscribe :alice, "/messages/*"
|
374
374
|
end
|
375
|
-
|
375
|
+
|
376
376
|
it "delivers each message once to each client" do
|
377
377
|
publish @message
|
378
378
|
expect_message :alice, [@message]
|
379
379
|
end
|
380
|
-
|
380
|
+
|
381
381
|
it "delivers the message as many times as it is published" do
|
382
382
|
publish [@message, @message]
|
383
383
|
expect_message :alice, [@message, @message]
|
@@ -385,36 +385,36 @@ describe "Pub/sub engines" do
|
|
385
385
|
end
|
386
386
|
end
|
387
387
|
end
|
388
|
-
|
388
|
+
|
389
389
|
shared_examples_for "distributed engine" do
|
390
390
|
include EngineSteps
|
391
|
-
|
391
|
+
|
392
392
|
def create_engine
|
393
393
|
opts = options.merge(engine_opts)
|
394
394
|
Faye::Engine::Proxy.new(opts)
|
395
395
|
end
|
396
|
-
|
396
|
+
|
397
397
|
let(:options) { {} }
|
398
398
|
let(:left) { create_engine }
|
399
399
|
let(:right) { create_engine }
|
400
|
-
|
400
|
+
|
401
401
|
alias :engine :left
|
402
|
-
|
402
|
+
|
403
403
|
before do
|
404
404
|
Faye.stub(:logger)
|
405
405
|
Faye::Engine.ensure_reactor_running!
|
406
406
|
create_client :alice
|
407
407
|
create_client :bob
|
408
|
-
|
408
|
+
|
409
409
|
connect :alice, left
|
410
410
|
end
|
411
|
-
|
411
|
+
|
412
412
|
describe :publish do
|
413
413
|
before do
|
414
414
|
subscribe :alice, "/foo"
|
415
415
|
publish "channel" => "/foo", "data" => "first"
|
416
416
|
end
|
417
|
-
|
417
|
+
|
418
418
|
it "only delivers each message once" do
|
419
419
|
expect_message :alice, ["channel" => "/foo", "data" => "first"]
|
420
420
|
publish "channel" => "/foo", "data" => "second"
|
data/spec/ruby/faye_spec.rb
CHANGED
@@ -5,24 +5,24 @@ describe Faye do
|
|
5
5
|
it "returns a 128-bit random number in base 36" do
|
6
6
|
Faye.random.should =~ /^[a-z0-9]+$/
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "always produces the same length of string" do
|
10
10
|
ids = (1..100).map { Faye.random }
|
11
11
|
ids.should be_all { |id| id.size == 31 }
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
describe :copy_obect do
|
16
16
|
let(:object) { {"foo" => "bar", "qux" => 42, "hey" => nil, "obj" => {"bar" => 67}} }
|
17
|
-
|
17
|
+
|
18
18
|
it "returns an equal object" do
|
19
19
|
Faye.copy_object(object).should == {"foo" => "bar", "qux" => 42, "hey" => nil, "obj" => {"bar" => 67}}
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "does not return the same object" do
|
23
23
|
Faye.copy_object(object).should_not be_equal(object)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "performs a deep clone" do
|
27
27
|
Faye.copy_object(object)["obj"].should_not be_equal(object["obj"])
|
28
28
|
end
|
data/spec/ruby/grammar_spec.rb
CHANGED
@@ -5,61 +5,61 @@ describe Faye::Grammar do
|
|
5
5
|
it "matches valid channel names" do
|
6
6
|
Faye::Grammar::CHANNEL_NAME.should =~ "/fo_o/$@()bar"
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "does not match channel patterns" do
|
10
10
|
Faye::Grammar::CHANNEL_NAME.should_not =~ "/foo/**"
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "does not match invalid channel names" do
|
14
14
|
Faye::Grammar::CHANNEL_NAME.should_not =~ "foo/$@()bar"
|
15
15
|
Faye::Grammar::CHANNEL_NAME.should_not =~ "/foo/$@()bar/"
|
16
16
|
Faye::Grammar::CHANNEL_NAME.should_not =~ "/fo o/$@()bar"
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
describe :CHANNEL_PATTERN do
|
21
21
|
it "does not match channel names" do
|
22
22
|
Faye::Grammar::CHANNEL_PATTERN.should_not =~ "/fo_o/$@()bar"
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it "matches valid channel patterns" do
|
26
26
|
Faye::Grammar::CHANNEL_PATTERN.should =~ "/foo/**"
|
27
27
|
Faye::Grammar::CHANNEL_PATTERN.should =~ "/foo/*"
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "does not match invalid channel patterns" do
|
31
31
|
Faye::Grammar::CHANNEL_PATTERN.should_not =~ "/foo/**/*"
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
describe :ERROR do
|
36
36
|
it "matches an error with an argument" do
|
37
37
|
Faye::Grammar::ERROR.should =~ "402:xj3sjdsjdsjad:Unknown Client ID"
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it "matches an error with many arguments" do
|
41
41
|
Faye::Grammar::ERROR.should =~ "403:xj3sjdsjdsjad,/foo/bar:Subscription denied"
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it "matches an error with no arguments" do
|
45
45
|
Faye::Grammar::ERROR.should =~ "402::Unknown Client ID"
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it "does not match an error with no code" do
|
49
49
|
Faye::Grammar::ERROR.should_not =~ ":xj3sjdsjdsjad:Unknown Client ID"
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
it "does not match an error with an invalid code" do
|
53
53
|
Faye::Grammar::ERROR.should_not =~ "40:xj3sjdsjdsjad:Unknown Client ID"
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
describe :VERSION do
|
58
58
|
it "matches a version number" do
|
59
59
|
Faye::Grammar::VERSION.should =~ "9"
|
60
60
|
Faye::Grammar::VERSION.should =~ "9.0.a-delta1"
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
it "does not match invalid version numbers" do
|
64
64
|
Faye::Grammar::VERSION.should_not =~ "9.0.a-delta1."
|
65
65
|
Faye::Grammar::VERSION.should_not =~ ""
|