From 98626ba21fd5aed7b9ce4966f72c8fe566179950 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Tue, 2 Apr 2024 13:33:52 +0200 Subject: [PATCH] stores: fix TestSlabCleanup --- stores/metadata_test.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/stores/metadata_test.go b/stores/metadata_test.go index b92ced4b2..ebb5f0df1 100644 --- a/stores/metadata_test.go +++ b/stores/metadata_test.go @@ -4097,24 +4097,29 @@ func TestSlabCleanup(t *testing.T) { if err != nil { t.Fatal(err) } + time.Sleep(100 * time.Millisecond) // check slice count var slabCntr int64 - if err := ss.db.Model(&dbSlab{}).Count(&slabCntr).Error; err != nil { - t.Fatal(err) - } else if slabCntr != 1 { - t.Fatalf("expected 1 slabs, got %v", slabCntr) - } + ss.Retry(100, 100*time.Millisecond, func() error { + if err := ss.db.Model(&dbSlab{}).Count(&slabCntr).Error; err != nil { + return err + } else if slabCntr != 1 { + return fmt.Errorf("expected 1 slabs, got %v", slabCntr) + } + return nil + }) // delete second object err = ss.RemoveObject(context.Background(), api.DefaultBucketName, obj2.ObjectID) if err != nil { t.Fatal(err) } + time.Sleep(100 * time.Millisecond) ss.Retry(100, 100*time.Millisecond, func() error { if err := ss.db.Model(&dbSlab{}).Count(&slabCntr).Error; err != nil { - t.Fatal(err) + return err } else if slabCntr != 0 { return fmt.Errorf("expected 0 slabs, got %v", slabCntr) } @@ -4159,11 +4164,16 @@ func TestSlabCleanup(t *testing.T) { if err != nil { t.Fatal(err) } - if err := ss.db.Model(&dbSlab{}).Count(&slabCntr).Error; err != nil { - t.Fatal(err) - } else if slabCntr != 1 { - t.Fatalf("expected 1 slabs, got %v", slabCntr) - } + time.Sleep(100 * time.Millisecond) + + ss.Retry(100, 100*time.Millisecond, func() error { + if err := ss.db.Model(&dbSlab{}).Count(&slabCntr).Error; err != nil { + return err + } else if slabCntr != 1 { + return fmt.Errorf("expected 1 slabs, got %v", slabCntr) + } + return nil + }) } func TestUpsertSectors(t *testing.T) {