mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Fix flakey TestGetSetPods
This commit is contained in:
		@@ -21,7 +21,6 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
						"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
				
			||||||
	kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Stub out mirror client for testing purpose.
 | 
					// Stub out mirror client for testing purpose.
 | 
				
			||||||
@@ -69,26 +68,36 @@ func TestGetSetPods(t *testing.T) {
 | 
				
			|||||||
	updates := append(expectedPods, mirrorPod)
 | 
						updates := append(expectedPods, mirrorPod)
 | 
				
			||||||
	podManager, _ := newFakePodManager()
 | 
						podManager, _ := newFakePodManager()
 | 
				
			||||||
	podManager.SetPods(updates)
 | 
						podManager.SetPods(updates)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Tests that all regular pods are recorded corrrectly.
 | 
				
			||||||
	actualPods := podManager.GetPods()
 | 
						actualPods := podManager.GetPods()
 | 
				
			||||||
	if !reflect.DeepEqual(expectedPods, actualPods) {
 | 
						if len(actualPods) != len(expectedPods) {
 | 
				
			||||||
		t.Errorf("pods are not set correctly; expected %#v, got %#v", expectedPods, actualPods)
 | 
							t.Errorf("expected %d pods, got %d pods; expected pods %#v, got pods %#v", len(expectedPods), len(actualPods),
 | 
				
			||||||
 | 
								expectedPods, actualPods)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	actualPod, ok := podManager.mirrorPodByUID[mirrorPod.UID]
 | 
						for _, expected := range expectedPods {
 | 
				
			||||||
	if !ok {
 | 
							found := false
 | 
				
			||||||
		t.Errorf("mirror pod %q is not found in the mirror pod map by UID", mirrorPod.UID)
 | 
							for _, actual := range actualPods {
 | 
				
			||||||
	} else if !reflect.DeepEqual(&mirrorPod, actualPod) {
 | 
								if actual.UID == expected.UID {
 | 
				
			||||||
		t.Errorf("mirror pod is recorded incorrectly. expect: %v, got: %v", mirrorPod, actualPod)
 | 
									if !reflect.DeepEqual(&expected, &actual) {
 | 
				
			||||||
	}
 | 
										t.Errorf("pod was recorded incorrectly. expect: %#v, got: %#v", expected, actual)
 | 
				
			||||||
	actualPod, ok = podManager.mirrorPodByFullName[kubecontainer.GetPodFullName(&mirrorPod)]
 | 
									}
 | 
				
			||||||
	if !ok {
 | 
									found = true
 | 
				
			||||||
		t.Errorf("mirror pod %q is not found in the mirror pod map by full name", kubecontainer.GetPodFullName(&mirrorPod))
 | 
									break
 | 
				
			||||||
	} else if !reflect.DeepEqual(&mirrorPod, actualPod) {
 | 
								}
 | 
				
			||||||
		t.Errorf("mirror pod is recorded incorrectly. expect: %v, got: %v", mirrorPod, actualPod)
 | 
							}
 | 
				
			||||||
 | 
							if !found {
 | 
				
			||||||
 | 
								t.Errorf("pod %q was not found in %#v", expected.UID, actualPods)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// Tests UID translation works as expected.
 | 
				
			||||||
	if uid := podManager.TranslatePodUID(mirrorPod.UID); uid != staticPod.UID {
 | 
						if uid := podManager.TranslatePodUID(mirrorPod.UID); uid != staticPod.UID {
 | 
				
			||||||
		t.Errorf("unable to translate UID %q to the static POD's UID %q; %#v", mirrorPod.UID, staticPod.UID, podManager.mirrorPodByUID)
 | 
							t.Errorf("unable to translate UID %q to the static POD's UID %q; %#v",
 | 
				
			||||||
 | 
								mirrorPod.UID, staticPod.UID, podManager.mirrorPodByUID)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	actualPod, ok = podManager.GetPodByFullName("bar_default")
 | 
					
 | 
				
			||||||
 | 
						// Test the basic Get methods.
 | 
				
			||||||
 | 
						actualPod, ok := podManager.GetPodByFullName("bar_default")
 | 
				
			||||||
	if !ok || !reflect.DeepEqual(actualPod, &staticPod) {
 | 
						if !ok || !reflect.DeepEqual(actualPod, &staticPod) {
 | 
				
			||||||
		t.Errorf("unable to get pod by full name; expected: %#v, got: %#v", staticPod, actualPod)
 | 
							t.Errorf("unable to get pod by full name; expected: %#v, got: %#v", staticPod, actualPod)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user