Skip to content

Commit

Permalink
fix(scheduler): test for deleted resources that are recreated (#5993)
Browse files Browse the repository at this point in the history
* adding a test for resources that have been recreated after they have been deleted

* add a comment
  • Loading branch information
driev authored Oct 25, 2024
1 parent f446185 commit 9ac44d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions scheduler/pkg/store/experiment/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package experiment
import (
"fmt"
"testing"
"time"

"github.com/dgraph-io/badger/v3"
"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -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())

Expand All @@ -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())
}
Expand Down
14 changes: 12 additions & 2 deletions scheduler/pkg/store/pipeline/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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())
}
Expand Down

0 comments on commit 9ac44d3

Please sign in to comment.