mirror of https://github.com/k3s-io/k3s
kubelet_test: Add verifyUnorderedCalls().
This fixes TestSyncPodsDeletesWithNoPodInfraContainer. Since we need to sync two pods in parallel, we should not verify the docker calls in strict order.pull/6/head
parent
1cad0df268
commit
aa2e7fe688
|
@ -19,6 +19,7 @@ package dockertools
|
|||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -66,6 +67,23 @@ func (f *FakeDockerClient) AssertCalls(calls []string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (f *FakeDockerClient) AssertUnorderedCalls(calls []string) (err error) {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
|
||||
var actual, expected []string
|
||||
copy(actual, calls)
|
||||
copy(expected, f.called)
|
||||
|
||||
sort.StringSlice(actual).Sort()
|
||||
sort.StringSlice(expected).Sort()
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
err = fmt.Errorf("expected(sorted) %#v, got(sorted) %#v", expected, actual)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ListContainers is a test-spy implementation of DockerInterface.ListContainers.
|
||||
// It adds an entry "list" to the internal method call record.
|
||||
func (f *FakeDockerClient) ListContainers(options docker.ListContainersOptions) ([]docker.APIContainers, error) {
|
||||
|
|
|
@ -121,6 +121,13 @@ func verifyCalls(t *testing.T, fakeDocker *dockertools.FakeDockerClient, calls [
|
|||
}
|
||||
}
|
||||
|
||||
func verifyUnorderedCalls(t *testing.T, fakeDocker *dockertools.FakeDockerClient, calls []string) {
|
||||
err := fakeDocker.AssertUnorderedCalls(calls)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func verifyStringArrayEquals(t *testing.T, actual, expected []string) {
|
||||
invalid := len(actual) != len(expected)
|
||||
if !invalid {
|
||||
|
@ -819,7 +826,7 @@ func TestSyncPodsDeletesWithNoPodInfraContainer(t *testing.T) {
|
|||
}
|
||||
waitGroup.Wait()
|
||||
|
||||
verifyCalls(t, fakeDocker, []string{
|
||||
verifyUnorderedCalls(t, fakeDocker, []string{
|
||||
"list", "list", "list", "list", "inspect_container", "inspect_container", "list", "inspect_container", "inspect_container", "stop", "create", "start", "inspect_container", "create", "start", "list", "inspect_container", "inspect_container"})
|
||||
|
||||
// A map iteration is used to delete containers, so must not depend on
|
||||
|
|
Loading…
Reference in New Issue