Skip to content

Commit 455b61c

Browse files
jdelStrotherbriandunn
authored andcommitted
Don't spawn more workers than there are jobs
1 parent 0d9727f commit 455b61c

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

lib/flatware/cli.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def try_setpgrp
7676
def workers
7777
options[:workers]
7878
end
79+
80+
def worker_spawn_count(jobs)
81+
[workers, jobs.length].min
82+
end
7983
end
8084
end
8185

lib/flatware/cucumber/cli.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,22 @@ class CLI
1616
'parallelizes cucumber with custom arguments'
1717
)
1818
def cucumber(*args)
19-
config = Cucumber.configure args
19+
jobs = load_jobs(args)
2020

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

2323
Flatware.verbose = options[:log]
24-
sink = options['sink-endpoint']
25-
Worker.spawn(count: workers, runner: Cucumber, sink: sink)
26-
start_sink(
27-
jobs: config.jobs,
28-
workers: workers,
29-
formatter: Flatware::Cucumber::Formatters::Console.new($stdout, $stderr)
30-
)
24+
25+
spawn_count = worker_spawn_count(jobs)
26+
Worker.spawn(count: spawn_count, runner: Cucumber, sink: options['sink-endpoint'])
27+
start_sink(jobs: jobs, workers: spawn_count, formatter: formatter)
3128
end
3229

3330
private
3431

35-
def ensure_jobs(config)
36-
return if config.jobs.any?
32+
def load_jobs(args)
33+
config = Cucumber.configure args
34+
return config.jobs if config.jobs.any?
3735

3836
abort(
3937
format(

lib/flatware/rspec/cli.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def rspec(*rspec_args)
2323
)
2424

2525
Flatware.verbose = options[:log]
26-
Worker.spawn count: workers, runner: RSpec, sink: options['sink-endpoint']
27-
start_sink(jobs: jobs, workers: workers, formatter: formatter)
26+
27+
spawn_count = worker_spawn_count(jobs)
28+
Worker.spawn(count: spawn_count, runner: RSpec, sink: options['sink-endpoint'])
29+
start_sink(jobs: jobs, workers: spawn_count, formatter: formatter)
2830
end
2931
end
3032
end

0 commit comments

Comments
 (0)