From 32f75cd6077144893e71139e813293a8ceb4ef0d Mon Sep 17 00:00:00 2001 From: Tanner Stirrat Date: Wed, 27 Nov 2024 17:42:23 -0700 Subject: [PATCH] Add one more test for mixed valid/invalid --- .../schemacaching/standardcaching_test.go | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/internal/datastore/proxy/schemacaching/standardcaching_test.go b/internal/datastore/proxy/schemacaching/standardcaching_test.go index 66f60c1da8..2bc6e20ec1 100644 --- a/internal/datastore/proxy/schemacaching/standardcaching_test.go +++ b/internal/datastore/proxy/schemacaching/standardcaching_test.go @@ -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) @@ -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) +}