Unified Storage: Removes check for name ordering and adds test (#110183)
removes check for name ordering. Adds test to assert expected name and rv ordering.
This commit is contained in:
@@ -709,13 +709,6 @@ func (b *backend) ListModifiedSince(ctx context.Context, key resource.Namespaced
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if mr.Key.Name <= lastSeen {
|
|
||||||
// resource names should be sorted alphabetically. So if not, the query is not correct.
|
|
||||||
if !yield(nil, fmt.Errorf("listModifiedSince: resources are not sorted by name ASC, lastSeen: %q, current: %q", lastSeen, mr.Key.Name)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastSeen = mr.Key.Name
|
lastSeen = mr.Key.Name
|
||||||
|
|
||||||
if !yield(mr, nil) {
|
if !yield(mr, nil) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/go-jose/go-jose/v3/jwt"
|
"github.com/go-jose/go-jose/v3/jwt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -553,6 +554,39 @@ func runTestIntegrationBackendListModifiedSince(t *testing.T, backend resource.S
|
|||||||
}
|
}
|
||||||
require.Equal(t, 1, counter) // only one event should be returned
|
require.Equal(t, 1, counter) // only one event should be returned
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("will order events by resource version ascending and name descending", func(t *testing.T) {
|
||||||
|
// When we order by name ASC, sqlite orders upper case strings first - so skipping for sqlite
|
||||||
|
// For example: for this test, the actual ordering of events for sqlite is CItem, aItem, bItem
|
||||||
|
if db.IsTestDbSQLite() {
|
||||||
|
t.Skip("Skipping test for sqlite since ordering by name is different than mysql due to case sensitivity")
|
||||||
|
}
|
||||||
|
|
||||||
|
key := resource.NamespacedResource{
|
||||||
|
Namespace: ns,
|
||||||
|
Group: "group",
|
||||||
|
Resource: "resource",
|
||||||
|
}
|
||||||
|
|
||||||
|
rvCreated1, _ := writeEvent(ctx, backend, "aItem", resourcepb.WatchEvent_ADDED, WithNamespace(ns))
|
||||||
|
rvCreated2, _ := writeEvent(ctx, backend, "bItem", resourcepb.WatchEvent_ADDED, WithNamespace(ns))
|
||||||
|
rvCreated3, _ := writeEvent(ctx, backend, "CItem", resourcepb.WatchEvent_ADDED, WithNamespace(ns))
|
||||||
|
|
||||||
|
latestRv, seq := backend.ListModifiedSince(ctx, key, rvCreated1-1)
|
||||||
|
require.Greater(t, latestRv, rvCreated3)
|
||||||
|
|
||||||
|
counter := 0
|
||||||
|
names := []string{"aItem", "bItem", "CItem"}
|
||||||
|
rvs := []int64{rvCreated1, rvCreated2, rvCreated3}
|
||||||
|
for res, err := range seq {
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, key.Namespace, res.Key.Namespace)
|
||||||
|
require.Equal(t, names[counter], res.Key.Name)
|
||||||
|
require.Equal(t, rvs[counter], res.ResourceVersion)
|
||||||
|
counter++
|
||||||
|
}
|
||||||
|
require.Equal(t, 3, counter)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTestIntegrationBackendListHistory(t *testing.T, backend resource.StorageBackend, nsPrefix string) {
|
func runTestIntegrationBackendListHistory(t *testing.T, backend resource.StorageBackend, nsPrefix string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user