Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct planner's behaviour when there are no capacity left for buffer #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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: 2 additions & 2 deletions engine/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func (p *planner) Plan(ctx context.Context) error {

ctx = logger.WithContext(ctx, log)

free := max(capacity-running-p.buffer, 0)
diff := serverDiff(pending, free, p.cap)
free := max(capacity-running, 0)
diff := serverDiff(pending+p.buffer, free, p.cap)

// if the server differential to handle the build volume
// is positive, we can reduce server capacity.
Expand Down
44 changes: 44 additions & 0 deletions engine/planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,50 @@ func TestPlan_MoreBufferCapacity(t *testing.T) {
}
}

// This test verifies that if the server capacity minus buffer is
// less than the pending count, and the server capacity is
// < the pool maximum, additional servers are provisioned.
// Edge case: server capacity - buffer < 0
func TestPlan_MoreBufferCapacity_2(t *testing.T) {
controller := gomock.NewController(t)
defer controller.Finish()

// x2 capacity
servers := []*autoscaler.Server{
{Name: "server1", Capacity: 2, State: autoscaler.StateRunning},
}

// x2 running builds
// x0 pending builds
builds := []*drone.Stage{
{Status: drone.StatusRunning},
{Status: drone.StatusRunning},
}

store := mocks.NewMockServerStore(controller)
store.EXPECT().List(gomock.Any()).Return(servers, nil)
store.EXPECT().Create(gomock.Any(), gomock.Any()).Return(nil)

client := mocks.NewMockClient(controller)
client.EXPECT().Queue().Return(builds, nil)

p := planner{
cap: 2,
buffer: 1,
min: 1,
max: 4,
client: client,
servers: store,
}

err := p.Plan(context.TODO())
if err != nil {
t.Error(err)
}
}



// This test verifies that if the server capacity is
// < than the pending count, and the server capacity is
// >= the pool maximum, no actions are taken.
Expand Down