test/plezi_tests.rb in plezi-0.8.7 vs test/plezi_tests.rb in plezi-0.9.0

- old
+ new

@@ -133,10 +133,19 @@ def _push data response << data.to_s end end +class WSsizeTestCtrl + # called when new Websocket data is recieved + # + # data is a string that contains binary or UTF8 (message dependent) data. + def on_message data + response << data + end +end + module PleziTestTasks module_function RESULTS = {true => "\e[32mpassed\e[0m", :waiting => "\e[32mwaiting validation\e[0m", :failed => "\e[31mFAILED!\e[0m"} @@ -249,11 +258,11 @@ else puts " * Websocket broadcast message test: #{RESULTS[broadcast_test = (msg == 'echo test')]}" go_test = false end end - ws3 = Plezi::WebsocketClient.connect_to("wss://localhost:3030") do |msg| + ws3 = Plezi::WebsocketClient.connect_to("ws://localhost:3000") do |msg| if msg.match /uuid: ([^s]*)/ ws2 << "to: #{msg.match(/^uuid: ([^s]*)/)[1]}" puts " * Websocket UUID for unicast testing: #{msg.match(/^uuid: ([^s]*)/)[1]}" elsif msg == "unicast" puts " * Websocket unicast testing: #{RESULTS[:waiting]}" @@ -288,10 +297,31 @@ PL.on_shutdown {puts " * Websocket connection message test: #{RESULTS[connection_test]}" unless connection_test} PL.on_shutdown {puts " * Websocket echo message test: #{RESULTS[echo_test]}" unless echo_test} PL.on_shutdown {puts " * Websocket broadcast message test: #{RESULTS[broadcast_test]}" unless broadcast_test} PL.on_shutdown {puts " * Websocket unicast message test: #{RESULTS[unicast_test]}"} end + def test_websocket_sizes + should_disconnect = false + ws = Plezi::WebsocketClient.connect_to("ws://localhost:3000/ws/size") do |msg| + if should_disconnect + puts " * Websocket size disconnection test: #{RESULTS[false]}" + else + puts " * Websocket message size test: got #{msg.bytesize} bytes" + end + + end + ws.on_disconnect do + puts " * Websocket size disconnection test: #{RESULTS[should_disconnect]}" + end + str = 'a' + time_now = Time.now + 6.times {|i| str = str * 2**i;puts " * Websocket message size test: sending #{str.bytesize} bytes"; ws.send str; sleep 0.2 } + sleep (Time.now - time_now + 1) + should_disconnect = true + Plezi.ws_message_size_limit = 1024 + ws << str + end def test_404 puts " * 404 not found and router continuity tests: #{RESULTS[ Net::HTTP.get_response(URI.parse "http://localhost:3000/get404" ).code == '404' ]}" rescue => e puts " **** 404 not found test FAILED TO RUN!!!" @@ -320,9 +350,11 @@ listen port: 3000 route("/ssl") {|req, res| res << "false" } listen port: 3030, ssl: true route("/ssl") {|req, res| res << "true" } + +shared_route 'ws/size', WSsizeTestCtrl shared_route '/some/:multi{path|another_path}/(:option){route|test}/(:id)/(:optional)', TestCtrl shared_route '/', TestCtrl