@@ -1663,45 +1663,62 @@ func RunTestConsistentList(ctx context.Context, t *testing.T, store storage.Inte
1663
1663
inPod := & example.Pod {ObjectMeta : metav1.ObjectMeta {Namespace : "default" , Name : "foo" }}
1664
1664
err := store .Create (ctx , computePodKey (inPod ), inPod , outPod , 0 )
1665
1665
require .NoError (t , err )
1666
- writeRV , err := strconv .Atoi (outPod .ResourceVersion )
1666
+ lastResourceWriteRV , err := strconv .Atoi (outPod .ResourceVersion )
1667
1667
require .NoError (t , err )
1668
1668
1669
1669
increaseRV (ctx , t )
1670
- consistentRV := writeRV + 1
1670
+ consistentRV := lastResourceWriteRV + 1
1671
+ cacheSyncRV := 0
1671
1672
1672
1673
tcs := []struct {
1673
1674
name string
1674
1675
requestRV string
1676
+ continueToken string
1675
1677
validateResponseRV func (* testing.T , int )
1676
1678
}{
1677
1679
{
1678
- name : "Non-consistent list before sync " ,
1680
+ name : "Non-consistent list before consistent read " ,
1679
1681
requestRV : "0" ,
1680
1682
validateResponseRV : func (t * testing.T , rv int ) {
1681
1683
if cacheEnabled {
1682
1684
// Cache might not yet observed write
1683
- assert .LessOrEqual (t , rv , writeRV )
1685
+ assert .LessOrEqual (t , rv , lastResourceWriteRV )
1684
1686
} else {
1685
1687
// Etcd should always be up to date with consistent RV
1686
1688
assert .Equal (t , consistentRV , rv )
1687
1689
}
1688
1690
},
1689
1691
},
1690
1692
{
1691
- name : "Consistent request returns currentRV " ,
1693
+ name : "LIST without RV returns consistent RV " ,
1692
1694
requestRV : "" ,
1693
1695
validateResponseRV : func (t * testing.T , rv int ) {
1694
1696
assert .Equal (t , consistentRV , rv )
1697
+ cacheSyncRV = rv
1695
1698
},
1696
1699
},
1697
1700
{
1698
- name : "Non-consistent request after sync" ,
1701
+ name : "List with negative continue RV returns consistent RV" ,
1702
+ continueToken : encodeContinueOrDie ("/pods/a" , - 1 ),
1703
+ validateResponseRV : func (t * testing.T , rv int ) {
1704
+ // TODO: Update cacheSyncRV after continue is served from cache.
1705
+ assert .Equal (t , consistentRV , rv )
1706
+ },
1707
+ },
1708
+ {
1709
+ name : "Non-consistent request after consistent read" ,
1699
1710
requestRV : "0" ,
1700
1711
validateResponseRV : func (t * testing.T , rv int ) {
1701
- // Consistent read is required to sync cache
1702
- if cacheEnabled && ! consistentReadsSupported {
1703
- assert .LessOrEqual (t , rv , writeRV )
1712
+ if cacheEnabled {
1713
+ if consistentReadsSupported {
1714
+ // Consistent read will sync cache
1715
+ assert .Equal (t , cacheSyncRV , rv )
1716
+ } else {
1717
+ // Without consisten reads cache is not synced
1718
+ assert .LessOrEqual (t , rv , lastResourceWriteRV )
1719
+ }
1704
1720
} else {
1721
+ // Etcd always points to newest RV
1705
1722
assert .Equal (t , consistentRV , rv )
1706
1723
}
1707
1724
},
@@ -1712,7 +1729,11 @@ func RunTestConsistentList(ctx context.Context, t *testing.T, store storage.Inte
1712
1729
out := & example.PodList {}
1713
1730
opts := storage.ListOptions {
1714
1731
ResourceVersion : tc .requestRV ,
1715
- Predicate : storage .Everything ,
1732
+ Predicate : storage.SelectionPredicate {
1733
+ Label : labels .Everything (),
1734
+ Field : fields .Everything (),
1735
+ Continue : tc .continueToken ,
1736
+ },
1716
1737
}
1717
1738
err = store .GetList (ctx , "/pods/empty" , opts , out )
1718
1739
require .NoError (t , err )
@@ -1721,6 +1742,9 @@ func RunTestConsistentList(ctx context.Context, t *testing.T, store storage.Inte
1721
1742
require .NoError (t , err )
1722
1743
tc .validateResponseRV (t , parsedOutRV )
1723
1744
})
1745
+ // Update RV on each read to test multiple reads for consistent RV.
1746
+ increaseRV (ctx , t )
1747
+ consistentRV ++
1724
1748
}
1725
1749
}
1726
1750
0 commit comments