Skip to content

Commit 910008d

Browse files
committed
Increase the job capacity of all plans by 1
This work is part of the "1 free private repo job" plan. https://github.com/travis-ci/product/issues/97
1 parent eae37af commit 910008d

File tree

5 files changed

+69
-45
lines changed

5 files changed

+69
-45
lines changed

lib/travis/owners/subscriptions.rb

+19-2
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,32 @@ def plan_limits
2525
end
2626

2727
def plan_limit(plan)
28-
config[plan.to_sym].tap { |limit| missing_plan(plan) unless limit }
28+
limit = config[plan[:plan].to_sym].tap { |limit| missing_plan(plan[:plan]) unless limit }
29+
30+
# Increment this by 1 as our original values are being increased up by
31+
# one as part of our "free 1-job private repo" plan project,
32+
# expected to be launched in December, 2018.
33+
#
34+
# https://github.com/travis-ci/product/issues/97
35+
#
36+
37+
if plan[:owner].is_a?(User) && !limit.nil?
38+
limit += 1 unless limit.nil?
39+
end
40+
41+
limit
2942
end
3043

3144
def missing_plan(plan)
3245
logger.warn MSGS[:missing_plan] % [plan, owners.to_s]
3346
end
3447

3548
def plans
36-
subscriptions.map(&:selected_plan).compact
49+
subscriptions.map { |sub|
50+
if sub.selected_plan && sub.owner
51+
{ plan: sub.selected_plan, owner: sub.owner }
52+
end
53+
}.compact
3754
end
3855

3956
def subscriptions

spec/travis/owners/subscriptions_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
subject { described_class.new(owners, plans).max_jobs }
1212

13+
# Note that all plans are 1 higher than their original values due to our "free
14+
# 1-job private repo" plan project, expected to be launched in December,
15+
# 2018.
16+
#
17+
# https://github.com/travis-ci/product/issues/97
18+
#
19+
1320
describe 'a single org with a five jobs plan' do
1421
before { FactoryGirl.create(:subscription, owner: travis, selected_plan: :five) }
1522
it { should eq 5 }

spec/travis/owners_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
describe 'with a subscription on the delegatee' do
1818
before { FactoryGirl.create(:subscription, owner: anja, selected_plan: :ten) }
19-
it { expect(owners.max_jobs).to eq 10 }
19+
it { expect(owners.max_jobs).to eq 11 }
2020
end
2121

2222
describe 'with a subscription on the delegate' do
@@ -27,7 +27,7 @@
2727
describe 'with a subscription on both the delegatee and delegate' do
2828
before { FactoryGirl.create(:subscription, owner: anja, selected_plan: :ten) }
2929
before { FactoryGirl.create(:subscription, owner: travis, selected_plan: :five) }
30-
it { expect(owners.max_jobs).to eq 15 }
30+
it { expect(owners.max_jobs).to eq 16 }
3131
end
3232
end
3333

spec/travis/scheduler/jobs_spec.rb

+24-24
Original file line numberDiff line numberDiff line change
@@ -86,33 +86,33 @@ def subscribe(plan, owner = self.user)
8686
before { create_jobs(1, private: true, state: :started) }
8787
before { create_jobs(5, private: true) }
8888

89-
it { expect(selected.size).to eq 1 }
90-
it { expect(reports).to include 'user svenfuchs capacities: public max=3, plan max=2' }
91-
it { expect(reports).to include 'user svenfuchs plan capacity: running=1 max=2 selected=1' }
92-
it { expect(reports).to include 'user svenfuchs: queueable=5 running=1 selected=1 total_waiting=4 waiting_for_concurrency=4' }
89+
it { expect(selected.size).to eq 2 }
90+
it { expect(reports).to include 'user svenfuchs capacities: public max=3, plan max=3' }
91+
it { expect(reports).to include 'user svenfuchs plan capacity: running=1 max=3 selected=2' }
92+
it { expect(reports).to include 'user svenfuchs: queueable=5 running=1 selected=2 total_waiting=3 waiting_for_concurrency=3' }
9393
end
9494

9595
describe 'with public jobs only' do
9696
before { create_jobs(1, private: false, state: :started) }
9797
before { create_jobs(5, private: false) }
9898

99-
it { expect(selected.size).to eq 4 }
100-
it { expect(reports).to include 'user svenfuchs capacities: public max=3, plan max=2' }
99+
it { expect(selected.size).to eq 5 }
100+
it { expect(reports).to include 'user svenfuchs capacities: public max=3, plan max=3' }
101101
it { expect(reports).to include 'user svenfuchs public capacity: running=1 max=3 selected=2' }
102-
it { expect(reports).to include 'user svenfuchs plan capacity: running=0 max=2 selected=2' }
103-
it { expect(reports).to include 'user svenfuchs: queueable=5 running=1 selected=4 total_waiting=1 waiting_for_concurrency=1' }
102+
it { expect(reports).to include 'user svenfuchs plan capacity: running=0 max=3 selected=3' }
103+
it { expect(reports).to include 'user svenfuchs: queueable=5 running=1 selected=5 total_waiting=0 waiting_for_concurrency=0' }
104104
end
105105

106106
describe 'for mixed public and private jobs' do
107107
before { create_jobs(1, private: true, state: :started) }
108108
before { create_jobs(1, private: false, state: :started) }
109109
before { create_jobs(2, private: false) + create_jobs(2, private: true) }
110110

111-
it { expect(selected.size).to eq 3 }
112-
it { expect(reports).to include 'user svenfuchs capacities: public max=3, plan max=2' }
111+
it { expect(selected.size).to eq 4 }
112+
it { expect(reports).to include 'user svenfuchs capacities: public max=3, plan max=3' }
113113
it { expect(reports).to include 'user svenfuchs public capacity: running=1 max=3 selected=2' }
114-
it { expect(reports).to include 'user svenfuchs plan capacity: running=1 max=2 selected=1' }
115-
it { expect(reports).to include 'user svenfuchs: queueable=4 running=2 selected=3 total_waiting=1 waiting_for_concurrency=1' }
114+
it { expect(reports).to include 'user svenfuchs plan capacity: running=1 max=3 selected=2' }
115+
it { expect(reports).to include 'user svenfuchs: queueable=4 running=2 selected=4 total_waiting=0 waiting_for_concurrency=0' }
116116
end
117117
end
118118

@@ -232,30 +232,30 @@ def subscribe(plan, owner = self.user)
232232
before { create_jobs(1, private: true, state: :started) }
233233
before { create_jobs(5, private: true) }
234234

235-
it { expect(selected.size).to eq 1 }
236-
it { expect(reports).to include 'user svenfuchs plan capacity: running=1 max=2 selected=1' }
237-
it { expect(reports).to include 'user svenfuchs: queueable=5 running=1 selected=1 total_waiting=4 waiting_for_concurrency=4' }
235+
it { expect(selected.size).to eq 2 }
236+
it { expect(reports).to include 'user svenfuchs plan capacity: running=1 max=3 selected=2' }
237+
it { expect(reports).to include 'user svenfuchs: queueable=5 running=1 selected=2 total_waiting=3 waiting_for_concurrency=3' }
238238
end
239239

240240
describe 'with public jobs only' do
241241
before { create_jobs(1, private: false, state: :started) }
242242
before { create_jobs(5, private: false) }
243243

244-
it { expect(selected.size).to eq 4 }
244+
it { expect(selected.size).to eq 5 }
245245
it { expect(reports).to include 'user svenfuchs public capacity: running=1 max=3 selected=2' }
246-
it { expect(reports).to include 'user svenfuchs plan capacity: running=0 max=2 selected=2' }
247-
it { expect(reports).to include 'user svenfuchs: queueable=5 running=1 selected=4 total_waiting=1 waiting_for_concurrency=1' }
246+
it { expect(reports).to include 'user svenfuchs plan capacity: running=0 max=3 selected=3' }
247+
it { expect(reports).to include 'user svenfuchs: queueable=5 running=1 selected=5 total_waiting=0 waiting_for_concurrency=0' }
248248
end
249249

250250
describe 'for mixed public and private jobs' do
251251
before { create_jobs(1, private: true, state: :started) }
252252
before { create_jobs(1, private: false, state: :started) }
253253
before { create_jobs(2, private: false) + create_jobs(2, private: true) }
254254

255-
it { expect(selected.size).to eq 3 }
255+
it { expect(selected.size).to eq 4 }
256256
it { expect(reports).to include 'user svenfuchs public capacity: running=1 max=3 selected=2' }
257-
it { expect(reports).to include 'user svenfuchs plan capacity: running=1 max=2 selected=1' }
258-
it { expect(reports).to include 'user svenfuchs: queueable=4 running=2 selected=3 total_waiting=1 waiting_for_concurrency=1' }
257+
it { expect(reports).to include 'user svenfuchs plan capacity: running=1 max=3 selected=2' }
258+
it { expect(reports).to include 'user svenfuchs: queueable=4 running=2 selected=4 total_waiting=0 waiting_for_concurrency=0' }
259259
end
260260
end
261261

@@ -381,7 +381,7 @@ def subscribe(plan, owner = self.user)
381381

382382
it { expect(selected.size).to eq 3 }
383383
it { expect(reports).to include 'user svenfuchs limited by queue builds.osx: max=3 rejected=7 selected=2' }
384-
it { expect(reports).to include 'user svenfuchs plan capacity: running=2 max=10 selected=3' }
384+
it { expect(reports).to include 'user svenfuchs plan capacity: running=2 max=11 selected=3' }
385385
it { expect(reports).to include 'user svenfuchs: queueable=10 running=2 selected=3 total_waiting=7 waiting_for_concurrency=0' }
386386
end
387387

@@ -394,7 +394,7 @@ def subscribe(plan, owner = self.user)
394394
it { expect(selected.size).to eq 3 }
395395
it { expect(reports).to include 'user svenfuchs limited by queue builds.osx: max=3 rejected=7 selected=2' }
396396
it { expect(reports).to include 'user svenfuchs public capacity: running=2 max=3 selected=1' }
397-
it { expect(reports).to include 'user svenfuchs plan capacity: running=0 max=10 selected=2' }
397+
it { expect(reports).to include 'user svenfuchs plan capacity: running=0 max=11 selected=2' }
398398
it { expect(reports).to include 'user svenfuchs: queueable=10 running=2 selected=3 total_waiting=7 waiting_for_concurrency=0' }
399399
end
400400

@@ -409,7 +409,7 @@ def subscribe(plan, owner = self.user)
409409
it { expect(selected.size).to eq 4 }
410410
it { expect(reports).to include 'user svenfuchs limited by queue builds.osx: max=3 rejected=6 selected=2' }
411411
it { expect(reports).to include 'user svenfuchs public capacity: running=0 max=3 selected=1' }
412-
it { expect(reports).to include 'user svenfuchs plan capacity: running=2 max=10 selected=3' }
412+
it { expect(reports).to include 'user svenfuchs plan capacity: running=2 max=11 selected=3' }
413413
it { expect(reports).to include 'user svenfuchs: queueable=10 running=2 selected=4 total_waiting=6 waiting_for_concurrency=0' }
414414
end
415415
end

spec/travis/scheduler/limit/com_spec.rb

+17-17
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ def subscription(plan, owner = self.owner)
8484
before { create_jobs(2, state: :created, private: true) }
8585
before { run }
8686

87-
it { expect(selected).to eq 1 }
88-
it { expect(report).to include('max jobs for user svenfuchs by plan: 2 (svenfuchs)') }
89-
it { expect(report).to include('user svenfuchs: total: 2, running: 1, queueable: 1') }
90-
it { expect(limit.waiting_by_owner).to eq 1 }
87+
it { expect(selected).to eq 2 }
88+
it { expect(report).to include('max jobs for user svenfuchs by plan: 3 (svenfuchs)') }
89+
it { expect(report).to include('user svenfuchs: total: 2, running: 1, queueable: 2') }
90+
it { expect(limit.waiting_by_owner).to eq 0 }
9191
end
9292

9393
describe 'with public jobs only' do
@@ -97,7 +97,7 @@ def subscription(plan, owner = self.owner)
9797
before { run }
9898

9999
it { expect(selected).to eq 2 }
100-
it { expect(report).to include('max jobs for user svenfuchs by plan: 5 (svenfuchs)') } # TODO fix log output?
100+
it { expect(report).to include('max jobs for user svenfuchs by plan: 6 (svenfuchs)') } # TODO fix log output?
101101
it { expect(report).to include('user svenfuchs: total: 2, running: 1, queueable: 2') }
102102
it { expect(limit.waiting_by_owner).to eq 0 }
103103
end
@@ -110,10 +110,10 @@ def subscription(plan, owner = self.owner)
110110
before { subscription(:two) }
111111
before { run }
112112

113-
it { expect(selected).to eq 3 }
114-
it { expect(report).to include('max jobs for user svenfuchs by plan: 2 (svenfuchs)') }
115-
it { expect(report).to include('user svenfuchs: total: 4, running: 2, queueable: 3') }
116-
it { expect(limit.waiting_by_owner).to eq 1 }
113+
it { expect(selected).to eq 4 }
114+
it { expect(report).to include('max jobs for user svenfuchs by plan: 3 (svenfuchs)') }
115+
it { expect(report).to include('user svenfuchs: total: 4, running: 2, queueable: 4') }
116+
it { expect(limit.waiting_by_owner).to eq 0 }
117117
end
118118
end
119119

@@ -303,7 +303,7 @@ def subscription(plan, owner = self.owner)
303303
before { run }
304304

305305
it { expect(selected).to eq 2 }
306-
it { expect(report).to include('max jobs for user svenfuchs by plan: 4 (svenfuchs)') }
306+
it { expect(report).to include('max jobs for user svenfuchs by plan: 5 (svenfuchs)') }
307307
it { expect(report).to include('max jobs for repo svenfuchs/gem-release by repo_settings: 3') }
308308
it { expect(report).to include('user svenfuchs: total: 4, running: 1, queueable: 2') }
309309
it { expect(limit.waiting_by_owner).to eq 0 } # TODO eh??? should be 2, no?
@@ -315,7 +315,7 @@ def subscription(plan, owner = self.owner)
315315
before { run }
316316

317317
it { expect(selected).to eq 2 }
318-
it { expect(report).to include('max jobs for user svenfuchs by plan: 7 (svenfuchs)') } # TODO fix log output?
318+
it { expect(report).to include('max jobs for user svenfuchs by plan: 8 (svenfuchs)') } # TODO fix log output?
319319
it { expect(report).to include('max jobs for repo svenfuchs/gem-release by repo_settings: 3') }
320320
it { expect(report).to include('user svenfuchs: total: 4, running: 1, queueable: 2') }
321321
it { expect(limit.waiting_by_owner).to eq 0 }
@@ -329,7 +329,7 @@ def subscription(plan, owner = self.owner)
329329
before { run }
330330

331331
it { expect(selected).to eq 1 }
332-
it { expect(report).to include('max jobs for user svenfuchs by plan: 4 (svenfuchs)') }
332+
it { expect(report).to include('max jobs for user svenfuchs by plan: 5 (svenfuchs)') }
333333
it { expect(report).to include('max jobs for repo svenfuchs/gem-release by repo_settings: 3') }
334334
it { expect(report).to include('user svenfuchs: total: 6, running: 2, queueable: 1') }
335335
it { expect(limit.waiting_by_owner).to eq 0 } # TODO eh???
@@ -343,8 +343,8 @@ def subscription(plan, owner = self.owner)
343343
before { subscription(:two) }
344344
before { run }
345345

346-
it { expect(selected).to eq 2 }
347-
it { expect(report).to include('user svenfuchs: total: 4, running: 0, queueable: 2') }
346+
it { expect(selected).to eq 3 }
347+
it { expect(report).to include('user svenfuchs: total: 4, running: 0, queueable: 3') }
348348
end
349349

350350
describe 'with public jobs only' do
@@ -397,7 +397,7 @@ def subscription(plan, owner = self.owner)
397397

398398
it { expect(selected).to eq 6 }
399399
it { expect(limit.selected.map(&:owner).map(&:login)).to eq ['svenfuchs'] * 3 + ['travis-ci'] * 3 }
400-
it { expect(report).to include('max jobs for user svenfuchs by plan: 8 (svenfuchs, travis-ci)') }
400+
it { expect(report).to include('max jobs for user svenfuchs by plan: 9 (svenfuchs, travis-ci)') }
401401
it { expect(report).to include('user svenfuchs, user carla, org travis-ci: total: 6, running: 2, queueable: 6') }
402402
end
403403
end
@@ -430,7 +430,7 @@ def subscription(plan, owner = self.owner)
430430

431431
it { expect(selected).to eq 6 }
432432
it { expect(limit.selected.map(&:owner).map(&:login)).to eq ['svenfuchs'] * 3 + ['travis-ci'] * 3 }
433-
it { expect(report).to include('max jobs for user svenfuchs by plan: 8 (svenfuchs, travis-ci)') } # TODO fix log output
433+
it { expect(report).to include('max jobs for user svenfuchs by plan: 9 (svenfuchs, travis-ci)') } # TODO fix log output
434434
it { expect(report).to include('user svenfuchs, user carla, org travis-ci: total: 6, running: 2, queueable: 6') }
435435
end
436436
end
@@ -463,7 +463,7 @@ def subscription(plan, owner = self.owner)
463463

464464
it { expect(selected).to eq 6 }
465465
it { expect(limit.selected.map(&:owner).map(&:login)).to eq ['svenfuchs'] * 3 + ['travis-ci'] * 3 }
466-
it { expect(report).to include('max jobs for user svenfuchs by plan: 8 (svenfuchs, travis-ci)') }
466+
it { expect(report).to include('max jobs for user svenfuchs by plan: 9 (svenfuchs, travis-ci)') }
467467
it { expect(report).to include('user svenfuchs, user carla, org travis-ci: total: 6, running: 2, queueable: 6') }
468468
end
469469
end

0 commit comments

Comments
 (0)