diff --git a/content/local/store_test.go b/content/local/store_test.go index d5ca5a4b6..0882d2e66 100644 --- a/content/local/store_test.go +++ b/content/local/store_test.go @@ -72,12 +72,12 @@ func (mls *memoryLabelStore) Update(d digest.Digest, update map[string]string) ( } func TestContent(t *testing.T) { - testsuite.ContentSuite(t, "fs", func(ctx context.Context, root string) (content.Store, func() error, error) { + testsuite.ContentSuite(t, "fs", func(ctx context.Context, root string) (context.Context, content.Store, func() error, error) { cs, err := NewLabeledStore(root, newMemoryLabelStore()) if err != nil { - return nil, nil, err + return nil, nil, nil, err } - return cs, func() error { + return ctx, cs, func() error { return nil }, nil }) diff --git a/content/testsuite/testsuite.go b/content/testsuite/testsuite.go index d8236ab61..47759a736 100644 --- a/content/testsuite/testsuite.go +++ b/content/testsuite/testsuite.go @@ -22,7 +22,7 @@ import ( ) // ContentSuite runs a test suite on the content store given a factory function. -func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, root string) (content.Store, func() error, error)) { +func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, root string) (context.Context, content.Store, func() error, error)) { t.Run("Writer", makeTest(t, name, storeFn, checkContentStoreWriter)) t.Run("UploadStatus", makeTest(t, name, storeFn, checkUploadStatus)) t.Run("Resume", makeTest(t, name, storeFn, checkResumeWriter)) @@ -34,7 +34,7 @@ func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, r t.Run("Labels", makeTest(t, name, storeFn, checkLabels)) } -func makeTest(t *testing.T, name string, storeFn func(ctx context.Context, root string) (content.Store, func() error, error), fn func(ctx context.Context, t *testing.T, cs content.Store)) func(t *testing.T) { +func makeTest(t *testing.T, name string, storeFn func(ctx context.Context, root string) (context.Context, content.Store, func() error, error), fn func(ctx context.Context, t *testing.T, cs content.Store)) func(t *testing.T) { return func(t *testing.T) { ctx := namespaces.WithNamespace(context.Background(), name) @@ -44,7 +44,7 @@ func makeTest(t *testing.T, name string, storeFn func(ctx context.Context, root } defer os.RemoveAll(tmpDir) - cs, cleanup, err := storeFn(ctx, tmpDir) + ctx, cs, cleanup, err := storeFn(ctx, tmpDir) if err != nil { t.Fatal(err) } diff --git a/content_test.go b/content_test.go index 5bcfe908e..5e0c71fc8 100644 --- a/content_test.go +++ b/content_test.go @@ -10,15 +10,18 @@ import ( "github.com/pkg/errors" ) -func newContentStore(ctx context.Context, root string) (content.Store, func() error, error) { +func newContentStore(ctx context.Context, root string) (context.Context, content.Store, func() error, error) { client, err := New(address) if err != nil { - return nil, nil, err + return nil, nil, nil, err + } + ctx, releaselease, err := client.WithLease(ctx) + if err != nil { + return nil, nil, nil, err } - cs := client.ContentStore() - return cs, func() error { + return ctx, cs, func() error { statuses, err := cs.ListStatuses(ctx) if err != nil { return err @@ -28,6 +31,7 @@ func newContentStore(ctx context.Context, root string) (content.Store, func() er return errors.Wrapf(err, "failed to abort %s", st.Ref) } } + releaselease() return cs.Walk(ctx, func(info content.Info) error { if err := cs.Delete(ctx, info.Digest); err != nil { if errdefs.IsNotFound(err) { diff --git a/metadata/content_test.go b/metadata/content_test.go index ad212c28a..2dabe9fc0 100644 --- a/metadata/content_test.go +++ b/metadata/content_test.go @@ -17,19 +17,19 @@ import ( "github.com/pkg/errors" ) -func createContentStore(ctx context.Context, root string) (content.Store, func() error, error) { +func createContentStore(ctx context.Context, root string) (context.Context, content.Store, func() error, error) { // TODO: Use mocked or in-memory store cs, err := local.NewStore(root) if err != nil { - return nil, nil, err + return nil, nil, nil, err } db, err := bolt.Open(filepath.Join(root, "metadata.db"), 0660, nil) if err != nil { - return nil, nil, err + return nil, nil, nil, err } - return NewDB(db, cs, nil).ContentStore(), func() error { + return ctx, NewDB(db, cs, nil).ContentStore(), func() error { return db.Close() }, nil }