@@ -1631,7 +1631,9 @@ func RunTestListContinuation(ctx context.Context, t *testing.T, store storage.In
1631
1631
}
1632
1632
}
1633
1633
options := storage.ListOptions {
1634
- ResourceVersion : "0" ,
1634
+ // Limit is ignored when ResourceVersion is set to 0.
1635
+ // Set it to consistent read.
1636
+ ResourceVersion : "" ,
1635
1637
Predicate : pred (1 , "" ),
1636
1638
Recursive : true ,
1637
1639
}
@@ -1654,7 +1656,8 @@ func RunTestListContinuation(ctx context.Context, t *testing.T, store storage.In
1654
1656
// no limit, should get two items
1655
1657
out = & example.PodList {}
1656
1658
options = storage.ListOptions {
1657
- ResourceVersion : "0" ,
1659
+ // ResourceVersion should be unset when setting continuation token.
1660
+ ResourceVersion : "" ,
1658
1661
Predicate : pred (0 , continueFromSecondItem ),
1659
1662
Recursive : true ,
1660
1663
}
@@ -1677,7 +1680,8 @@ func RunTestListContinuation(ctx context.Context, t *testing.T, store storage.In
1677
1680
// limit, should get two more pages
1678
1681
out = & example.PodList {}
1679
1682
options = storage.ListOptions {
1680
- ResourceVersion : "0" ,
1683
+ // ResourceVersion should be unset when setting continuation token.
1684
+ ResourceVersion : "" ,
1681
1685
Predicate : pred (1 , continueFromSecondItem ),
1682
1686
Recursive : true ,
1683
1687
}
@@ -1699,7 +1703,8 @@ func RunTestListContinuation(ctx context.Context, t *testing.T, store storage.In
1699
1703
1700
1704
out = & example.PodList {}
1701
1705
options = storage.ListOptions {
1702
- ResourceVersion : "0" ,
1706
+ // ResourceVersion should be unset when setting continuation token.
1707
+ ResourceVersion : "" ,
1703
1708
Predicate : pred (1 , continueFromThirdItem ),
1704
1709
Recursive : true ,
1705
1710
}
@@ -1815,7 +1820,9 @@ func RunTestListContinuationWithFilter(ctx context.Context, t *testing.T, store
1815
1820
}
1816
1821
}
1817
1822
options := storage.ListOptions {
1818
- ResourceVersion : "0" ,
1823
+ // Limit is ignored when ResourceVersion is set to 0.
1824
+ // Set it to consistent read.
1825
+ ResourceVersion : "" ,
1819
1826
Predicate : pred (2 , "" ),
1820
1827
Recursive : true ,
1821
1828
}
@@ -1845,7 +1852,8 @@ func RunTestListContinuationWithFilter(ctx context.Context, t *testing.T, store
1845
1852
// both read counters should be incremented for the singular calls they make in this case
1846
1853
out = & example.PodList {}
1847
1854
options = storage.ListOptions {
1848
- ResourceVersion : "0" ,
1855
+ // ResourceVersion should be unset when setting continuation token.
1856
+ ResourceVersion : "" ,
1849
1857
Predicate : pred (2 , cont ),
1850
1858
Recursive : true ,
1851
1859
}
@@ -2407,7 +2415,7 @@ func RunTestGuaranteedUpdateWithSuggestionAndConflict(ctx context.Context, t *te
2407
2415
err := store .GuaranteedUpdate (ctx , key , updatedPod , false , nil ,
2408
2416
storage .SimpleUpdate (func (obj runtime.Object ) (runtime.Object , error ) {
2409
2417
pod := obj .(* example.Pod )
2410
- pod .Name = "foo-2"
2418
+ pod .Generation = 2
2411
2419
return pod , nil
2412
2420
}),
2413
2421
nil ,
@@ -2424,24 +2432,24 @@ func RunTestGuaranteedUpdateWithSuggestionAndConflict(ctx context.Context, t *te
2424
2432
err = store .GuaranteedUpdate (ctx , key , updatedPod2 , false , nil ,
2425
2433
storage .SimpleUpdate (func (obj runtime.Object ) (runtime.Object , error ) {
2426
2434
pod := obj .(* example.Pod )
2427
- if pod .Name != "foo-2" {
2435
+ if pod .Generation != 2 {
2428
2436
if sawConflict {
2429
2437
t .Fatalf ("unexpected second conflict" )
2430
2438
}
2431
2439
sawConflict = true
2432
2440
// simulated stale object - return a conflict
2433
2441
return nil , apierrors .NewConflict (example .SchemeGroupVersion .WithResource ("pods" ).GroupResource (), "name" , errors .New ("foo" ))
2434
2442
}
2435
- pod .Name = "foo-3"
2443
+ pod .Generation = 3
2436
2444
return pod , nil
2437
2445
}),
2438
2446
originalPod ,
2439
2447
)
2440
2448
if err != nil {
2441
2449
t .Fatalf ("unexpected error: %v" , err )
2442
2450
}
2443
- if updatedPod2 .Name != "foo-3" {
2444
- t .Errorf ("unexpected pod name : %q" , updatedPod2 .Name )
2451
+ if updatedPod2 .Generation != 3 {
2452
+ t .Errorf ("unexpected pod generation : %q" , updatedPod2 .Generation )
2445
2453
}
2446
2454
2447
2455
// Third, update using a current version as the suggestion.
@@ -2452,14 +2460,8 @@ func RunTestGuaranteedUpdateWithSuggestionAndConflict(ctx context.Context, t *te
2452
2460
err = store .GuaranteedUpdate (ctx , key , updatedPod3 , false , nil ,
2453
2461
storage .SimpleUpdate (func (obj runtime.Object ) (runtime.Object , error ) {
2454
2462
pod := obj .(* example.Pod )
2455
- if pod .Name != updatedPod2 .Name || pod .ResourceVersion != updatedPod2 .ResourceVersion {
2456
- t .Errorf (
2457
- "unexpected live object (name=%s, rv=%s), expected name=%s, rv=%s" ,
2458
- pod .Name ,
2459
- pod .ResourceVersion ,
2460
- updatedPod2 .Name ,
2461
- updatedPod2 .ResourceVersion ,
2462
- )
2463
+ if pod .Generation != updatedPod2 .Generation || pod .ResourceVersion != updatedPod2 .ResourceVersion {
2464
+ t .Logf ("stale object (rv=%s), expected rv=%s" , pod .ResourceVersion , updatedPod2 .ResourceVersion )
2463
2465
}
2464
2466
attempts ++
2465
2467
return nil , fmt .Errorf ("validation or admission error" )
@@ -2469,8 +2471,10 @@ func RunTestGuaranteedUpdateWithSuggestionAndConflict(ctx context.Context, t *te
2469
2471
if err == nil {
2470
2472
t .Fatalf ("expected error, got none" )
2471
2473
}
2472
- if attempts != 1 {
2473
- t .Errorf ("expected 1 attempt, got %d" , attempts )
2474
+ // Implementations of the storage interface are allowed to ignore the suggestion,
2475
+ // in which case two attempts are possible.
2476
+ if attempts > 2 {
2477
+ t .Errorf ("update function should have been called at most twice, called %d" , attempts )
2474
2478
}
2475
2479
}
2476
2480
0 commit comments