mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
chore: revert custom index in favor of key_Split
Signed-off-by: Keith Zantow <keith.zantow@anchore.com>
This commit is contained in:
@@ -38,7 +38,7 @@ func TestLimiter_chargeAndRelease(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLimiter_refund(t *testing.T) {
|
||||
// a partial entry dropped at a bound is no longer on disk, so the limiter must not go on holding it
|
||||
// a partial entry dropped at a bound is no longer on disk, so the limiter must not still hold it
|
||||
limiter := NewLimiter(Limits{MaxDiskBytes: 100})
|
||||
charge := limiter.Charge()
|
||||
|
||||
@@ -55,8 +55,8 @@ func TestLimiter_refund(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLimiter_boundsAreIndependent(t *testing.T) {
|
||||
// a caller may bound one limit without bounding the other: a limit on one side of the pair does
|
||||
// not change how the other side reads its own value.
|
||||
// a caller may bound one limit without the other: a limit on one side does not change how the other
|
||||
// reads its own value
|
||||
memoryBounded := NewLimiter(Limits{MaxMemoryBytes: 10, MaxDiskBytes: -1}).Charge()
|
||||
assert.False(t, memoryBounded.Memory(50))
|
||||
assert.True(t, memoryBounded.Disk(1_000_000), "a negative disk limit admits anything")
|
||||
@@ -67,9 +67,8 @@ func TestLimiter_boundsAreIndependent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLimiter_threeStateReadingIsUniform(t *testing.T) {
|
||||
// Memory and Disk read their limit the same way: positive is the limit, zero refuses
|
||||
// unconditionally, negative admits unconditionally. The two used to disagree in opposite
|
||||
// directions - Memory got zero right and negative wrong, Disk got negative right and zero wrong.
|
||||
// Memory and Disk read their limit the same way: positive is the limit, zero refuses, negative
|
||||
// admits
|
||||
t.Run("positive is the limit", func(t *testing.T) {
|
||||
c := NewLimiter(Limits{MaxMemoryBytes: 100, MaxDiskBytes: 100}).Charge()
|
||||
assert.True(t, c.Memory(100))
|
||||
@@ -93,8 +92,7 @@ func TestLimiter_threeStateReadingIsUniform(t *testing.T) {
|
||||
|
||||
func TestLimiter_nilIsUnbounded(t *testing.T) {
|
||||
// what an extraction with no configured bounds gets: charges succeed and nothing is measured.
|
||||
// This is distinct from a configured but non-positive MaxMemoryBytes, which refuses instead -
|
||||
// there is no limiter here at all to refuse anything.
|
||||
// Distinct from a configured but non-positive MaxMemoryBytes, which refuses instead.
|
||||
var limiter *Limiter
|
||||
charge := limiter.Charge()
|
||||
assert.Nil(t, charge)
|
||||
@@ -104,22 +102,19 @@ func TestLimiter_nilIsUnbounded(t *testing.T) {
|
||||
charge.RefundDisk(10)
|
||||
charge.Release()
|
||||
|
||||
mem, disk := charge.Held()
|
||||
mem, disk := charge.held()
|
||||
assert.Zero(t, mem)
|
||||
assert.Zero(t, disk)
|
||||
|
||||
mem, disk = limiter.InUse()
|
||||
assert.Zero(t, mem)
|
||||
assert.Zero(t, disk)
|
||||
assert.Zero(t, limiter.MaxDiskBytes())
|
||||
}
|
||||
|
||||
func TestLimiter_concurrentChargesAgree(t *testing.T) {
|
||||
// the walk is sequential today, but the archive task merges into a shared builder while top-level
|
||||
// catalogers run, so the accounting is guarded rather than left for whoever parallelises it.
|
||||
// Both limits need an explicit value here: zero now refuses every charge on either bound, so
|
||||
// MaxMemoryBytes is set comfortably above what this test charges and MaxDiskBytes is negative
|
||||
// for unbounded, rather than leaving either at its zero value.
|
||||
// catalogers run, so the accounting is guarded. Both limits need an explicit value, since zero
|
||||
// refuses every charge: memory is set above what this test charges and disk is negative.
|
||||
limiter := NewLimiter(Limits{MaxMemoryBytes: 1_000_000, MaxDiskBytes: -1})
|
||||
|
||||
var wg sync.WaitGroup
|
||||
@@ -150,8 +145,8 @@ func TestLimiter_concurrentChargesAgree(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Limiter_peakIsAHighWaterMark(t *testing.T) {
|
||||
// the peak is what the scan held at its worst moment, so it must survive the release that takes
|
||||
// the in-use gauge back down - a peak that fell on release would measure what InUse already does
|
||||
// the peak is what the scan held at its worst moment, so it must survive the release that takes the
|
||||
// in-use gauge back down
|
||||
l := NewLimiter(Limits{MaxMemoryBytes: -1, MaxDiskBytes: -1})
|
||||
|
||||
first := l.Charge()
|
||||
@@ -173,8 +168,7 @@ func Test_Limiter_peakIsAHighWaterMark(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Limiter_peakCountsConcurrentHoldersTogether(t *testing.T) {
|
||||
// two archives held at the same time peak at their sum, which is the number the limits are
|
||||
// enforced against and therefore the number worth reporting
|
||||
// two archives held at once peak at their sum, the number the limits are enforced against
|
||||
l := NewLimiter(Limits{MaxMemoryBytes: -1, MaxDiskBytes: -1})
|
||||
|
||||
outer := l.Charge()
|
||||
@@ -196,8 +190,8 @@ func Test_Limiter_peakOfANilLimiterIsZero(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Limiter_refusedChargeDoesNotMoveThePeak(t *testing.T) {
|
||||
// nothing is charged when a limit refuses, so nothing may be recorded either: a peak that rose
|
||||
// on refusal would report bytes the scan never held
|
||||
// nothing is charged when a limit refuses, so nothing may be recorded: a peak that rose on refusal
|
||||
// would report bytes the scan never held
|
||||
l := NewLimiter(Limits{MaxMemoryBytes: 50, MaxDiskBytes: 50})
|
||||
|
||||
c := l.Charge()
|
||||
|
||||
Reference in New Issue
Block a user