Skip to content
Open
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
4 changes: 4 additions & 0 deletions lib/flatware/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def try_setpgrp
def workers
options[:workers]
end

def worker_spawn_count(jobs)
[workers, jobs.length].min
end
end
end

Expand Down
20 changes: 9 additions & 11 deletions lib/flatware/cucumber/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,22 @@ class CLI
'parallelizes cucumber with custom arguments'
)
def cucumber(*args)
config = Cucumber.configure args
jobs = load_jobs(args)

ensure_jobs(config)
formatter = Flatware::Cucumber::Formatters::Console.new($stdout, $stderr)

Flatware.verbose = options[:log]
sink = options['sink-endpoint']
Worker.spawn(count: workers, runner: Cucumber, sink: sink)
start_sink(
jobs: config.jobs,
workers: workers,
formatter: Flatware::Cucumber::Formatters::Console.new($stdout, $stderr)
)

spawn_count = worker_spawn_count(jobs)
Worker.spawn(count: spawn_count, runner: Cucumber, sink: options['sink-endpoint'])
start_sink(jobs: jobs, workers: spawn_count, formatter: formatter)
end

private

def ensure_jobs(config)
return if config.jobs.any?
def load_jobs(args)
config = Cucumber.configure args
return config.jobs if config.jobs.any?
Comment on lines 18 to +34
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed more than strictly necessary here, just so that the Flatware::Cucumber::CLI#cucumber method looks more like Flatware::RSpec::CLI#rspec.

I don't use cucumber myself so would welcome some extra testing here


abort(
format(
Expand Down
6 changes: 4 additions & 2 deletions lib/flatware/rspec/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def rspec(*rspec_args)
)

Flatware.verbose = options[:log]
Worker.spawn count: workers, runner: RSpec, sink: options['sink-endpoint']
start_sink(jobs: jobs, workers: workers, formatter: formatter)

spawn_count = worker_spawn_count(jobs)
Worker.spawn(count: spawn_count, runner: RSpec, sink: options['sink-endpoint'])
start_sink(jobs: jobs, workers: spawn_count, formatter: formatter)
end
end
end
16 changes: 11 additions & 5 deletions lib/flatware/rspec/job_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ def jobs
private

def balance_jobs(bucket_count:, timed_files:, untimed_files:)
balance_by(bucket_count, timed_files, &:last)
.map { |bucket| bucket.map(&:first) }
.zip(
round_robin(bucket_count, untimed_files)
).map(&:flatten)
timed_groups = balance_by(bucket_count, timed_files, &:last)
.map { |bucket| bucket.map(&:first) }
untimed_groups = round_robin(bucket_count, untimed_files)

# When the files can't be evenly divided between groups, the first groups
# in each of timed_groups & untimed_groups will have more files.
# By reversing one of them before combining them, we can improve the final distribution.
timed_groups
.zip(untimed_groups.reverse)
.map(&:flatten)
.reject(&:empty?)
.map { |files| Job.new(files, args) }
end

Expand Down
24 changes: 23 additions & 1 deletion spec/flatware/rspec/job_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

let(:persisted_examples) { [] }
let(:files_to_run) { [] }
let(:worker_count) { 2 }

subject do
described_class.new([], workers: 2).jobs
described_class.new([], workers: worker_count).jobs
end

context 'when this run includes persisted examples' do
Expand Down Expand Up @@ -65,5 +66,26 @@
)
end
end

context 'and there are more workers than example-files' do
let(:files_to_run) do
%w[
fast_1_spec.rb
slow_spec.rb
new_1_spec.rb
]
end
let(:worker_count) { 5 }

it "doesn't return empty job-groups" do
expect(subject).to match_array(
[
have_attributes(id: include('./fast_1_spec.rb')),
have_attributes(id: include('./slow_spec.rb')),
have_attributes(id: include('./new_1_spec.rb'))
]
)
end
end
end
end
Loading