@@ -201,7 +201,6 @@ func TestGetListCacheBypass(t *testing.T) {
201
201
{opts : storage.ListOptions {ResourceVersion : "0" , Predicate : storage.SelectionPredicate {Continue : "a" }}, expectBypass : true },
202
202
{opts : storage.ListOptions {ResourceVersion : "1" , Predicate : storage.SelectionPredicate {Continue : "a" }}, expectBypass : true },
203
203
204
- {opts : storage.ListOptions {ResourceVersion : "" , Predicate : storage.SelectionPredicate {Limit : 500 }}, expectBypass : true },
205
204
{opts : storage.ListOptions {ResourceVersion : "0" , Predicate : storage.SelectionPredicate {Limit : 500 }}, expectBypass : false },
206
205
{opts : storage.ListOptions {ResourceVersion : "1" , Predicate : storage.SelectionPredicate {Limit : 500 }}, expectBypass : true },
207
206
@@ -214,6 +213,7 @@ func TestGetListCacheBypass(t *testing.T) {
214
213
featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .ConsistentListFromCache , false )
215
214
testCases := append (commonTestCases ,
216
215
testCase {opts : storage.ListOptions {ResourceVersion : "" }, expectBypass : true },
216
+ testCase {opts : storage.ListOptions {ResourceVersion : "" , Predicate : storage.SelectionPredicate {Limit : 500 }}, expectBypass : true },
217
217
)
218
218
for _ , tc := range testCases {
219
219
testGetListCacheBypass (t , tc .opts , tc .expectBypass )
@@ -233,6 +233,7 @@ func TestGetListCacheBypass(t *testing.T) {
233
233
234
234
testCases := append (commonTestCases ,
235
235
testCase {opts : storage.ListOptions {ResourceVersion : "" }, expectBypass : false },
236
+ testCase {opts : storage.ListOptions {ResourceVersion : "" , Predicate : storage.SelectionPredicate {Limit : 500 }}, expectBypass : false },
236
237
)
237
238
for _ , tc := range testCases {
238
239
testGetListCacheBypass (t , tc .opts , tc .expectBypass )
@@ -2591,6 +2592,63 @@ func TestWatchStreamSeparation(t *testing.T) {
2591
2592
}
2592
2593
}
2593
2594
2595
+ func TestComputeListLimit (t * testing.T ) {
2596
+ scenarios := []struct {
2597
+ name string
2598
+ opts storage.ListOptions
2599
+ expectedLimit int64
2600
+ }{
2601
+ {
2602
+ name : "limit is zero" ,
2603
+ opts : storage.ListOptions {
2604
+ Predicate : storage.SelectionPredicate {
2605
+ Limit : 0 ,
2606
+ },
2607
+ },
2608
+ expectedLimit : 0 ,
2609
+ },
2610
+ {
2611
+ name : "limit is positive, RV is unset" ,
2612
+ opts : storage.ListOptions {
2613
+ Predicate : storage.SelectionPredicate {
2614
+ Limit : 1 ,
2615
+ },
2616
+ ResourceVersion : "" ,
2617
+ },
2618
+ expectedLimit : 1 ,
2619
+ },
2620
+ {
2621
+ name : "limit is positive, RV = 100" ,
2622
+ opts : storage.ListOptions {
2623
+ Predicate : storage.SelectionPredicate {
2624
+ Limit : 1 ,
2625
+ },
2626
+ ResourceVersion : "100" ,
2627
+ },
2628
+ expectedLimit : 1 ,
2629
+ },
2630
+ {
2631
+ name : "legacy case: limit is positive, RV = 0" ,
2632
+ opts : storage.ListOptions {
2633
+ Predicate : storage.SelectionPredicate {
2634
+ Limit : 1 ,
2635
+ },
2636
+ ResourceVersion : "0" ,
2637
+ },
2638
+ expectedLimit : 0 ,
2639
+ },
2640
+ }
2641
+
2642
+ for _ , scenario := range scenarios {
2643
+ t .Run (scenario .name , func (t * testing.T ) {
2644
+ actualLimit := computeListLimit (scenario .opts )
2645
+ if actualLimit != scenario .expectedLimit {
2646
+ t .Errorf ("computeListLimit returned = %v, expected %v" , actualLimit , scenario .expectedLimit )
2647
+ }
2648
+ })
2649
+ }
2650
+ }
2651
+
2594
2652
func watchAndWaitForBookmark (t * testing.T , ctx context.Context , etcdStorage storage.Interface ) func () (resourceVersion uint64 ) {
2595
2653
opts := storage.ListOptions {ResourceVersion : "" , Predicate : storage .Everything , Recursive : true }
2596
2654
opts .Predicate .AllowWatchBookmarks = true
0 commit comments