Skip to content
Merged
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
5 changes: 3 additions & 2 deletions pkg/selector/comparators.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ func supportSyntaxToBool(instanceTypeSupport *string) *bool {
}

func calculateVCpusToMemoryRatio(vcpusVal *int64, memoryVal *int64) *float64 {
if vcpusVal == nil || memoryVal == nil {
if vcpusVal == nil || *vcpusVal == 0 || memoryVal == nil {
return nil
}
// normalize vcpus to a mebivcpu value
return aws.Float64(float64(*memoryVal) / float64(*vcpusVal*1024))
result := math.Ceil(float64(*memoryVal) / float64(*vcpusVal*1024))
return &result
}

// Slice helper function
Expand Down
11 changes: 8 additions & 3 deletions pkg/selector/comparators_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,22 @@ func TestCalculateVCpusToMemoryRatio(t *testing.T) {
vcpus := aws.Int64(4)
memory := aws.Int64(4096)
ratio := calculateVCpusToMemoryRatio(vcpus, memory)
h.Assert(t, *ratio == 1.00, "nil should evaluate to nil")
h.Assert(t, *ratio == 1.00, "ratio should equal 1:1")

vcpus = aws.Int64(2)
memory = aws.Int64(4096)
ratio = calculateVCpusToMemoryRatio(vcpus, memory)
h.Assert(t, *ratio == 2.00, "nil should evaluate to nil")
h.Assert(t, *ratio == 2.00, "ratio should equal 1:2")

vcpus = aws.Int64(1)
memory = aws.Int64(512)
ratio = calculateVCpusToMemoryRatio(vcpus, memory)
h.Assert(t, *ratio == 0.50, "nil should evaluate to nil")
h.Assert(t, *ratio == 1.0, "ratio should take the ceiling which equals 1:1")

vcpus = aws.Int64(0)
memory = aws.Int64(512)
ratio = calculateVCpusToMemoryRatio(vcpus, memory)
h.Assert(t, ratio == nil, "ratio should be nil when vcpus is 0")
}

func TestCalculateVCpusToMemoryRatio_Nil(t *testing.T) {
Expand Down