Merge pull request #718 from vmware-tanzu/workaround_for_flaky_unit_test
TestAgentController unit test is flaky, try to add workaround
This commit is contained in:
commit
be7bf9c193
@ -214,6 +214,7 @@ func TestAgentController(t *testing.T) {
|
|||||||
addKubeReactions func(*kubefake.Clientset)
|
addKubeReactions func(*kubefake.Clientset)
|
||||||
mocks func(*testing.T, *mocks.MockPodCommandExecutorMockRecorder, *mocks.MockDynamicCertPrivateMockRecorder, *cache.Expiring)
|
mocks func(*testing.T, *mocks.MockPodCommandExecutorMockRecorder, *mocks.MockDynamicCertPrivateMockRecorder, *cache.Expiring)
|
||||||
wantDistinctErrors []string
|
wantDistinctErrors []string
|
||||||
|
alsoAllowUndesiredDistinctErrors []string
|
||||||
wantDistinctLogs []string
|
wantDistinctLogs []string
|
||||||
wantAgentDeployment *appsv1.Deployment
|
wantAgentDeployment *appsv1.Deployment
|
||||||
wantStrategy *configv1alpha1.CredentialIssuerStrategy
|
wantStrategy *configv1alpha1.CredentialIssuerStrategy
|
||||||
@ -351,6 +352,10 @@ func TestAgentController(t *testing.T) {
|
|||||||
wantDistinctErrors: []string{
|
wantDistinctErrors: []string{
|
||||||
"could not find a healthy agent pod (1 candidate)",
|
"could not find a healthy agent pod (1 candidate)",
|
||||||
},
|
},
|
||||||
|
alsoAllowUndesiredDistinctErrors: []string{
|
||||||
|
// due to the high amount of nondeterminism in this test, this error will sometimes also happen, but is not required to happen
|
||||||
|
`could not ensure agent deployment: deployments.apps "pinniped-concierge-kube-cert-agent" already exists`,
|
||||||
|
},
|
||||||
wantDistinctLogs: []string{
|
wantDistinctLogs: []string{
|
||||||
`kube-cert-agent-controller "level"=0 "msg"="creating new deployment" "deployment"={"name":"pinniped-concierge-kube-cert-agent","namespace":"concierge"} "templatePod"={"name":"kube-controller-manager-1","namespace":"kube-system"}`,
|
`kube-cert-agent-controller "level"=0 "msg"="creating new deployment" "deployment"={"name":"pinniped-concierge-kube-cert-agent","namespace":"concierge"} "templatePod"={"name":"kube-controller-manager-1","namespace":"kube-system"}`,
|
||||||
},
|
},
|
||||||
@ -395,6 +400,10 @@ func TestAgentController(t *testing.T) {
|
|||||||
wantDistinctErrors: []string{
|
wantDistinctErrors: []string{
|
||||||
"could not find a healthy agent pod (1 candidate)",
|
"could not find a healthy agent pod (1 candidate)",
|
||||||
},
|
},
|
||||||
|
alsoAllowUndesiredDistinctErrors: []string{
|
||||||
|
// due to the high amount of nondeterminism in this test, this error will sometimes also happen, but is not required to happen
|
||||||
|
`could not ensure agent deployment: deployments.apps "pinniped-concierge-kube-cert-agent" already exists`,
|
||||||
|
},
|
||||||
wantDistinctLogs: []string{
|
wantDistinctLogs: []string{
|
||||||
`kube-cert-agent-controller "level"=0 "msg"="creating new deployment" "deployment"={"name":"pinniped-concierge-kube-cert-agent","namespace":"concierge"} "templatePod"={"name":"kube-controller-manager-1","namespace":"kube-system"}`,
|
`kube-cert-agent-controller "level"=0 "msg"="creating new deployment" "deployment"={"name":"pinniped-concierge-kube-cert-agent","namespace":"concierge"} "templatePod"={"name":"kube-controller-manager-1","namespace":"kube-system"}`,
|
||||||
},
|
},
|
||||||
@ -756,7 +765,14 @@ func TestAgentController(t *testing.T) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
errorMessages := runControllerUntilQuiet(ctx, t, controller, kubeInformers, conciergeInformers)
|
errorMessages := runControllerUntilQuiet(ctx, t, controller, kubeInformers, conciergeInformers)
|
||||||
assert.Equal(t, tt.wantDistinctErrors, deduplicate(errorMessages), "unexpected errors")
|
|
||||||
|
actualErrors := deduplicate(errorMessages)
|
||||||
|
require.Subsetf(t, actualErrors, tt.wantDistinctErrors, "required error(s) were not found in the actual errors")
|
||||||
|
|
||||||
|
allAllowedErrors := append([]string{}, tt.wantDistinctErrors...)
|
||||||
|
allAllowedErrors = append(allAllowedErrors, tt.alsoAllowUndesiredDistinctErrors...)
|
||||||
|
require.Subsetf(t, allAllowedErrors, actualErrors, "actual errors contained additional error(s) which is not expected by the test")
|
||||||
|
|
||||||
assert.Equal(t, tt.wantDistinctLogs, deduplicate(log.Lines()), "unexpected logs")
|
assert.Equal(t, tt.wantDistinctLogs, deduplicate(log.Lines()), "unexpected logs")
|
||||||
|
|
||||||
// Assert that the agent deployment is in the expected final state.
|
// Assert that the agent deployment is in the expected final state.
|
||||||
|
Loading…
Reference in New Issue
Block a user