@@ -1596,45 +1596,62 @@ func RunTestConsistentList(ctx context.Context, t *testing.T, store storage.Inte
1596
1596
inPod := & example.Pod {ObjectMeta : metav1.ObjectMeta {Namespace : "default" , Name : "foo" }}
1597
1597
err := store .Create (ctx , computePodKey (inPod ), inPod , outPod , 0 )
1598
1598
require .NoError (t , err )
1599
- writeRV , err := strconv .Atoi (outPod .ResourceVersion )
1599
+ lastResourceWriteRV , err := strconv .Atoi (outPod .ResourceVersion )
1600
1600
require .NoError (t , err )
1601
1601
1602
1602
increaseRV (ctx , t )
1603
- consistentRV := writeRV + 1
1603
+ consistentRV := lastResourceWriteRV + 1
1604
+ cacheSyncRV := 0
1604
1605
1605
1606
tcs := []struct {
1606
1607
name string
1607
1608
requestRV string
1609
+ continueToken string
1608
1610
validateResponseRV func (* testing.T , int )
1609
1611
}{
1610
1612
{
1611
- name : "Non-consistent list before sync " ,
1613
+ name : "Non-consistent list before consistent read " ,
1612
1614
requestRV : "0" ,
1613
1615
validateResponseRV : func (t * testing.T , rv int ) {
1614
1616
if cacheEnabled {
1615
1617
// Cache might not yet observed write
1616
- assert .LessOrEqual (t , rv , writeRV )
1618
+ assert .LessOrEqual (t , rv , lastResourceWriteRV )
1617
1619
} else {
1618
1620
// Etcd should always be up to date with consistent RV
1619
1621
assert .Equal (t , consistentRV , rv )
1620
1622
}
1621
1623
},
1622
1624
},
1623
1625
{
1624
- name : "Consistent request returns currentRV " ,
1626
+ name : "LIST without RV returns consistent RV " ,
1625
1627
requestRV : "" ,
1626
1628
validateResponseRV : func (t * testing.T , rv int ) {
1627
1629
assert .Equal (t , consistentRV , rv )
1630
+ cacheSyncRV = rv
1628
1631
},
1629
1632
},
1630
1633
{
1631
- name : "Non-consistent request after sync" ,
1634
+ name : "List with negative continue RV returns consistent RV" ,
1635
+ continueToken : encodeContinueOrDie ("/pods/a" , - 1 ),
1636
+ validateResponseRV : func (t * testing.T , rv int ) {
1637
+ // TODO: Update cacheSyncRV after continue is served from cache.
1638
+ assert .Equal (t , consistentRV , rv )
1639
+ },
1640
+ },
1641
+ {
1642
+ name : "Non-consistent request after consistent read" ,
1632
1643
requestRV : "0" ,
1633
1644
validateResponseRV : func (t * testing.T , rv int ) {
1634
- // Consistent read is required to sync cache
1635
- if cacheEnabled && ! consistentReadsSupported {
1636
- assert .LessOrEqual (t , rv , writeRV )
1645
+ if cacheEnabled {
1646
+ if consistentReadsSupported {
1647
+ // Consistent read will sync cache
1648
+ assert .Equal (t , cacheSyncRV , rv )
1649
+ } else {
1650
+ // Without consisten reads cache is not synced
1651
+ assert .LessOrEqual (t , rv , lastResourceWriteRV )
1652
+ }
1637
1653
} else {
1654
+ // Etcd always points to newest RV
1638
1655
assert .Equal (t , consistentRV , rv )
1639
1656
}
1640
1657
},
@@ -1645,7 +1662,11 @@ func RunTestConsistentList(ctx context.Context, t *testing.T, store storage.Inte
1645
1662
out := & example.PodList {}
1646
1663
opts := storage.ListOptions {
1647
1664
ResourceVersion : tc .requestRV ,
1648
- Predicate : storage .Everything ,
1665
+ Predicate : storage.SelectionPredicate {
1666
+ Label : labels .Everything (),
1667
+ Field : fields .Everything (),
1668
+ Continue : tc .continueToken ,
1669
+ },
1649
1670
}
1650
1671
err = store .GetList (ctx , "/pods/empty" , opts , out )
1651
1672
require .NoError (t , err )
@@ -1654,6 +1675,9 @@ func RunTestConsistentList(ctx context.Context, t *testing.T, store storage.Inte
1654
1675
require .NoError (t , err )
1655
1676
tc .validateResponseRV (t , parsedOutRV )
1656
1677
})
1678
+ // Update RV on each read to test multiple reads for consistent RV.
1679
+ increaseRV (ctx , t )
1680
+ consistentRV ++
1657
1681
}
1658
1682
}
1659
1683
0 commit comments