protondrive: check warm listings within the listing budget test
The warm listing budget, with caching on and off, reuses the folders TestBudgetList seeds instead of seeding its own, which saves about 15s under -race. The assertions are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
16480e3d80
commit
c28077174e
1 file changed
+28
-50
@@ -87,68 +87,46 @@ func seedBudgetFolders(srv *protontest.Server, u *protontest.User, sizes []int)
|
||||
// 9.4's P + ceil(N/100) + 1. The Fs is rooted at the folder, so finding
|
||||
// it is part of NewFs.
|
||||
//
|
||||
// A second listing costs nothing with enable_caching at its default,
|
||||
// and with it off costs the same as the first, no more. The latter is
|
||||
// checked at the sizes which differ in kind - empty, one batch, several
|
||||
// pages and batches - to save time.
|
||||
//
|
||||
// Measured, per route (children pages + links batches):
|
||||
// N=0: 1+0, N=1: 1+1, N=100: 1+1, N=101: 1+2, N=250: 2+3 - exactly
|
||||
// P + ceil(N/100), so the bound is that, without the spec's +1.
|
||||
// P + ceil(N/100), so the bound is that, without the spec's +1. Warm: 0
|
||||
// at every N; with caching off the second listing repeats the first.
|
||||
func TestBudgetList(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
remote, srv, u := setupFakeRemote(t)
|
||||
seedBudgetFolders(srv, u, budgetSizes)
|
||||
list := func(t *testing.T, f fs.Fs, n int) map[string]int {
|
||||
t.Helper()
|
||||
srv.ResetRequests()
|
||||
entries, err := f.List(ctx, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, entries, n)
|
||||
return srv.Requests()
|
||||
}
|
||||
for _, n := range budgetSizes {
|
||||
t.Run(fmt.Sprint(n), func(t *testing.T) {
|
||||
f := newFakeFs(t, remote, fmt.Sprintf("n%d", n))
|
||||
srv.ResetRequests()
|
||||
entries, err := f.List(ctx, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, entries, n)
|
||||
|
||||
got := srv.Requests()
|
||||
root := fmt.Sprintf("n%d", n)
|
||||
f := newFakeFs(t, remote, root)
|
||||
cold := list(t, f, n)
|
||||
pages, batches := childPages(n, budgetPageSize), ceilDiv(n, 100)
|
||||
assert.LessOrEqual(t, got[childrenRoute], pages, "%v", got)
|
||||
assert.LessOrEqual(t, got[linksRoute], batches, "%v", got)
|
||||
assert.LessOrEqual(t, totalRequests(got), pages+batches, "%v", got)
|
||||
})
|
||||
}
|
||||
}
|
||||
assert.LessOrEqual(t, cold[childrenRoute], pages, "%v", cold)
|
||||
assert.LessOrEqual(t, cold[linksRoute], batches, "%v", cold)
|
||||
assert.LessOrEqual(t, totalRequests(cold), pages+batches, "%v", cold)
|
||||
|
||||
// TestBudgetWarmList checks a second listing costs nothing with
|
||||
// enable_caching at its default, and with it off costs the same as the
|
||||
// first, no more.
|
||||
//
|
||||
// It is checked at the sizes of TestBudgetList which differ in kind -
|
||||
// empty, one batch, several pages and batches - to save time.
|
||||
//
|
||||
// Measured: warm 0 at every N; with caching off the second listing
|
||||
// repeats the cold breakdown of TestBudgetList exactly.
|
||||
func TestBudgetWarmList(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
sizes := []int{0, 1, 250}
|
||||
remote, srv, u := setupFakeRemote(t)
|
||||
seedBudgetFolders(srv, u, sizes)
|
||||
for _, caching := range []bool{true, false} {
|
||||
t.Run(fmt.Sprintf("caching=%v", caching), func(t *testing.T) {
|
||||
if !caching {
|
||||
t.Setenv(fakeEnvPrefix+"ENABLE_CACHING", "false")
|
||||
}
|
||||
for _, n := range sizes {
|
||||
f := newFakeFs(t, remote, fmt.Sprintf("n%d", n))
|
||||
srv.ResetRequests()
|
||||
_, err := f.List(ctx, "")
|
||||
require.NoError(t, err)
|
||||
cold := srv.Requests()
|
||||
assert.Empty(t, list(t, f, n), "warm listing")
|
||||
|
||||
srv.ResetRequests()
|
||||
entries, err := f.List(ctx, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, entries, n)
|
||||
warm := srv.Requests()
|
||||
if caching {
|
||||
assert.Empty(t, warm, "N=%d", n)
|
||||
} else {
|
||||
assert.Equal(t, cold, warm, "N=%d", n)
|
||||
assert.LessOrEqual(t, totalRequests(warm), childPages(n, budgetPageSize)+ceilDiv(n, 100), "N=%d: %v", n, warm)
|
||||
}
|
||||
if n == 100 || n == 101 {
|
||||
return
|
||||
}
|
||||
t.Setenv(fakeEnvPrefix+"ENABLE_CACHING", "false")
|
||||
uncached := newFakeFs(t, remote, root)
|
||||
assert.Equal(t, cold, list(t, uncached, n), "first listing without caching")
|
||||
assert.Equal(t, cold, list(t, uncached, n), "second listing without caching")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user