Skip to content

Commit

Permalink
move test that belongs to DistributeFairly()
Browse files Browse the repository at this point in the history
  • Loading branch information
majewsky committed May 21, 2024
1 parent a0c5ac2 commit 7613787
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
21 changes: 0 additions & 21 deletions internal/datamodel/apply_computed_project_quota_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"

"github.com/sapcc/go-api-declarations/limes"
"github.com/sapcc/go-bits/assert"

"github.com/sapcc/limes/internal/core"
"github.com/sapcc/limes/internal/db"
Expand Down Expand Up @@ -403,23 +402,3 @@ func expectACPQResult(t *testing.T, input map[limes.AvailabilityZone]clusterAZAl
func p2u64(x uint64) *uint64 {
return &x
}

func TestACPQDistributeFairlyWithLargeNumbers(t *testing.T) {
// This tests how acpqDistributeFairly() deals with very large numbers
// (as can occur e.g. for Swift capacity measured in bytes).
// We used to have a crash here because of an overflowing uint64 multiplication.
total := uint64(200000000000000)
requested := map[db.ProjectServiceID]uint64{
401: total / 2,
402: total / 2,
403: total / 2,
404: total / 2,
}
result := acpqDistributeFairly(total, requested)
assert.DeepEqual(t, "output of acpqDistributeFairly", result, map[db.ProjectServiceID]uint64{
401: total / 4,
402: total / 4,
403: total / 4,
404: total / 4,
})
}
50 changes: 50 additions & 0 deletions internal/util/algorithms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*******************************************************************************
*
* Copyright 2024 SAP SE
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You should have received a copy of the License along with this
* program. If not, you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*******************************************************************************/

package util

import (
"testing"

"github.com/sapcc/go-bits/assert"

"github.com/sapcc/limes/internal/db"
)

// NOTE: Most test coverage for DistributeFairly() is implicit as part of datamodel.ApplyComputedProjectQuota().

func TestDistributeFairlyWithLargeNumbers(t *testing.T) {
// This tests how DistributeFairly() deals with very large numbers
// (as can occur e.g. for Swift capacity measured in bytes).
// We used to have a crash here because of an overflowing uint64 multiplication.
total := uint64(200000000000000)
requested := map[db.ProjectServiceID]uint64{
401: total / 2,
402: total / 2,
403: total / 2,
404: total / 2,
}
result := DistributeFairly(total, requested)
assert.DeepEqual(t, "output of DistributeFairly", result, map[db.ProjectServiceID]uint64{
401: total / 4,
402: total / 4,
403: total / 4,
404: total / 4,
})
}

0 comments on commit 7613787

Please sign in to comment.