lease: count every store call in the generation start tests
countingStore embedded VersionedStore, so OpenVersion (a streamed GET) bypassed the counter and the zero-other-requests budget checks could not see it. It now holds the store in a named field and writes out all six interface methods, OpenVersion counted as other; a compile-time assertion means a method added to VersionedStore breaks the build instead of passing through uncounted. Verified by injecting an OpenVersion call into CopyStart: both budget tests fail, then pass with the injection removed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+21
−8
internal/lease/genstart_test.go+21 −8
CI failed — run details
Intent
diff --git a/internal/lease/genstart_test.go b/internal/lease/genstart_test.go| index f7e003697..3066394da 100644 |
| --- a/internal/lease/genstart_test.go |
| +++ b/internal/lease/genstart_test.go |
| @@ -4,6 +4,7 @@ import ( |
| "context" |
| "errors" |
| "fmt" |
| + "io" |
| "net/http" |
| "net/http/httptest" |
| "net/url" |
| @@ -43,9 +44,14 @@ func genHead(gen string) lease.Head { |
| } |
| // countingStore counts every request a VersionedStore makes, can rewrite |
| -// listed sizes, and can intercept copies. |
| +// listed sizes, and can intercept copies. It wraps the store in a named |
| +// field, not an embedded one, so every interface method is written out |
| +// here and counted: a method added to VersionedStore breaks this build |
| +// instead of passing through uncounted. It implements no optional |
| +// interface (VersionRangeOpener, FilePutIfAbsent), so a caller probing |
| +// for one falls back to a counted method. |
| type countingStore struct { |
| - lease.VersionedStore |
| + vs lease.VersionedStore |
| mu sync.Mutex |
| lists int |
| copies int |
| @@ -56,13 +62,15 @@ type countingStore struct { |
| onCopy func(ctx context.Context, key string, inFlight int) error // runs before the copy; an error fails it |
| } |
| -func newCounting(vs lease.VersionedStore) *countingStore { return &countingStore{VersionedStore: vs} } |
| +func newCounting(vs lease.VersionedStore) *countingStore { return &countingStore{vs: vs} } |
| + |
| +var _ lease.VersionedStore = (*countingStore)(nil) |
| func (c *countingStore) ListVersions(ctx context.Context, bucket, prefix string) ([]lease.ObjectVersion, error) { |
| c.mu.Lock() |
| c.lists++ |
| c.mu.Unlock() |
| - vs, err := c.VersionedStore.ListVersions(ctx, bucket, prefix) |
| + vs, err := c.vs.ListVersions(ctx, bucket, prefix) |
| for i := range vs { |
| if s, ok := c.sizes[vs[i].Key]; ok { |
| vs[i].Size = s |
| @@ -90,7 +98,7 @@ func (c *countingStore) CopyVersion(ctx context.Context, srcBucket, srcKey, srcV |
| return "", "", err |
| } |
| } |
| - return c.VersionedStore.CopyVersion(ctx, srcBucket, srcKey, srcVersionID, dstBucket, dstKey, createOnly) |
| + return c.vs.CopyVersion(ctx, srcBucket, srcKey, srcVersionID, dstBucket, dstKey, createOnly) |
| } |
| func (c *countingStore) count(p *int) { |
| @@ -99,19 +107,24 @@ func (c *countingStore) count(p *int) { |
| c.mu.Unlock() |
| } |
| +func (c *countingStore) OpenVersion(ctx context.Context, bucket, key, versionID string) (io.ReadCloser, error) { |
| + c.count(&c.other) |
| + return c.vs.OpenVersion(ctx, bucket, key, versionID) |
| +} |
| + |
| func (c *countingStore) GetVersion(ctx context.Context, bucket, key, versionID string) ([]byte, error) { |
| c.count(&c.other) |
| - return c.VersionedStore.GetVersion(ctx, bucket, key, versionID) |
| + return c.vs.GetVersion(ctx, bucket, key, versionID) |
| } |
| func (c *countingStore) DeleteVersion(ctx context.Context, bucket, key, versionID string) error { |
| c.count(&c.other) |
| - return c.VersionedStore.DeleteVersion(ctx, bucket, key, versionID) |
| + return c.vs.DeleteVersion(ctx, bucket, key, versionID) |
| } |
| func (c *countingStore) PutIfAbsent(ctx context.Context, bucket, key string, body []byte) (string, error) { |
| c.count(&c.other) |
| - return c.VersionedStore.PutIfAbsent(ctx, bucket, key, body) |
| + return c.vs.PutIfAbsent(ctx, bucket, key, body) |
| } |
| func (c *countingStore) snapshot() (lists, copies, other int) { |