From 4ee3660077893b27c8165284d748c8342b87aa57 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 9 Apr 2012 12:03:54 -0400 Subject: [PATCH] do you like evented i/o? i like evented i/o. --- lib/assets/javascripts/flowerbox.js.coffee | 25 ++++--- lib/flowerbox/result/base.rb | 10 +-- lib/flowerbox/result/failure_message.rb | 11 +-- lib/flowerbox/result/file_info.rb | 12 +++- lib/flowerbox/runner/node.rb | 11 +++ lib/flowerbox/runner/selenium.rb | 8 ++- lib/flowerbox/server.rb | 80 +++++++++++----------- 7 files changed, 87 insertions(+), 70 deletions(-) diff --git a/lib/assets/javascripts/flowerbox.js.coffee b/lib/assets/javascripts/flowerbox.js.coffee index fd574d0..105326f 100644 --- a/lib/assets/javascripts/flowerbox.js.coffee +++ b/lib/assets/javascripts/flowerbox.js.coffee @@ -16,19 +16,24 @@ Flowerbox = message = [ url, data ] Flowerbox.messageQueue.push(message) - if Flowerbox.socket - while Flowerbox.messageQueue.length > 0 - message = Flowerbox.messageQueue.shift() - Flowerbox.socket.send(JSON.stringify(message)) - - if url == 'results' - if __$instrument? - Flowerbox.socket.send(JSON.stringify(['instrument', __$instrument])) - - Flowerbox.done = true + Flowerbox.queuePuller() if Flowerbox.socket started: false done: false + queuePuller: -> + if Flowerbox.messageQueue.length > 0 + message = Flowerbox.messageQueue.shift() + + Flowerbox.socket.send JSON.stringify(message), {}, -> + if message[0] == 'results' + if __$instrument? + Flowerbox.socket.send JSON.stringify(['instrument', __$instrument]) {}, -> + Flowerbox.done = true + else + Flowerbox.done = true + + Flowerbox.queuePuller() + fail: -> diff --git a/lib/flowerbox/result/base.rb b/lib/flowerbox/result/base.rb index b2653f4..263856b 100644 --- a/lib/flowerbox/result/base.rb +++ b/lib/flowerbox/result/base.rb @@ -13,7 +13,7 @@ module Flowerbox def_delegators :data, :[] def type - self.class.name.split("::").last.downcase.to_sym + @type ||= self.class.name.split("::").last.downcase.to_sym end def initialize(data) @@ -41,13 +41,7 @@ module Flowerbox end def <=>(other) - result = self.name.length <=> other.name.length - - if result == 0 - - end - - result + self.name.length <=> other.name.length end def runners diff --git a/lib/flowerbox/result/failure_message.rb b/lib/flowerbox/result/failure_message.rb index 8f9b379..a6b9d25 100644 --- a/lib/flowerbox/result/failure_message.rb +++ b/lib/flowerbox/result/failure_message.rb @@ -35,16 +35,11 @@ module Flowerbox::Result end def filtered_stack - filtered_stack = stack.reject { |line| - Flowerbox.backtrace_filter.any? { |filter| line[filter] } - }.collect { |line| - line.gsub(%r{\.coffee:(\d+)}) do |_| - ".coffee:~#{($1.to_i * 0.67 + 1).to_i}" - end - } + filtered_stack = stack.reject { |line| Flowerbox.backtrace_filter.any? { |filter| line[filter] } } filtered_stack.shift if exception? - filtered_stack + + filter_coffeescript_lines(filtered_stack) end def first_local_stack diff --git a/lib/flowerbox/result/file_info.rb b/lib/flowerbox/result/file_info.rb index c988fee..4f0635f 100644 --- a/lib/flowerbox/result/file_info.rb +++ b/lib/flowerbox/result/file_info.rb @@ -25,7 +25,7 @@ module Flowerbox::Result::FileInfo return @line_number if @line_number @line_number = file.to_s.split(":")[1] - @line_number = "~#{(@line_number.to_i * 0.67).to_i}" if file_translated? + @line_number = "~#{coffeescript_line_to_js_line(@line_number)}" if file_translated? @line_number ||= "0" end @@ -38,5 +38,15 @@ module Flowerbox::Result::FileInfo def system_files Flowerbox.test_environment.system_files end + + def filter_coffeescript_lines(lines) + [ lines ].flatten.collect { |line| + line.gsub(%r{\.coffee:(\d+)}) { |_| ".coffee:~#{coffeescript_line_to_js_line($1)}" } + } + end + + def coffeescript_line_to_js_line(number) + (number.to_i * 0.67 + 1).to_i + end end diff --git a/lib/flowerbox/runner/node.rb b/lib/flowerbox/runner/node.rb index b6194aa..596486f 100644 --- a/lib/flowerbox/runner/node.rb +++ b/lib/flowerbox/runner/node.rb @@ -38,6 +38,15 @@ module Flowerbox File.open(file, 'wb') { |fh| fh.print template } system %{node #{file}} + + if $?.exitstatus == 0 + count = 20 + while !finished? && count > 0 + sleep 0.1 + + count -= 1 + end + end ensure File.unlink(file) if file end @@ -66,6 +75,8 @@ jsdom.env( var gotFlowerbox = false; + console._log = console.log; + var socket = new ws('ws://localhost:#{server.port + 1}/'); socket.onopen = function() { var files = #{sprockets.files.to_json}; diff --git a/lib/flowerbox/runner/selenium.rb b/lib/flowerbox/runner/selenium.rb index d106e4b..06e6d75 100644 --- a/lib/flowerbox/runner/selenium.rb +++ b/lib/flowerbox/runner/selenium.rb @@ -40,16 +40,20 @@ module Flowerbox puts msg end + def page_title + "Flowerbox - #{Flowerbox.test_environment.name} Runner" + end + def template env = start_test_environment <<-HTML - Flowerbox - #{Flowerbox.test_environment.name} Runner + #{page_title} -

Flowerbox - #{Flowerbox.test_environment.name} Runner

+

#{page_title}