mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 14:14:39 +00:00
Merge pull request #130863 from serathius/watchcache-negative-RV-consistent
Extend tests for negative RV with consistent reads
This commit is contained in:
@@ -1663,24 +1663,26 @@ func RunTestConsistentList(ctx context.Context, t *testing.T, store storage.Inte
|
|||||||
inPod := &example.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "foo"}}
|
inPod := &example.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "foo"}}
|
||||||
err := store.Create(ctx, computePodKey(inPod), inPod, outPod, 0)
|
err := store.Create(ctx, computePodKey(inPod), inPod, outPod, 0)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
writeRV, err := strconv.Atoi(outPod.ResourceVersion)
|
lastResourceWriteRV, err := strconv.Atoi(outPod.ResourceVersion)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
increaseRV(ctx, t)
|
increaseRV(ctx, t)
|
||||||
consistentRV := writeRV + 1
|
consistentRV := lastResourceWriteRV + 1
|
||||||
|
cacheSyncRV := 0
|
||||||
|
|
||||||
tcs := []struct {
|
tcs := []struct {
|
||||||
name string
|
name string
|
||||||
requestRV string
|
requestRV string
|
||||||
|
continueToken string
|
||||||
validateResponseRV func(*testing.T, int)
|
validateResponseRV func(*testing.T, int)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Non-consistent list before sync",
|
name: "Non-consistent list before consistent read",
|
||||||
requestRV: "0",
|
requestRV: "0",
|
||||||
validateResponseRV: func(t *testing.T, rv int) {
|
validateResponseRV: func(t *testing.T, rv int) {
|
||||||
if cacheEnabled {
|
if cacheEnabled {
|
||||||
// Cache might not yet observed write
|
// Cache might not yet observed write
|
||||||
assert.LessOrEqual(t, rv, writeRV)
|
assert.LessOrEqual(t, rv, lastResourceWriteRV)
|
||||||
} else {
|
} else {
|
||||||
// Etcd should always be up to date with consistent RV
|
// Etcd should always be up to date with consistent RV
|
||||||
assert.Equal(t, consistentRV, rv)
|
assert.Equal(t, consistentRV, rv)
|
||||||
@@ -1688,20 +1690,35 @@ func RunTestConsistentList(ctx context.Context, t *testing.T, store storage.Inte
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Consistent request returns currentRV",
|
name: "LIST without RV returns consistent RV",
|
||||||
requestRV: "",
|
requestRV: "",
|
||||||
validateResponseRV: func(t *testing.T, rv int) {
|
validateResponseRV: func(t *testing.T, rv int) {
|
||||||
assert.Equal(t, consistentRV, rv)
|
assert.Equal(t, consistentRV, rv)
|
||||||
|
cacheSyncRV = rv
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "List with negative continue RV returns consistent RV",
|
||||||
|
continueToken: encodeContinueOrDie("/pods/a", -1),
|
||||||
|
validateResponseRV: func(t *testing.T, rv int) {
|
||||||
|
// TODO: Update cacheSyncRV after continue is served from cache.
|
||||||
|
assert.Equal(t, consistentRV, rv)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Non-consistent request after sync",
|
name: "Non-consistent request after consistent read",
|
||||||
requestRV: "0",
|
requestRV: "0",
|
||||||
validateResponseRV: func(t *testing.T, rv int) {
|
validateResponseRV: func(t *testing.T, rv int) {
|
||||||
// Consistent read is required to sync cache
|
if cacheEnabled {
|
||||||
if cacheEnabled && !consistentReadsSupported {
|
if consistentReadsSupported {
|
||||||
assert.LessOrEqual(t, rv, writeRV)
|
// Consistent read will sync cache
|
||||||
|
assert.Equal(t, cacheSyncRV, rv)
|
||||||
|
} else {
|
||||||
|
// Without consisten reads cache is not synced
|
||||||
|
assert.LessOrEqual(t, rv, lastResourceWriteRV)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Etcd always points to newest RV
|
||||||
assert.Equal(t, consistentRV, rv)
|
assert.Equal(t, consistentRV, rv)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1712,7 +1729,11 @@ func RunTestConsistentList(ctx context.Context, t *testing.T, store storage.Inte
|
|||||||
out := &example.PodList{}
|
out := &example.PodList{}
|
||||||
opts := storage.ListOptions{
|
opts := storage.ListOptions{
|
||||||
ResourceVersion: tc.requestRV,
|
ResourceVersion: tc.requestRV,
|
||||||
Predicate: storage.Everything,
|
Predicate: storage.SelectionPredicate{
|
||||||
|
Label: labels.Everything(),
|
||||||
|
Field: fields.Everything(),
|
||||||
|
Continue: tc.continueToken,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
err = store.GetList(ctx, "/pods/empty", opts, out)
|
err = store.GetList(ctx, "/pods/empty", opts, out)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -1721,6 +1742,9 @@ func RunTestConsistentList(ctx context.Context, t *testing.T, store storage.Inte
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tc.validateResponseRV(t, parsedOutRV)
|
tc.validateResponseRV(t, parsedOutRV)
|
||||||
})
|
})
|
||||||
|
// Update RV on each read to test multiple reads for consistent RV.
|
||||||
|
increaseRV(ctx, t)
|
||||||
|
consistentRV++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user