@@ -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 )
@@ -2566,6 +2567,63 @@ func TestWatchStreamSeparation(t *testing.T) {
2566
2567
}
2567
2568
}
2568
2569
2570
+ func TestComputeListLimit (t * testing.T ) {
2571
+ scenarios := []struct {
2572
+ name string
2573
+ opts storage.ListOptions
2574
+ expectedLimit int64
2575
+ }{
2576
+ {
2577
+ name : "limit is zero" ,
2578
+ opts : storage.ListOptions {
2579
+ Predicate : storage.SelectionPredicate {
2580
+ Limit : 0 ,
2581
+ },
2582
+ },
2583
+ expectedLimit : 0 ,
2584
+ },
2585
+ {
2586
+ name : "limit is positive, RV is unset" ,
2587
+ opts : storage.ListOptions {
2588
+ Predicate : storage.SelectionPredicate {
2589
+ Limit : 1 ,
2590
+ },
2591
+ ResourceVersion : "" ,
2592
+ },
2593
+ expectedLimit : 1 ,
2594
+ },
2595
+ {
2596
+ name : "limit is positive, RV = 100" ,
2597
+ opts : storage.ListOptions {
2598
+ Predicate : storage.SelectionPredicate {
2599
+ Limit : 1 ,
2600
+ },
2601
+ ResourceVersion : "100" ,
2602
+ },
2603
+ expectedLimit : 1 ,
2604
+ },
2605
+ {
2606
+ name : "legacy case: limit is positive, RV = 0" ,
2607
+ opts : storage.ListOptions {
2608
+ Predicate : storage.SelectionPredicate {
2609
+ Limit : 1 ,
2610
+ },
2611
+ ResourceVersion : "0" ,
2612
+ },
2613
+ expectedLimit : 0 ,
2614
+ },
2615
+ }
2616
+
2617
+ for _ , scenario := range scenarios {
2618
+ t .Run (scenario .name , func (t * testing.T ) {
2619
+ actualLimit := computeListLimit (scenario .opts )
2620
+ if actualLimit != scenario .expectedLimit {
2621
+ t .Errorf ("computeListLimit returned = %v, expected %v" , actualLimit , scenario .expectedLimit )
2622
+ }
2623
+ })
2624
+ }
2625
+ }
2626
+
2569
2627
func watchAndWaitForBookmark (t * testing.T , ctx context.Context , etcdStorage storage.Interface ) func () (resourceVersion uint64 ) {
2570
2628
opts := storage.ListOptions {ResourceVersion : "" , Predicate : storage .Everything , Recursive : true }
2571
2629
opts .Predicate .AllowWatchBookmarks = true
0 commit comments