mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #26555 from jsafrane/stabilize-test-flakes
Automatic merge from submit-queue Stabilize controller unit tests. Remove test "5-1", it's flaky as it depends on order of execution of goroutines. When the controller starts, existing claim is enqueued as "initial sync event" and a new volume is enqueued to separate goroutine. It is not deterministic which goroutine processes its events first and there is no way how to tell that the claim event was processed. Also, force resync of the controllers after the test to make sure all events are processed. Fixes unit test flakes. @kubernetes/sig-storage
This commit is contained in:
commit
38d5be4f36
@ -34,31 +34,13 @@ import (
|
||||
// can't reliably simulate periodic sync of volumes/claims - it would be
|
||||
// either very timing-sensitive or slow to wait for real periodic sync.
|
||||
func TestControllerSync(t *testing.T) {
|
||||
expectedChanges := []int{1, 4, 1, 1}
|
||||
expectedChanges := []int{4, 1, 1}
|
||||
tests := []controllerTest{
|
||||
// [Unit test set 5] - controller tests.
|
||||
// We test the controller as if
|
||||
// it was connected to real API server, i.e. we call add/update/delete
|
||||
// Claim/Volume methods. Also, all changes to volumes and claims are
|
||||
// sent to add/update/delete Claim/Volume as real controller would do.
|
||||
{
|
||||
// addVolume gets a new volume. Check it's marked as Available and
|
||||
// that it's not bound to any claim - we bind volumes on periodic
|
||||
// syncClaim, not on addVolume.
|
||||
"5-1 - addVolume",
|
||||
novolumes, /* added in testCall below */
|
||||
newVolumeArray("volume5-1", "10Gi", "", "", api.VolumeAvailable, api.PersistentVolumeReclaimRetain),
|
||||
newClaimArray("claim5-1", "uid5-1", "1Gi", "", api.ClaimPending),
|
||||
newClaimArray("claim5-1", "uid5-1", "1Gi", "", api.ClaimPending),
|
||||
noevents, noerrors,
|
||||
// Custom test function that generates an add event
|
||||
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
|
||||
volume := newVolume("volume5-1", "10Gi", "", "", api.VolumePending, api.PersistentVolumeReclaimRetain)
|
||||
reactor.volumes[volume.Name] = volume
|
||||
reactor.volumeSource.Add(volume)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
// addClaim gets a new claim. Check it's bound to a volume.
|
||||
"5-2 - complete bind",
|
||||
@ -157,6 +139,10 @@ func TestControllerSync(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Test %q initial test call failed: %v", test.name, err)
|
||||
}
|
||||
// Simulate a periodic resync, just in case some events arrived in a
|
||||
// wrong order.
|
||||
ctrl.claims.Resync()
|
||||
ctrl.volumes.store.Resync()
|
||||
|
||||
for reactor.getChangeCount() < count+expectedChanges[ix] {
|
||||
reactor.waitTest()
|
||||
|
Loading…
Reference in New Issue
Block a user