From 9ac44d330c29408108240a0b963eb7f23ccaf452 Mon Sep 17 00:00:00 2001 From: Niall D <4562759+driev@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:34:21 +0100 Subject: [PATCH] fix(scheduler): test for deleted resources that are recreated (#5993) * adding a test for resources that have been recreated after they have been deleted * add a comment --- scheduler/pkg/store/experiment/db_test.go | 14 ++++++++++++-- scheduler/pkg/store/pipeline/db_test.go | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/scheduler/pkg/store/experiment/db_test.go b/scheduler/pkg/store/experiment/db_test.go index a184ac0505..4356a9a753 100644 --- a/scheduler/pkg/store/experiment/db_test.go +++ b/scheduler/pkg/store/experiment/db_test.go @@ -12,7 +12,6 @@ package experiment import ( "fmt" "testing" - "time" "github.com/dgraph-io/badger/v3" "github.com/google/go-cmp/cmp" @@ -105,7 +104,6 @@ func TestSaveWithTTL(t *testing.T) { logger := log.New() db, err := newExperimentDbManager(getExperimentDbFolder(path), logger) g.Expect(err).To(BeNil()) - experiment.DeletedAt = time.Now() err = db.save(experiment) g.Expect(err).To(BeNil()) @@ -117,6 +115,18 @@ func TestSaveWithTTL(t *testing.T) { g.Expect(err).To(BeNil()) g.Expect(item.ExpiresAt()).ToNot(BeZero()) + // check that the resource can be "undeleted" + experiment.Deleted = false + err = db.save(experiment) + g.Expect(err).To(BeNil()) + + err = db.db.View(func(txn *badger.Txn) error { + item, err = txn.Get(([]byte(experiment.Name))) + return err + }) + g.Expect(err).To(BeNil()) + g.Expect(item.ExpiresAt()).To(BeZero()) + err = db.Stop() g.Expect(err).To(BeNil()) } diff --git a/scheduler/pkg/store/pipeline/db_test.go b/scheduler/pkg/store/pipeline/db_test.go index 12d01680fd..f3e87375f6 100644 --- a/scheduler/pkg/store/pipeline/db_test.go +++ b/scheduler/pkg/store/pipeline/db_test.go @@ -50,8 +50,6 @@ func TestSaveWithTTL(t *testing.T) { }, Deleted: true, } - ttl := time.Duration(time.Second) - pipeline.DeletedAt = time.Now().Add(-utils.DeletedResourceTTL).Add(ttl) path := fmt.Sprintf("%s/db", t.TempDir()) logger := log.New() @@ -68,6 +66,18 @@ func TestSaveWithTTL(t *testing.T) { g.Expect(err).To(BeNil()) g.Expect(item.ExpiresAt()).ToNot(BeZero()) + // check that the resource can be "undeleted" + pipeline.Deleted = false + err = db.save(pipeline) + g.Expect(err).To(BeNil()) + + err = db.db.View(func(txn *badger.Txn) error { + item, err = txn.Get(([]byte(pipeline.Name))) + return err + }) + g.Expect(err).To(BeNil()) + g.Expect(item.ExpiresAt()).To(BeZero()) + err = db.Stop() g.Expect(err).To(BeNil()) }