Skip to content

Commit

Permalink
load unique tasks - fix names and line numbers of task sources
Browse files Browse the repository at this point in the history
  • Loading branch information
whummer committed Jul 20, 2014
1 parent eb502bc commit 086b798
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.5
1.1.6
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

"testing": {
"timeservice_url" : "http://www.infosys.tuwien.ac.at/staff/hummer/tmp/time.php",
"test_hosts" : ["localhost"]
"test_hosts" : ["localhost"],
"max_threads" : 8
},
"db": {
"host": "localhost",
Expand Down
2 changes: 1 addition & 1 deletion lib/toaster/chef/chef_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def self.register_aop_hook()
end
end
task = get_task_from_sourcecode_line(resource, action, source_line_spec)
puts "get task #{resource} #{action} #{source_line_spec}: #{task}"
#puts "get task #{resource} #{action} #{source_line_spec}: #{task}"
end

# check if we execute within an "immediate notification"
Expand Down
6 changes: 3 additions & 3 deletions lib/toaster/chef/chef_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -813,17 +813,17 @@ def self.parse_resources(cookbook, recipe_name, version="latest",

File.open(recipe_file) do |io|
io.each_with_index { |line,idx|
#if line.match(/^\s*((#{resource_names.join(")|(")}))\s+.*((do)|(\{)).*$/)
idx += 1 # index is 0-based, line should be 1-based
if line.match(/^(\s*[0-9a-zA-Z_]+\s*=\s*)?\s*((#{resource_names.join(")|(")}))((\s+)|($)|(\s*\())/)
resource_lines << idx
elsif line.match(/execute.*do/) && !line.match(/^\s*#/)
puts "WARN: NO resource line: #{line}"
end
}
resource_lines.each do |line|
code = read_sourcecode_from_line(recipe_file, line + 1)
code = read_sourcecode_from_line(recipe_file, line)
if !code
puts "WARN: Could not parse code file #{recipe_file} : #{line + 1}"
puts "WARN: Could not parse code file #{recipe_file} : #{line}"
else
resource_obj = ResourceInspector.get_resource_from_source(code, attributes_source)
result[cookbook][recipe_name]["resources"][line] = code
Expand Down
2 changes: 1 addition & 1 deletion lib/toaster/model/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ def self.load_from_chef_source(resource, action, sourcecode, sourcefile, sourcel
params = {
:resource => resource.to_s,
:action => action,
:sourcecode => sourcecode,
:sourcefile => sourcefile,
:sourceline => sourceline
}
task = find_by(params)
if !task
params[:sourcecode] = sourcecode
task = Task.new(params)
end
task.resource_obj = resource
Expand Down
5 changes: 5 additions & 0 deletions lib/toaster/test/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ def success
return automation_run ? automation_run.success : nil
end

# force loading of associations from DB
def load_associations
hash() # loads all
end

def hash()
h = 0
h += skip_task_uuids.hash
Expand Down
6 changes: 5 additions & 1 deletion lib/toaster/test/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class << self

# private constructor
def initialize(max_threads_active=nil, terminate_when_queue_empty=false)
@max_threads_active = max_threads_active ? max_threads_active : 5
@max_threads_active = max_threads_active ? max_threads_active : Config.get("testing.max_threads")
@active_threads = []
@terminate_when_queue_empty = terminate_when_queue_empty
@request_queue = Queue.new
Expand Down Expand Up @@ -368,6 +368,10 @@ def start_worker_threads()
end
if test_case
begin
# do this to load all fields and avoid activeRecord error
# "could not obtain a database connection within X seconds""
test_case.load_associations()
# now execute the test case
automation_run = TestRunner.execute_test(test_case)
@result_map.put(test_case, automation_run)
rescue Object => ex
Expand Down
4 changes: 0 additions & 4 deletions lib/toaster/toaster_app_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,5 @@ def self.start_service()
puts "Starting service on port #{$service_port}"
Toaster::Config.init_db_connection()
server = ToasterAppService.new($service_port, "0.0.0.0")

# client = ToasterApp.new()
# client.runtest("2285f8539f6c48873")
# client.runtests("88056bebc7e384cac")
server.start
end
7 changes: 6 additions & 1 deletion lib/toaster/util/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def self.get(key, v=values)
end

def self.init_db_connection(config=nil)
if $db_connection_initialized
return
end
require "toaster/util/util"
if !config || !config["mysql"]
config = {
Expand All @@ -59,8 +62,10 @@ def self.init_db_connection(config=nil)
:host => "#{config["mysql"]["host"]}".empty? ? get("db.host") : config["mysql"]["host"],
:database => "#{config["mysql"]["database"]}".empty? ? get("db.database") : config["mysql"]["database"],
:username => "#{config["mysql"]["username"]}".empty? ? get("db.username") : config["mysql"]["username"],
:password => "#{config["mysql"]["password"]}".empty? ? get("db.password") : config["mysql"]["password"]
:password => "#{config["mysql"]["password"]}".empty? ? get("db.password") : config["mysql"]["password"],
:pool => 50 # connection pool size limit (default is 5 which is not sufficient)
)
$db_connection_initialized = true
else
puts "WARN: Incorrect database connection configuration"
end
Expand Down
2 changes: 1 addition & 1 deletion webapp/app/controllers/scripts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def import_chef
if recipe_info["resource_objs"][line]
action = recipe_info["resource_objs"][line].action
action = action.join(" , ") if action.kind_of?(Array)
resource = recipe_info["resource_objs"][line].resource_name
resource = recipe_info["resource_objs"][line].to_s
end
task = Task.new(
:automation => a,
Expand Down
2 changes: 1 addition & 1 deletion webapp/app/views/execs/task_executions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ global_executions = task.global_executions
<p>Automation run UUID: <%= run.uuid %></p>
<table class="tablesorter" id="tablesorter">
<thead>
<tr><th>#</th><th>ID</th>
<tr><th>#</th><th>Task ID</th>
<th>Start Time</th><th>Duration</th>
<th>Resource</th><th>Action</th><th>File</th><th>Line</th>
<th>Success</th>
Expand Down

0 comments on commit 086b798

Please sign in to comment.