plezi 0.10.12 → 0.10.13

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.
@@ -7,11 +7,15 @@
7
7
  Root ||= Pathname.new(File.dirname(__FILE__)).expand_path
8
8
  ## make sure all file access and file loading is relative to the application's root folder
9
9
  # Dir.chdir Root.to_s
10
+ ## load code from a subfolder called 'code'
11
+ # Dir[File.join "{code}", "**" , "*.rb"].each {|file| load File.expand_path(file)}
10
12
 
11
- ## Commet the following in order to use use your original app's Gemfile.
12
13
  ## If this app is independant, use bundler to load gems (including the plezi gem).
13
- require 'bundler'
14
- Bundler.require(:default, ENV['ENV'].to_s.to_sym)
14
+ ## Else, use the original app's Gemfile and start Plezi's Rack mode.
15
+ require 'bundler'
16
+ Bundler.require(:default, ENV['ENV'].to_s.to_sym)
17
+ ## OR:
18
+ # Plesi.start_rack # remember
15
19
 
16
20
  ## Uncomment to create a log file
17
21
  # GReactor.create_logger File.expand_path(Root.join('server.log').to_s)
@@ -58,8 +62,7 @@ end
58
62
  listen host: :default,
59
63
  # root: Root.join('public').to_s,
60
64
  # assets: Root.join('assets').to_s,
61
- # assets_public: '/assets',
62
- # templates: Root.join('app','views').to_s,
65
+ # templates: Root.join('templates').to_s,
63
66
  ssl: false
64
67
 
65
68
  ## Optional stuff:
@@ -175,13 +175,13 @@ input[type=submit]:active
175
175
  </style>
176
176
  <script type="text/javascript">
177
177
  // Your websocket URI should be an absolute path. The following sets the base URI.
178
- var ws_uri = (window.location.protocol.match(/https/) ? 'wss' : 'ws') + '://' + window.location.hostname + (window.location.port == '' ? '' : (':' + window.location.port) ) + window.location.pathname;
179
- // remember to add the specific controller's path to your websocket URI.
180
- ws_uri += "/";
178
+ // remember to update to the specific controller's path to your websocket URI.
179
+ var ws_controller_path = '/' // window.location.pathname; // change to '/controller/path'
180
+ var ws_uri = (window.location.protocol.match(/https/) ? 'wss' : 'ws') + '://' + window.location.hostname + (window.location.port == '' ? '' : (':' + window.location.port) ) + ws_controller_path
181
181
  // websocket variable.
182
182
  var websocket = NaN
183
183
  // count failed attempts
184
- var websocket_fail = 0
184
+ var websocket_fail_count = 0
185
185
 
186
186
  function init_websocket()
187
187
  {
@@ -312,28 +312,32 @@ module PleziTestTasks
312
312
  PL.on_shutdown {puts " * Websocket unicast message test: #{RESULTS[unicast_test]}"}
313
313
  end
314
314
  def test_websocket_sizes
315
- should_disconnect = false
316
- ws = GRHttp::WSClient.connect_to("ws://localhost:3000/ws/size") do |ws|
317
- if should_disconnect
318
- puts " * Websocket size disconnection test: #{RESULTS[false]}"
319
- else
320
- puts " * Websocket message size test: got #{ws.data.bytesize} bytes"
321
- end
322
-
323
- end
324
- ws.on_close do
325
- puts " * Websocket size disconnection test: #{RESULTS[should_disconnect]}"
326
- end
327
- str = 'a'
328
- time_now = Time.now
329
- 8.times {|i| str = str * 2**i;puts " * Websocket message size test: sending #{str.bytesize} bytes"; ws << str; }
330
- str.clear
331
- to_sleep = (Time.now - time_now)*2 + 1
332
- puts "will now sleep for #{to_sleep} seconds, waiting allowing the server to respond"
333
- sleep to_sleep rescue true
334
- should_disconnect = true
335
- Plezi::Settings.ws_message_size_limit = 1024
336
- ws << ('0123'*258)
315
+ # should_disconnect = false
316
+ # ws = GRHttp::WSClient.connect_to("ws://localhost:3000/ws/size") do |ws|
317
+ # if should_disconnect
318
+ # puts " * Websocket size disconnection test: #{RESULTS[false]}"
319
+ # else
320
+ # puts " * Websocket message size test: got #{ws.data.bytesize} bytes"
321
+ # end
322
+
323
+ # end
324
+ # ws.on_close do
325
+ # puts " * Websocket size disconnection test: #{RESULTS[should_disconnect]}"
326
+ # end
327
+ # str = 'a'
328
+ # time_now = Time.now
329
+ # 8.times {|i| str = str * 2**i;puts " * Websocket message size test: sending #{str.bytesize} bytes"; ws << str; }
330
+ # str.clear
331
+ # to_sleep = (Time.now - time_now)*2 + 1
332
+ # puts "will now sleep for #{to_sleep} seconds, waiting allowing the server to respond"
333
+ # sleep to_sleep rescue true
334
+ # should_disconnect = true
335
+ # Plezi::Settings.ws_message_size_limit = 1024
336
+ # ws << ('0123'*258)
337
+ end
338
+ def test_broadcast_stress
339
+ PlaceboStressTestCtrl.create_listeners
340
+ PlaceboStressTestCtrl.run_test
337
341
  end
338
342
  def test_404
339
343
  puts " * 404 not found and router continuity tests: #{RESULTS[ Net::HTTP.get_response(URI.parse "http://localhost:3000/get404" ).code == '404' ]}"
@@ -343,17 +347,17 @@ module PleziTestTasks
343
347
  puts e
344
348
  end
345
349
  def test_500
346
- # workers = GReactor.instance_exec {@threads.select {|t| t.alive?} .count}
347
- # print " * 500 internal error test: #{RESULTS[ Net::HTTP.get_response(URI.parse "http://localhost:3000/fail" ).code == '500' ]}"
348
- # # cause 10 more exceptions to be raised... testing thread survival.
349
- # 10.times { putc "."; Net::HTTP.get_response(URI.parse "http://localhost:3000/fail" ).code }
350
- # putc "\n"
351
- # workers_after_test = GReactor.instance_exec {@threads.select {|t| t.alive?} .count}
352
- # puts " * Worker survival test: #{RESULTS[workers_after_test == workers]} (#{workers_after_test} out of #{workers})"
353
-
354
- # rescue => e
355
- # puts " **** 500 internal error test FAILED TO RUN!!!"
356
- # puts e
350
+ workers = GReactor.instance_exec {@threads.select {|t| t.alive?} .count}
351
+ print " * 500 internal error test: #{RESULTS[ Net::HTTP.get_response(URI.parse "http://localhost:3000/fail" ).code == '500' ]}"
352
+ # cause 10 more exceptions to be raised... testing thread survival.
353
+ 10.times { putc "."; Net::HTTP.get_response(URI.parse "http://localhost:3000/fail" ).code }
354
+ putc "\n"
355
+ workers_after_test = GReactor.instance_exec {@threads.select {|t| t.alive?} .count}
356
+ puts " * Worker survival test: #{RESULTS[workers_after_test == workers]} (#{workers_after_test} out of #{workers})"
357
+
358
+ rescue => e
359
+ puts " **** 500 internal error test FAILED TO RUN!!!"
360
+ puts e
357
361
  end
358
362
  end
359
363
 
@@ -388,6 +392,40 @@ class PlaceboCtrl
388
392
  end
389
393
  end
390
394
 
395
+
396
+ class PlaceboStressTestCtrl
397
+ def review start_time, fin = false, uni = false
398
+ if fin
399
+ time_now = Time.now
400
+ average = (((time_now - start_time)*1.0/(LISTENERS*REPEATS))*1000.0).round(4)
401
+ total = (time_now - start_time).round(3)
402
+ puts " * Placebo stress test - Total of #{LISTENERS*REPEATS} events) finished in #{total} seconds"
403
+ puts " * Placebo stress test - average: (#{average} seconds per event."
404
+ PlaceboStressTestCtrl.run_unicast_test unless uni
405
+ end
406
+ end
407
+ def self.run_test
408
+ puts "\n * Placebo Broadcast stress test starting - (#{LISTENERS} listening objects with #{REPEATS} messages."
409
+ start_time = Time.now
410
+ (REPEATS - 1).times {|i| PlaceboStressTestCtrl.broadcast :review, start_time}
411
+ PlaceboStressTestCtrl.unicast @uuid, :review, start_time, true
412
+ puts " * Placebo stress test - sending messages required: (#{Time.now - start_time} seconds."
413
+ end
414
+ def self.run_unicast_test
415
+ puts "\n * Placebo Unicast stress test starting - (#{LISTENERS} listening objects with #{REPEATS} messages."
416
+ start_time = Time.now
417
+ (REPEATS - 1).times {|i| PlaceboStressTestCtrl.unicast @uuid, :review, start_time, false, true}
418
+ PlaceboStressTestCtrl.unicast @uuid, :review, start_time, true, true
419
+ puts " * Placebo stress test - sending messages required: (#{Time.now - start_time} seconds."
420
+ end
421
+ def self.create_listeners
422
+ @uuid = nil
423
+ LISTENERS.times {@uuid = Plezi::Placebo.new(PlaceboStressTestCtrl).uuid}
424
+ end
425
+ REPEATS = 1000
426
+ LISTENERS = 600
427
+ end
428
+
391
429
  PL.create_logger nil
392
430
  # PL::Settings.max_threads = 4
393
431
 
@@ -401,6 +439,9 @@ shared_route 'ws/no', Nothing
401
439
  shared_route 'ws/placebo', PlaceboTestCtrl
402
440
  shared_route 'ws/size', WSsizeTestCtrl
403
441
 
442
+
443
+ # puts Nothing.ancestors.join "\n"
444
+
404
445
  shared_route '/some/:multi{path|another_path}/(:option){route|test}/(:id)/(:optional)', TestCtrl
405
446
  shared_route '/', TestCtrl
406
447
 
@@ -418,23 +459,26 @@ end
418
459
 
419
460
 
420
461
 
421
- r = Plezi::Placebo.new PlaceboCtrl
422
- puts " * Create Placebo test: #{PleziTestTasks::RESULTS[r && true]}"
423
462
 
424
- Plezi.start_async
425
463
  puts " --- Plezi will ran async, performing some tests that than hang"
426
464
 
427
465
  puts " --- Starting tests"
428
466
  puts " --- Failed tests should read: #{PleziTestTasks::RESULTS[false]}"
467
+ Plezi.start_async
429
468
  PleziTestTasks.run_tests
430
- puts "\n --- Press ^C to complete tests."
431
469
 
470
+ r = Plezi::Placebo.new PlaceboCtrl
471
+ puts " * Create Placebo test: #{PleziTestTasks::RESULTS[r && true]}"
472
+
473
+ # ENV['PL_REDIS_URL'] ||= ENV['REDIS_URL'] || ENV['REDISCLOUD_URL'] || ENV['REDISTOGO_URL'] || "redis://test:1234@pub-redis-11008.us-east-1-4.5.ec2.garantiadata.com:11008"
474
+ # # GReactor::Settings.set_forking 4
475
+ # GR.run_async { PleziTestTasks.run_tests }
432
476
  # start_services
433
477
 
434
478
  shoutdown_test = false
435
- # GReactor::Settings.set_forking 4
436
479
  Plezi.on_shutdown { shoutdown_test = true }
437
480
 
481
+ puts "\n --- Press ^C to complete tests."
438
482
  Plezi.start
439
483
  # Plezi::EventMachine.clear_timers
440
484
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plezi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.12
4
+ version: 0.10.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-24 00:00:00.000000000 Z
11
+ date: 2015-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grhttp
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.15
19
+ version: 0.0.16
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.15
26
+ version: 0.0.16
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,8 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
- description: Plezi is the native Ruby Framework for real time web-apps. An easy way
56
- to write Websockets, RESTful routing and HTTP streaming apps.
55
+ description: Plezi - the easy way to add Websockets, RESTful routing and HTTP streaming
56
+ serviced to Ruby Web-Apps.
57
57
  email:
58
58
  - boaz@2be.co.il
59
59
  executables:
@@ -78,9 +78,11 @@ files:
78
78
  - lib/plezi/handlers/controller_core.rb
79
79
  - lib/plezi/handlers/controller_magic.rb
80
80
  - lib/plezi/handlers/http_router.rb
81
+ - lib/plezi/handlers/placebo old.rb
81
82
  - lib/plezi/handlers/placebo.rb
82
83
  - lib/plezi/handlers/route.rb
83
84
  - lib/plezi/handlers/stubs.rb
85
+ - lib/plezi/handlers/ws_object.rb
84
86
  - lib/plezi/helpers/http_sender.rb
85
87
  - lib/plezi/helpers/magic_helpers.rb
86
88
  - lib/plezi/helpers/mime_types.rb
@@ -145,8 +147,8 @@ rubyforge_project:
145
147
  rubygems_version: 2.4.7
146
148
  signing_key:
147
149
  specification_version: 4
148
- summary: Plezi is the native Ruby Framework for real time web-apps. An easy way to
149
- write Websockets, RESTful routing and HTTP streaming apps.
150
+ summary: Plezi - the easy way to add Websockets, RESTful routing and HTTP streaming
151
+ serviced to Ruby Web-Apps.
150
152
  test_files:
151
153
  - test/console
152
154
  - test/plezi_tests.rb