Skip to content

Commit

Permalink
UPSTREAM: <drop>: Revert "UPSTREAM: 98939: fixes race in TestSyncPods…
Browse files Browse the repository at this point in the history
…DeletesWhenSourcesAreReadyPerQOS"

This reverts commit b28c83b.
  • Loading branch information
soltysh committed May 25, 2021
1 parent 6857e95 commit 5b96666
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions pkg/kubelet/kubelet_test.go
Expand Up @@ -405,6 +405,8 @@ func TestSyncPodsStartPod(t *testing.T) {
}

func TestSyncPodsDeletesWhenSourcesAreReadyPerQOS(t *testing.T) {
ready := false // sources will not be ready initially, enabled later

testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
go testKubelet.kubelet.podKiller.PerformPodKillingWork()
defer testKubelet.Cleanup()
Expand All @@ -427,14 +429,19 @@ func TestSyncPodsDeletesWhenSourcesAreReadyPerQOS(t *testing.T) {
}
kubelet := testKubelet.kubelet
kubelet.cgroupsPerQOS = true // enable cgroupsPerQOS to turn on the cgroups cleanup
kubelet.sourcesReady = config.NewSourcesReady(func(_ sets.String) bool { return true })
kubelet.sourcesReady = config.NewSourcesReady(func(_ sets.String) bool { return ready })

// HandlePodCleanups gets called every 2 seconds within the Kubelet's
// housekeeping routine. This test registers the pod, removes the unwanted pod, then calls into
// HandlePodCleanups a few more times. We should only see one Destroy() event. podKiller runs
// within a goroutine so a two second delay should be enough time to
// mark the pod as killed (within this test case).

kubelet.HandlePodCleanups()
time.Sleep(2 * time.Second)
fakeRuntime.AssertKilledPods([]string{}) // Sources are not ready yet. Don't remove any pods.

ready = true // mark sources as ready
kubelet.HandlePodCleanups()
time.Sleep(2 * time.Second)

Expand All @@ -449,25 +456,18 @@ func TestSyncPodsDeletesWhenSourcesAreReadyPerQOS(t *testing.T) {
kubelet.HandlePodCleanups()
time.Sleep(2 * time.Second)

fakeContainerManager.PodContainerManager.Lock()
defer fakeContainerManager.PodContainerManager.Unlock()
calledFunctionCount := len(fakeContainerManager.PodContainerManager.CalledFunctions)
destroyCount := 0
err := wait.Poll(100*time.Millisecond, 10*time.Second, func() (bool, error) {
fakeContainerManager.PodContainerManager.Lock()
defer fakeContainerManager.PodContainerManager.Unlock()
destroyCount = 0
for _, functionName := range fakeContainerManager.PodContainerManager.CalledFunctions {
if functionName == "Destroy" {
destroyCount = destroyCount + 1
}
for _, functionName := range fakeContainerManager.PodContainerManager.CalledFunctions {
if functionName == "Destroy" {
destroyCount = destroyCount + 1
}
return destroyCount >= 1, nil
})
}

assert.NoError(t, err, "wait should not return error")
// housekeeping can get called multiple times. The cgroup Destroy() is
// done within a goroutine and can get called multiple times, so the
// Destroy() count in not deterministic on the actual number.
// https://github.com/kubernetes/kubernetes/blob/29fdbb065b5e0d195299eb2d260b975cbc554673/pkg/kubelet/kubelet_pods.go#L2006
assert.True(t, destroyCount >= 1, "Expect 1 or more destroys")
assert.Equal(t, 1, destroyCount, "Expect only 1 destroy")
assert.True(t, calledFunctionCount > 2, "expect more than two PodContainerManager calls")
}

func TestDispatchWorkOfCompletedPod(t *testing.T) {
Expand Down

0 comments on commit 5b96666

Please sign in to comment.