Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/buildkite/test_collector/library_hooks/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,43 @@

Buildkite::TestCollector.uploader = Buildkite::TestCollector::Uploader


RSpec.configure do |config|
config.before(:suite) do
config.add_formatter Buildkite::TestCollector::RSpecPlugin::Reporter
end

config.around(:each) do |example|
FAILED_TESTS = [
"./spec/helpers/emoji_helper_spec.rb[1:2:1]",
"./spec/features/usage/test_executions_spec.rb[1:4:1]",
"./spec/api/api/hello_world_spec.rb[1:1:1]"
]
$stdout.puts "🐛 start of around method" if FAILED_TESTS.include?(example.id)

$stdout.puts "🐛 create new tracer object" if FAILED_TESTS.include?(example.id)
tracer = Buildkite::TestCollector::Tracer.new


# The _buildkite prefix here is added as a safeguard against name collisions
# as we are in the main thread
Thread.current[:_buildkite_tracer] = tracer
$stdout.puts Thread.current if FAILED_TESTS.include?(example.id)
$stdout.puts "🐛 run the test" if FAILED_TESTS.include?(example.id)
example.run
$stdout.puts "🐛 end of run the test" if FAILED_TESTS.include?(example.id)
Thread.current[:_buildkite_tracer] = nil

$stdout.puts "🐛 finalize the tracer" if FAILED_TESTS.include?(example.id)
tracer.finalize

$stdout.puts "🐛 create new traces object" if FAILED_TESTS.include?(example.id)
trace = Buildkite::TestCollector::RSpecPlugin::Trace.new(example, history: tracer.history)
$stdout.puts "🐛 put test in the traces" if FAILED_TESTS.include?(example.id)
Buildkite::TestCollector.uploader.traces[example.id] = trace

$stdout.puts "🐛 end of around method" if FAILED_TESTS.include?(example.id)
$stdout.puts Thread.current if FAILED_TESTS.include?(example.id)
end

config.after(:suite) do
Expand Down
22 changes: 21 additions & 1 deletion lib/buildkite/test_collector/rspec_plugin/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,33 @@ def handle_example(notification)
end
end

def handle_failed_example(notification)
$stdout.puts "🤡 start of handle_failed_example"
$stdout.puts Thread.current
example = notification.example
trace = Buildkite::TestCollector.uploader.traces[example.id]
$stdout.puts "🤡 example id: #{example.id}"

if trace
$stdout.puts "🤡 found trace"
trace.example = example
$stdout.puts "🤡 execution result: #{example.execution_result}"
if example.execution_result.status == :failed
trace.failure_reason, trace.failure_expanded = failure_info(notification)
end
$stdout.puts "🤡 adding example to queue"
Buildkite::TestCollector.session.add_example_to_send_queue(example.id)
end
$stdout.puts "🤡 end of handle_failed_example"
end

def dump_summary(_notification)
Buildkite::TestCollector.session.send_remaining_data
Buildkite::TestCollector.session.close
end

alias_method :example_passed, :handle_example
alias_method :example_failed, :handle_example
alias_method :example_failed, :handle_failed_example
alias_method :example_pending, :handle_example

private
Expand Down
1 change: 1 addition & 0 deletions lib/buildkite/test_collector/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def add_example_to_send_queue(id)
end

def send_remaining_data
$stdout.puts "🤡 sending #{@send_queue_ids.count} items in the send queue"
return if @send_queue_ids.empty?

upload_data(@send_queue_ids)
Expand Down