Skip to content

Commit

Permalink
(GH-199) Update stack trace tests for Puppet 6.11.0
Browse files Browse the repository at this point in the history
The Puppet call stack has changed behaviour for both exceptions and succesful
calls.  This commit updates the tests for expect different stack traces for
exceptions, and updates the generate stack trace method to ignore call sites
with invalid line numbers (e.g. 0)
  • Loading branch information
glennsarti committed Nov 22, 2019
1 parent fb3dea7 commit 074ad0b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/puppet-debugserver/debug_session/hook_handlers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ def process_breakpoint_hook(reason, args)
end

break_description = break_display_text if break_description.empty?
stack_trace = Puppet::Pops::PuppetStack.stacktrace
# Due to a modification to the way stack traces are treated in Puppet 6.11.0, the stack
# now includes entries for files in Line 0, which doesn't exist. These indicate that a file
# has started to be processed/parsed/compiled. So we just ignore them
# See https://tickets.puppetlabs.com/browse/PUP-10150 for more infomation
stack_trace = Puppet::Pops::PuppetStack.stacktrace.reject { |item| item[1].zero? }
# Due to https://github.com/puppetlabs/puppet/commit/0f96dd918b6184261bc2219e5e68e246ffbeac10
# Prior to Puppet 4.8.0, stacktrace is in reverse order
stack_trace.reverse! if Gem::Version.new(Puppet.version) < Gem::Version.new('4.8.0')
Expand Down
18 changes: 14 additions & 4 deletions spec/debugserver/integration/puppet-debugserver/end_to_end_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
@debug_stderr.close
}

def modified_puppet_stack_trace
# Due to a modification to the way stack traces are treated in Puppet 6.11.0, the stack size is different
# See https://tickets.puppetlabs.com/browse/PUP-10150 for more infomation
@modified_puppet_stack_trace ||= Gem::Version.create(Puppet.version) >= Gem::Version.create('6.11.0')
end

context 'Processing an empty manifest with no breakpoints' do
let(:manifest_file) { File.join($fixtures_dir, 'environments', 'testfixtures', 'manifests', 'empty.pp') }
let(:noop) { true }
Expand Down Expand Up @@ -92,10 +98,14 @@
result = @client.data_from_request_seq_id(@client.current_seq_id)
# As we're only in the root, only two frames should be available. The error and where it was called from
expect(result['success']).to be true
expect(result['body']['stackFrames'].count).to eq(2)
expect(result['body']['stackFrames'][0]).to include('line' => 3)
expect(result['body']['stackFrames'][1]).to include('line' => 3)

if modified_puppet_stack_trace
expect(result['body']['stackFrames'].count).to eq(1)
expect(result['body']['stackFrames'][0]).to include('line' => 3)
else
expect(result['body']['stackFrames'].count).to eq(2)
expect(result['body']['stackFrames'][0]).to include('line' => 3)
expect(result['body']['stackFrames'][1]).to include('line' => 3)
end
# continue_request
@client.send_data(@client.continue_request(@client.next_seq_id, thread_id))
expect(@client).to receive_message_with_request_id_within_timeout([@client.current_seq_id, 5])
Expand Down

0 comments on commit 074ad0b

Please sign in to comment.