Skip to content

Commit c40b6af

Browse files
Merge pull request #219 from puppetlabs/bug-fix_timeout_matcher
(Bug) - Fix timeout matcher
2 parents 2c75b19 + a31f0b9 commit c40b6af

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

lib/puppet/provider/base_dsc_lite/powershell.rb

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ def set_timeout
6060
resource[:dsc_timeout] ? resource[:dsc_timeout] * 1000 : 1_200_000
6161
end
6262

63-
def compile_timeout_msg(timeout)
64-
"The DSC Resource did not respond within the timeout limit of #{timeout} milliseconds. \
65-
This can occur if the DSC Resource is stuck in an infinite loop, or if the DSC Resource is waiting for user input. \
66-
Please check the DSC Resource for any prompts that may require user input, and ensure that the DSC Resource does not contain any infinite loops. \
67-
If the DSC Resource is functioning correctly, you may need to increase the timeout limit using the 'dsc_timeout' parameter"
68-
end
69-
7063
def ps_manager
7164
debug_output = Puppet::Util::Log.level == :debug
7265
Pwsh::Manager.instance(command(:powershell), Pwsh::Manager.powershell_args, debug: debug_output)
@@ -81,14 +74,15 @@ def exists?
8174
Puppet.debug "\n" + self.class.redact_content(script_content)
8275

8376
if Pwsh::Manager.windows_powershell_supported?
84-
output = ps_manager.execute(script_content, timeout)[:stdout]
77+
output = ps_manager.execute(script_content, timeout)
78+
raise Puppet::Error, output[:errormessage] if output[:errormessage]&.match?(%r{PowerShell module timeout \(\d+ ms\) exceeded while executing})
79+
80+
output = output[:stdout]
8581
else
8682
self.class.upgrade_message
8783
output = powershell(Pwsh::Manager.powershell_args, script_content)
8884
end
8985

90-
raise Puppet::Error, compile_timeout_msg(timeout) if output.nil?
91-
9286
Puppet.debug "Dsc Resource returned: #{output}"
9387
data = JSON.parse(output)
9488
raise(data['errormessage']) unless data['errormessage'].empty?
@@ -107,14 +101,15 @@ def create
107101
Puppet.debug "\n" + self.class.redact_content(script_content)
108102

109103
if Pwsh::Manager.windows_powershell_supported?
110-
output = ps_manager.execute(script_content, timeout)[:stdout]
104+
output = ps_manager.execute(script_content, timeout)
105+
raise Puppet::Error, output[:errormessage] if output[:errormessage]&.match?(%r{PowerShell module timeout \(\d+ ms\) exceeded while executing})
106+
107+
output = output[:stdout]
111108
else
112109
self.class.upgrade_message
113110
output = powershell(Pwsh::Manager.powershell_args, script_content)
114111
end
115112

116-
raise Puppet::Error, compile_timeout_msg(timeout) if output.nil?
117-
118113
Puppet.debug "Create Dsc Resource returned: #{output}"
119114
data = JSON.parse(output)
120115

spec/acceptance/dsc_type/psdesiredstateconfiguration_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module => 'PSDesiredStateConfiguration',
6464
context 'times out when execution time is greater than dsc_timeout' do
6565
it 'applies manifest' do
6666
apply_manifest(dsc_timeout_manifest, expect_failures: true) do |result|
67-
expect(result.stderr).to match(%r{The DSC Resource did not respond within the timeout limit of 1000 milliseconds})
67+
expect(result.stderr).to match(%r{Catastrophic failure: PowerShell module timeout \(1000 ms\) exceeded while executing})
6868
end
6969
end
7070
end

0 commit comments

Comments
 (0)