2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

DEV: Add a new way to run specs in parallel with better output (#7778)

* DEV: Add a new way to run specs in parallel with better output

This commit:

 1. adds a new executable, `bin/interleaved_rspec` which works much like
    `rspec`, but runs the tests in parallel.

 2. adds a rake task, `rake interleaved:spec` which runs the whole test
    suite.

 3. makes autospec use this new wrapper by default. You can disable this
    by running `PARALLEL_SPEC=0 rake autospec`.

It works much like the `parallel_tests` gem (and relies on it), but
makes each subprocess use a machine-readable formatter and parses this
output in order to provide a better overall summary.

(It's called interleaved, because parallel was taken and naming is
hard).

* Make popen3 invocation safer

* Use FileUtils instead of shelling out

* DRY up reporter

* Moved summary logic into Reporter

* s/interleaved/turbo/g

* Move Reporter into its own file

* Moved run into its own class

* Moved Runner into its own file

* Move JsonRowsFormatter under TurboTests

* Join on threads at the end

* Acted on feedback from eviltrout
This commit is contained in:
Daniel Waterworth 2019-06-21 01:59:01 +01:00 committed by Sam
parent 9f0574dcfd
commit e18ce56f4b
9 changed files with 460 additions and 30 deletions

View file

@ -0,0 +1,93 @@
module TurboTests
# An RSpec formatter used for each subprocess during parallel test execution
class JsonRowsFormatter
RSpec::Core::Formatters.register(
self,
:close,
:example_failed,
:example_passed,
:example_pending,
:seed
)
attr_reader :output
def initialize(output)
@output = output
end
def exception_to_json(exception)
if exception
{
backtrace: exception.backtrace,
message: exception.message,
cause: exception.cause
}
end
end
def execution_result_to_json(result)
{
example_skipped?: result.example_skipped?,
pending_message: result.pending_message,
status: result.status,
pending_fixed?: result.pending_fixed?,
exception: exception_to_json(result.exception)
}
end
def example_to_json(example)
{
execution_result: execution_result_to_json(example.execution_result),
location: example.location,
full_description: example.full_description,
metadata: {
shared_group_inclusion_backtrace:
example.metadata[:shared_group_inclusion_backtrace]
},
location_rerun_argument: example.location_rerun_argument
}
end
def example_passed(notification)
output_row({
type: :example_passed,
example: example_to_json(notification.example)
})
end
def example_pending(notification)
output_row({
type: :example_pending,
example: example_to_json(notification.example)
})
end
def example_failed(notification)
output_row({
type: :example_failed,
example: example_to_json(notification.example)
})
end
def seed(notification)
output_row({
type: :seed,
seed: notification.seed,
})
end
def close(notification)
output_row({
type: :close,
})
end
private
def output_row(obj)
output.puts(obj.to_json)
output.flush
end
end
end