summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@opscode.com>2021-06-01 14:23:04 -0700
committerGitHub <noreply@github.com>2021-06-01 14:23:04 -0700
commit269dc37b230e7dad68a19f7d6671f13b3e178e34 (patch)
tree493013657fa790787ce113993e173dbb07d81b08
parent8ef9cd3fe555468306bc6b53f4b215f886236d04 (diff)
parent954c7a7feabf0bead4f4c187ab364d51fb737e2b (diff)
downloadchef-269dc37b230e7dad68a19f7d6671f13b3e178e34.tar.gz
Merge pull request #11648 from chef/lcg/add-slow-report
Fix Chef::Handler specs and slow report behavior
-rw-r--r--lib/chef/handler/slow_report.rb10
-rw-r--r--spec/unit/handler_spec.rb10
2 files changed, 15 insertions, 5 deletions
diff --git a/lib/chef/handler/slow_report.rb b/lib/chef/handler/slow_report.rb
index 3bdf77d2dc..7bb472f4d5 100644
--- a/lib/chef/handler/slow_report.rb
+++ b/lib/chef/handler/slow_report.rb
@@ -34,10 +34,10 @@ class Chef
return
end
- top = all_resources.sort_by(&:elapsed_time).last(amount).reverse
- data = top.map { |r| [ r.to_s, r.elapsed_time, r.cookbook_name, r.recipe_name, stripped_source_line(r) ] }
+ top = all_records.sort_by(&:elapsed_time).last(amount).reverse
+ data = top.map { |r| [ r.new_resource.to_s, r.elapsed_time, r.action, r.new_resource.cookbook_name, r.new_resource.recipe_name, stripped_source_line(r.new_resource) ] }
puts "\nTop #{count} slowest #{count == 1 ? "resource" : "resources"}:\n\n"
- table = TTY::Table.new(%w{resource elapsed_time cookbook recipe source}, data)
+ table = TTY::Table.new(%w{resource elapsed_time action cookbook recipe source}, data)
rendered = table.render do |renderer|
renderer.border do
mid "-"
@@ -48,6 +48,10 @@ class Chef
puts "\n"
end
+ def all_records
+ @all_records ||= action_collection&.filtered_collection(unprocessed: false) || []
+ end
+
def count
num = all_resources.count
num > amount ? amount : num
diff --git a/spec/unit/handler_spec.rb b/spec/unit/handler_spec.rb
index a9820e8a70..ee30113d1c 100644
--- a/spec/unit/handler_spec.rb
+++ b/spec/unit/handler_spec.rb
@@ -38,6 +38,8 @@ describe Chef::Handler do
@run_context = Chef::RunContext.new(@node, {}, @events)
@all_resources = [Chef::Resource::Cat.new("lolz"), Chef::Resource::ZenMaster.new("tzu")]
@all_resources.first.updated_by_last_action true
+ @handler.instance_variable_set(:@all_resources, @all_resources)
+ @handler.instance_variable_set(:@updated_resources, [@all_resources.first])
@run_context.resource_collection.all_resources.replace(@all_resources)
@run_status.run_context = @run_context
@start_time = Time.now
@@ -119,6 +121,8 @@ describe Chef::Handler do
@run_context = Chef::RunContext.new(@node, {}, @events)
@all_resources = [Chef::Resource::Cat.new("foo"), Chef::Resource::ZenMaster.new("moo")]
@all_resources.first.updated_by_last_action true
+ @handler.instance_variable_set(:@all_resources, @all_resources)
+ @handler.instance_variable_set(:@updated_resources, [@all_resources.first])
@run_context.resource_collection.all_resources.replace(@all_resources)
@run_status.run_context = @run_context
@start_time = Time.now
@@ -169,17 +173,19 @@ describe Chef::Handler do
# and this would test the start handler
describe "when running a start handler" do
before do
+ @handler.instance_variable_set(:@all_resources, [])
+ @handler.instance_variable_set(:@updated_resources, [])
@start_time = Time.now
allow(Time).to receive(:now).and_return(@start_time)
@run_status.start_clock
end
it "should not have all resources" do
- expect(@handler.all_resources).to be_falsey
+ expect(@handler.all_resources).to be_empty
end
it "should not have updated resources" do
- expect(@handler.updated_resources).to be_falsey
+ expect(@handler.updated_resources).to be_empty
end
it "has a shortcut for the start time" do