Skip to content

Commit

Permalink
chore: add tests for observable proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneorth committed Mar 6, 2024
1 parent c152814 commit ccb3d0b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/datastore/memdb/memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
numAttempts = 10
)

var errSerialization = errors.New("serialization error")
var ErrSerialization = errors.New("serialization error")

// DisableGC is a convenient constant for setting the garbage collection
// interval high enough that it will never run.
Expand Down Expand Up @@ -154,7 +154,7 @@ func (mdb *memdbDatastore) ReadWriteTx(
defer mdb.Unlock()

if mdb.activeWriteTxn != nil {
err = errSerialization
err = ErrSerialization
return
}

Expand All @@ -181,7 +181,7 @@ func (mdb *memdbDatastore) ReadWriteTx(
}

// If the error was a serialization error, retry the transaction
if errors.Is(err, errSerialization) {
if errors.Is(err, ErrSerialization) {
mdb.Unlock()

// If we don't sleep here, we run out of retries instantaneously
Expand Down
28 changes: 28 additions & 0 deletions internal/datastore/proxy/observable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package proxy

import (
"testing"
"time"

"github.com/authzed/spicedb/internal/datastore/memdb"
"github.com/authzed/spicedb/pkg/datastore"
"github.com/authzed/spicedb/pkg/datastore/test"
)

type observableTest struct{}

func (obs observableTest) New(revisionQuantization, _, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
db, err := memdb.NewMemdbDatastore(watchBufferLength, revisionQuantization, gcWindow)
if err != nil {
return nil, err
}
return NewObservableDatastoreProxy(db), nil
}

func TestObservableProxy(t *testing.T) {
test.All(t, observableTest{})
}

func (p *observableProxy) ExampleRetryableError() error {
return memdb.ErrSerialization
}

0 comments on commit ccb3d0b

Please sign in to comment.