Skip to content

Commit

Permalink
Add one more test for mixed valid/invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
tstirrat15 committed Nov 28, 2024
1 parent b6bb793 commit 32f75cd
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion internal/datastore/proxy/schemacaching/standardcaching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func TestMixedCaching(t *testing.T) {

// NOTE: This uses a full memdb datastore because we want to exercise
// the cache behavior without mocking it.
func TestInvalidEntriesInCache(t *testing.T) {
func TestInvalidNamespaceInCache(t *testing.T) {
invalidNamespace := "invalid_namespace"

require := require.New(t)
Expand Down Expand Up @@ -547,3 +547,43 @@ func TestInvalidEntriesInCache(t *testing.T) {
require.Empty(found)
require.NoError(err)
}

func TestMixedInvalidNamespacesInCache(t *testing.T) {
invalidNamespace := "invalid_namespace"
validNamespace := "valid_namespace"

require := require.New(t)

ctx := context.Background()

memoryDatastore, err := memdb.NewMemdbDatastore(0, 1*time.Hour, 1*time.Hour)
require.NoError(err)
ds := NewCachingDatastoreProxy(memoryDatastore, DatastoreProxyTestCache(t), 1*time.Hour, JustInTimeCaching, 100*time.Millisecond)

require.NoError(err)

// Write in the valid namespace
revision, err := ds.ReadWriteTx(ctx, func(ctx context.Context, rwt datastore.ReadWriteTransaction) error {
writeErr := rwt.WriteNamespaces(ctx, &core.NamespaceDefinition{
Name: validNamespace,
})
return writeErr
})
require.NoError(err)

dsReader := ds.SnapshotReader(revision)

namespace, _, err := dsReader.ReadNamespaceByName(ctx, invalidNamespace)
require.Nil(namespace)
// NOTE: we're expecting this to error, because the namespace doesn't exist.
// However, the act of calling it sets the cache value to nil, which means that
// subsequent calls to the cache return that nil value. That's what needed to
// be filtered out of the list call.
require.Error(err)

// We're asserting that we find the thing we're looking for and don't receive a notfound value
found, err := dsReader.LookupNamespacesWithNames(ctx, []string{invalidNamespace, validNamespace})
require.Len(found, 1)
require.Equal(validNamespace, found[0].Definition.Name)
require.NoError(err)
}

0 comments on commit 32f75cd

Please sign in to comment.