Skip to content

Commit

Permalink
add tests for ceil and floor rounding opts
Browse files Browse the repository at this point in the history
  • Loading branch information
wallee94 committed Nov 21, 2023
1 parent c022213 commit 57c88e3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions internal/runtime/cpu_quota_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ func TestNewQueryer(t *testing.T) {
_, err := newQueryer()
assert.ErrorIs(t, err, giveErr)
})

t.Run("round quota with ceil", func(t *testing.T) {
stubs := newStubs(t)

q := testQueryer{v: 2.7}
stubs.StubFunc(&_newCgroups2, q, nil)

got, _, err := CPUQuotaToGOMAXPROCS(0, Ceil)
require.NoError(t, err)
assert.Same(t, 3, got)
})

t.Run("round quota with floor", func(t *testing.T) {
stubs := newStubs(t)

q := testQueryer{v: 2.7}
stubs.StubFunc(&_newCgroups2, q, nil)

got, _, err := CPUQuotaToGOMAXPROCS(0, Floor)
require.NoError(t, err)
assert.Same(t, 2, got)
})
}

type testQueryer struct {
v float64
}

func (tq testQueryer) CPUQuota() (float64, bool, error) {
return tq.v, true, nil
}

func newStubs(t *testing.T) *gostub.Stubs {
Expand Down

0 comments on commit 57c88e3

Please sign in to comment.