2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

add debug mode to autospec

This commit is contained in:
Régis Hanol 2013-11-05 11:01:17 +01:00
parent a2efe27a58
commit eb9c1f28ed
3 changed files with 49 additions and 15 deletions

View file

@ -10,9 +10,6 @@ Discourse::Application.configure do
# Configure static asset server for tests with Cache-Control for performance # Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true config.serve_static_assets = true
# Log error messages when you accidentally call methods on nil
config.whiny_nils = true
# Show full error reports and disable caching # Show full error reports and disable caching
config.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
@ -39,4 +36,9 @@ Discourse::Application.configure do
# lower iteration count for test # lower iteration count for test
config.pbkdf2_iterations = 10 config.pbkdf2_iterations = 10
config.ember.variant = :development config.ember.variant = :development
# silence deprecation warnings in test
config.whiny_nils = true unless rails4?
config.eager_load = false if rails4?
ActiveSupport::Deprecation.silenced = true
end end

View file

@ -9,18 +9,19 @@ module Autospec; end
class Autospec::Manager class Autospec::Manager
def self.run(opts={}) def self.run(opts={})
self.new.run(opts) self.new(opts).run
end end
def initialize def initialize(opts = {})
@opts = opts
@debug = opts[:debug]
@queue = [] @queue = []
@mutex = Mutex.new @mutex = Mutex.new
@signal = ConditionVariable.new @signal = ConditionVariable.new
@runners = [ruby_runner, javascript_runner]
end end
def run(opts = {}) def run
@runners = [ruby_runner, javascript_runner]
Signal.trap("HUP") { stop_runners; exit } Signal.trap("HUP") { stop_runners; exit }
Signal.trap("INT") { stop_runners; exit } Signal.trap("INT") { stop_runners; exit }
@ -59,6 +60,7 @@ class Autospec::Manager
end end
def ensure_all_specs_will_run def ensure_all_specs_will_run
puts "@@@@@@@@@@@@ ensure_all_specs_will_run" if @debug
@runners.each do |runner| @runners.each do |runner|
@queue << ['spec', 'spec', runner] unless @queue.any? { |f, s, r| s == "spec" && r == runner } @queue << ['spec', 'spec', runner] unless @queue.any? { |f, s, r| s == "spec" && r == runner }
end end
@ -66,11 +68,13 @@ class Autospec::Manager
[:start, :stop, :abort].each do |verb| [:start, :stop, :abort].each do |verb|
define_method("#{verb}_runners") do define_method("#{verb}_runners") do
puts "@@@@@@@@@@@@ #{verb}_runners" if @debug
@runners.each(&verb) @runners.each(&verb)
end end
end end
def start_service_queue def start_service_queue
puts "@@@@@@@@@@@@ start_service_queue" if @debug
Thread.new do Thread.new do
while true while true
thread_loop thread_loop
@ -80,11 +84,17 @@ class Autospec::Manager
# the main loop, will run the specs in the queue till one fails or the queue is empty # the main loop, will run the specs in the queue till one fails or the queue is empty
def thread_loop def thread_loop
puts "@@@@@@@@@@@@ thread_loop" if @debug
@mutex.synchronize do @mutex.synchronize do
current = @queue.first current = @queue.first
last_failed = false last_failed = false
last_failed = process_spec(current) if current last_failed = process_spec(current) if current
# stop & wait for the queue to have at least one item or when there's been a failure # stop & wait for the queue to have at least one item or when there's been a failure
if @debug
puts "@@@@@@@@@@@@ waiting because..."
puts "@@@@@@@@@@@@ ...current spec has failed" if last_failed
puts "@@@@@@@@@@@@ ...queue is empty" if @queue.length == 0
end
@signal.wait(@mutex) if @queue.length == 0 || last_failed @signal.wait(@mutex) if @queue.length == 0 || last_failed
end end
rescue => e rescue => e
@ -93,6 +103,7 @@ class Autospec::Manager
# will actually run the spec and check whether the spec has failed or not # will actually run the spec and check whether the spec has failed or not
def process_spec(current) def process_spec(current)
puts "@@@@@@@@@@@@ process_spec --> #{current}" if @debug
has_failed = false has_failed = false
# retrieve the instance of the runner # retrieve the instance of the runner
runner = current[2] runner = current[2]
@ -100,9 +111,11 @@ class Autospec::Manager
result = runner.run(current[1]).to_i result = runner.run(current[1]).to_i
if result == 0 if result == 0
puts "@@@@@@@@@@@@ success" if @debug
# remove the spec from the queue # remove the spec from the queue
@queue.shift @queue.shift
else else
puts "@@@@@@@@@@@@ failure" if @debug
has_failed = true has_failed = true
if result > 0 if result > 0
focus_on_failed_tests(current) focus_on_failed_tests(current)
@ -114,6 +127,7 @@ class Autospec::Manager
end end
def focus_on_failed_tests(current) def focus_on_failed_tests(current)
puts "@@@@@@@@@@@@ focus_on_failed_tests --> #{current}" if @debug
runner = current[2] runner = current[2]
# we only want 1 focus in the queue # we only want 1 focus in the queue
@queue.shift if current[0] == "focus" @queue.shift if current[0] == "focus"
@ -123,15 +137,17 @@ class Autospec::Manager
@queue.unshift ["focus", failed_specs.join(" "), runner] if failed_specs.length > 0 @queue.unshift ["focus", failed_specs.join(" "), runner] if failed_specs.length > 0
end end
def listen_for_changes(opts = {}) def listen_for_changes
puts "@@@@@@@@@@@@ listen_for_changes" if @debug
options = { options = {
ignore: /^public|^lib\/autospec/, ignore: /^public|^lib\/autospec/,
relative_paths: true, relative_paths: true,
} }
if opts[:force_polling] if @opts[:force_polling]
options[:force_polling] = true options[:force_polling] = true
options[:latency] = opts[:latency] || 3 options[:latency] = @opts[:latency] || 3
end end
Thread.start do Thread.start do
@ -143,6 +159,9 @@ class Autospec::Manager
def process_change(files) def process_change(files)
return if files.length == 0 return if files.length == 0
puts "@@@@@@@@@@@@ process_change --> #{files}" if @debug
specs = [] specs = []
hit = false hit = false
@ -151,6 +170,7 @@ class Autospec::Manager
# reloaders # reloaders
runner.reloaders.each do |k| runner.reloaders.each do |k|
if k.match(file) if k.match(file)
puts "@@@@@@@@@@@@ #{file} matched a reloader for #{runner}" if @debug
runner.reload runner.reload
return return
end end
@ -158,6 +178,7 @@ class Autospec::Manager
# watchers # watchers
runner.watchers.each do |k,v| runner.watchers.each do |k,v|
if m = k.match(file) if m = k.match(file)
puts "@@@@@@@@@@@@ #{file} matched a watcher for #{runner}" if @debug
hit = true hit = true
spec = v ? (v.arity == 1 ? v.call(m) : v.call) : file spec = v ? (v.arity == 1 ? v.call(m) : v.call) : file
specs << [file, spec, runner] if File.exists?(spec) || Dir.exists?(spec) specs << [file, spec, runner] if File.exists?(spec) || Dir.exists?(spec)
@ -179,6 +200,8 @@ class Autospec::Manager
end end
def queue_specs(specs) def queue_specs(specs)
puts "@@@@@@@@@@@@ queue_specs --> #{specs}" if @debug
if specs.length == 0 if specs.length == 0
locked = @mutex.try_lock locked = @mutex.try_lock
if locked if locked
@ -190,7 +213,10 @@ class Autospec::Manager
abort_runners abort_runners
end end
puts "@@@@@@@@@@@@ waiting for the mutex" if @debug
@mutex.synchronize do @mutex.synchronize do
puts "@@@@@@@@@@@@ queueing specs" if @debug
puts "@@@@@@@@@@@@ #{@queue}" if @debug
specs.each do |file, spec, runner| specs.each do |file, spec, runner|
# make sure there's no other instance of this spec in the queue # make sure there's no other instance of this spec in the queue
@queue.delete_if { |f, s, r| s.strip == spec.strip && r == runner } @queue.delete_if { |f, s, r| s.strip == spec.strip && r == runner }
@ -205,12 +231,16 @@ class Autospec::Manager
@queue.unshift([file, spec, runner]) @queue.unshift([file, spec, runner])
end end
end end
puts "@@@@@@@@@@@@ specs queued" if @debug
puts "@@@@@@@@@@@@ #{@queue}" if @debug
@signal.signal @signal.signal
end end
end end
def process_queue def process_queue
puts "@@@@@@@@@@@@ process_queue" if @debug
if @queue.length == 0 if @queue.length == 0
puts "@@@@@@@@@@@@ queue is empty..." if @debug
ensure_all_specs_will_run ensure_all_specs_will_run
@signal.signal @signal.signal
else else
@ -220,7 +250,7 @@ class Autospec::Manager
puts puts
puts puts
if specs.length == 0 if specs.length == 0
puts "No specs have failed yet!" puts "No specs have failed yet! "
puts puts
else else
puts "The following specs have failed:" puts "The following specs have failed:"

View file

@ -6,8 +6,9 @@ desc "Run all specs automatically as needed"
task "autospec" => :environment do task "autospec" => :environment do
require 'autospec/manager' require 'autospec/manager'
force_polling = ARGV.any?{ |a| a == "p" || a == "polling" } debug = ARGV.any? { |a| a == "d" || a == "debug" }
latency = ((ARGV.find{ |a| a =~ /l=|latency=/ } || "").split("=")[1] || 3).to_i force_polling = ARGV.any? { |a| a == "p" || a == "polling" }
latency = ((ARGV.find { |a| a =~ /l=|latency=/ } || "").split("=")[1] || 3).to_i
if force_polling if force_polling
puts "Polling has been forced (slower) - checking every #{latency} #{"second".pluralize(latency)}" puts "Polling has been forced (slower) - checking every #{latency} #{"second".pluralize(latency)}"
@ -15,6 +16,7 @@ task "autospec" => :environment do
puts "If file watching is not working, you can force polling with: bundle exec rake autospec p l=3" puts "If file watching is not working, you can force polling with: bundle exec rake autospec p l=3"
end end
Autospec::Manager.run(force_polling: force_polling, latency: latency) puts "@@@@@@@@@@@@ Running in debug mode" if debug
Autospec::Manager.run(force_polling: force_polling, latency: latency, debug: debug)
end end