From c62025c8365126537964df0ac536756400063bbd Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 5 May 2023 17:02:27 +0300 Subject: [PATCH] [#321] metabase/test: execute tests in parallel Signed-off-by: Evgenii Stratonikov --- .../metabase/containers_test.go | 6 +++ .../metabase/counter_test.go | 49 ++++++++++--------- .../metabase/generic_test.go | 2 + .../metabase/list_test.go | 4 ++ .../metabase/lock_test.go | 6 +++ .../metabase/select_test.go | 18 +++++++ .../metabase/storage_id_test.go | 2 + 7 files changed, 65 insertions(+), 22 deletions(-) diff --git a/pkg/local_object_storage/metabase/containers_test.go b/pkg/local_object_storage/metabase/containers_test.go index a0be2c743..c0565b35a 100644 --- a/pkg/local_object_storage/metabase/containers_test.go +++ b/pkg/local_object_storage/metabase/containers_test.go @@ -15,6 +15,8 @@ import ( ) func TestDB_Containers(t *testing.T) { + t.Parallel() + db := newDB(t) const N = 10 @@ -90,6 +92,8 @@ func TestDB_Containers(t *testing.T) { } func TestDB_ContainersCount(t *testing.T) { + t.Parallel() + db := newDB(t) const R, T, SG, L = 10, 11, 12, 13 // amount of object per type @@ -133,6 +137,8 @@ func TestDB_ContainersCount(t *testing.T) { } func TestDB_ContainerSize(t *testing.T) { + t.Parallel() + db := newDB(t) const ( diff --git a/pkg/local_object_storage/metabase/counter_test.go b/pkg/local_object_storage/metabase/counter_test.go index 17a593b6d..507bfcd89 100644 --- a/pkg/local_object_storage/metabase/counter_test.go +++ b/pkg/local_object_storage/metabase/counter_test.go @@ -2,6 +2,7 @@ package meta_test import ( "context" + "os" "testing" objectcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" @@ -16,19 +17,23 @@ import ( const objCount = 10 func TestCounters(t *testing.T) { - db := newDB(t) - - var c meta.ObjectCounters - var err error + t.Parallel() + t.Cleanup(func() { + require.NoError(t, os.RemoveAll(t.Name())) + }) t.Run("defaults", func(t *testing.T) { - c, err = db.ObjectCounters() + t.Parallel() + db := newDB(t) + c, err := db.ObjectCounters() require.NoError(t, err) require.Zero(t, c.Phy()) require.Zero(t, c.Logic()) }) t.Run("put", func(t *testing.T) { + t.Parallel() + db := newDB(t) oo := make([]*object.Object, 0, objCount) for i := 0; i < objCount; i++ { oo = append(oo, testutil.GenerateObject()) @@ -39,10 +44,10 @@ func TestCounters(t *testing.T) { for i := 0; i < objCount; i++ { prm.SetObject(oo[i]) - _, err = db.Put(context.Background(), prm) + _, err := db.Put(context.Background(), prm) require.NoError(t, err) - c, err = db.ObjectCounters() + c, err := db.ObjectCounters() require.NoError(t, err) require.Equal(t, uint64(i+1), c.Phy()) @@ -50,9 +55,9 @@ func TestCounters(t *testing.T) { } }) - require.NoError(t, db.Reset()) - t.Run("delete", func(t *testing.T) { + t.Parallel() + db := newDB(t) oo := putObjs(t, db, objCount, false) var prm meta.DeletePrm @@ -63,7 +68,7 @@ func TestCounters(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(1), res.AvailableObjectsRemoved()) - c, err = db.ObjectCounters() + c, err := db.ObjectCounters() require.NoError(t, err) require.Equal(t, uint64(i), c.Phy()) @@ -71,9 +76,9 @@ func TestCounters(t *testing.T) { } }) - require.NoError(t, db.Reset()) - t.Run("inhume", func(t *testing.T) { + t.Parallel() + db := newDB(t) oo := putObjs(t, db, objCount, false) inhumedObjs := make([]oid.Address, objCount/2) @@ -94,16 +99,16 @@ func TestCounters(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(len(inhumedObjs)), res.AvailableInhumed()) - c, err = db.ObjectCounters() + c, err := db.ObjectCounters() require.NoError(t, err) require.Equal(t, uint64(objCount), c.Phy()) require.Equal(t, uint64(objCount-len(inhumedObjs)), c.Logic()) }) - require.NoError(t, db.Reset()) - t.Run("put_split", func(t *testing.T) { + t.Parallel() + db := newDB(t) parObj := testutil.GenerateObject() // put objects and check that parent info @@ -116,16 +121,16 @@ func TestCounters(t *testing.T) { require.NoError(t, putBig(db, o)) - c, err = db.ObjectCounters() + c, err := db.ObjectCounters() require.NoError(t, err) require.Equal(t, uint64(i+1), c.Phy()) require.Equal(t, uint64(i+1), c.Logic()) } }) - require.NoError(t, db.Reset()) - t.Run("delete_split", func(t *testing.T) { + t.Parallel() + db := newDB(t) oo := putObjs(t, db, objCount, true) // delete objects that have parent info @@ -141,9 +146,9 @@ func TestCounters(t *testing.T) { } }) - require.NoError(t, db.Reset()) - t.Run("inhume_split", func(t *testing.T) { + t.Parallel() + db := newDB(t) oo := putObjs(t, db, objCount, true) inhumedObjs := make([]oid.Address, objCount/2) @@ -160,10 +165,10 @@ func TestCounters(t *testing.T) { prm.SetTombstoneAddress(oidtest.Address()) prm.SetAddresses(inhumedObjs...) - _, err = db.Inhume(context.Background(), prm) + _, err := db.Inhume(context.Background(), prm) require.NoError(t, err) - c, err = db.ObjectCounters() + c, err := db.ObjectCounters() require.NoError(t, err) require.Equal(t, uint64(objCount), c.Phy()) diff --git a/pkg/local_object_storage/metabase/generic_test.go b/pkg/local_object_storage/metabase/generic_test.go index 227aa9f8d..9d15b6f7a 100644 --- a/pkg/local_object_storage/metabase/generic_test.go +++ b/pkg/local_object_storage/metabase/generic_test.go @@ -10,6 +10,8 @@ import ( ) func TestGeneric(t *testing.T) { + t.Parallel() + defer func() { _ = os.RemoveAll(t.Name()) }() var n int diff --git a/pkg/local_object_storage/metabase/list_test.go b/pkg/local_object_storage/metabase/list_test.go index 07a0d80f8..4bf3ca827 100644 --- a/pkg/local_object_storage/metabase/list_test.go +++ b/pkg/local_object_storage/metabase/list_test.go @@ -66,6 +66,8 @@ func benchmarkListWithCursor(b *testing.B, db *meta.DB, batchSize int) { } func TestLisObjectsWithCursor(t *testing.T) { + t.Parallel() + db := newDB(t) const ( @@ -159,6 +161,8 @@ func TestLisObjectsWithCursor(t *testing.T) { } func TestAddObjectDuringListingWithCursor(t *testing.T) { + t.Parallel() + db := newDB(t) const total = 5 diff --git a/pkg/local_object_storage/metabase/lock_test.go b/pkg/local_object_storage/metabase/lock_test.go index 7b62841dc..d5e063431 100644 --- a/pkg/local_object_storage/metabase/lock_test.go +++ b/pkg/local_object_storage/metabase/lock_test.go @@ -17,6 +17,8 @@ import ( ) func TestDB_Lock(t *testing.T) { + t.Parallel() + cnr := cidtest.ID() db := newDB(t) @@ -171,6 +173,8 @@ func TestDB_Lock(t *testing.T) { } func TestDB_Lock_Expired(t *testing.T) { + t.Parallel() + es := &epochState{e: 123} db := newDB(t, meta.WithEpochState(es)) @@ -192,6 +196,8 @@ func TestDB_Lock_Expired(t *testing.T) { } func TestDB_IsLocked(t *testing.T) { + t.Parallel() + db := newDB(t) // existing and locked objs diff --git a/pkg/local_object_storage/metabase/select_test.go b/pkg/local_object_storage/metabase/select_test.go index dab4c028d..e107085ab 100644 --- a/pkg/local_object_storage/metabase/select_test.go +++ b/pkg/local_object_storage/metabase/select_test.go @@ -20,6 +20,8 @@ import ( ) func TestDB_SelectUserAttributes(t *testing.T) { + t.Parallel() + db := newDB(t) cnr := cidtest.ID() @@ -142,6 +144,8 @@ func TestDB_SelectUserAttributes(t *testing.T) { } func TestDB_SelectRootPhyParent(t *testing.T) { + t.Parallel() + db := newDB(t) cnr := cidtest.ID() @@ -293,6 +297,8 @@ func TestDB_SelectRootPhyParent(t *testing.T) { } func TestDB_SelectInhume(t *testing.T) { + t.Parallel() + db := newDB(t) cnr := cidtest.ID() @@ -325,6 +331,8 @@ func TestDB_SelectInhume(t *testing.T) { } func TestDB_SelectPayloadHash(t *testing.T) { + t.Parallel() + db := newDB(t) cnr := cidtest.ID() @@ -393,6 +401,8 @@ func TestDB_SelectPayloadHash(t *testing.T) { } func TestDB_SelectWithSlowFilters(t *testing.T) { + t.Parallel() + db := newDB(t) cnr := cidtest.ID() @@ -498,6 +508,8 @@ func TestDB_SelectWithSlowFilters(t *testing.T) { } func TestDB_SelectObjectID(t *testing.T) { + t.Parallel() + db := newDB(t) cnr := cidtest.ID() @@ -611,6 +623,8 @@ func TestDB_SelectObjectID(t *testing.T) { } func TestDB_SelectSplitID(t *testing.T) { + t.Parallel() + db := newDB(t) cnr := cidtest.ID() @@ -665,6 +679,8 @@ func TestDB_SelectSplitID(t *testing.T) { } func TestDB_SelectContainerID(t *testing.T) { + t.Parallel() + db := newDB(t) cnr := cidtest.ID() @@ -750,6 +766,8 @@ func BenchmarkSelect(b *testing.B) { } func TestExpiredObjects(t *testing.T) { + t.Parallel() + db := newDB(t, meta.WithEpochState(epochState{currEpoch})) checkExpiredObjects(t, db, func(exp, nonExp *objectSDK.Object) { diff --git a/pkg/local_object_storage/metabase/storage_id_test.go b/pkg/local_object_storage/metabase/storage_id_test.go index 5b27cdc87..b3652a680 100644 --- a/pkg/local_object_storage/metabase/storage_id_test.go +++ b/pkg/local_object_storage/metabase/storage_id_test.go @@ -12,6 +12,8 @@ import ( ) func TestDB_StorageID(t *testing.T) { + t.Parallel() + db := newDB(t) raw1 := testutil.GenerateObject()