Skip to content

Commit 95d64ba

Browse files
authored
Fix flaky unit tests (#2364)
Problem: A couple unit tests were flaky due to the ordering of maps or lists that were being parsed. Solution: Eliminate the randomness of the results.
1 parent 21e0bad commit 95d64ba

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

internal/mode/static/state/dataplane/configuration_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3520,15 +3520,21 @@ func TestBuildStreamUpstreams(t *testing.T) {
35203520
}
35213521

35223522
fakeResolver := resolverfakes.FakeServiceResolver{}
3523-
fakeResolver.ResolveReturnsOnCall(0, nil, errors.New("error"))
35243523
fakeEndpoints := []resolver.Endpoint{
35253524
{Address: "1.1.1.1", Port: 80},
35263525
}
3527-
fakeResolver.ResolveReturnsOnCall(
3528-
1,
3529-
fakeEndpoints,
3530-
nil,
3531-
)
3526+
3527+
fakeResolver.ResolveStub = func(
3528+
_ context.Context,
3529+
nsName types.NamespacedName,
3530+
_ apiv1.ServicePort,
3531+
_ []discoveryV1.AddressType,
3532+
) ([]resolver.Endpoint, error) {
3533+
if nsName == secureAppKey.NamespacedName {
3534+
return nil, errors.New("error")
3535+
}
3536+
return fakeEndpoints, nil
3537+
}
35323538

35333539
streamUpstreams := buildStreamUpstreams(context.Background(), testGraph.Gateway.Listeners, &fakeResolver, Dual)
35343540

internal/mode/static/state/graph/policies_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
918918

919919
for _, pol := range processed {
920920
g.Expect(pol.Valid).To(Equal(test.valid))
921-
g.Expect(pol.Conditions).To(Equal(test.expConditions))
921+
g.Expect(pol.Conditions).To(ConsistOf(test.expConditions))
922922
}
923923
})
924924
}

0 commit comments

Comments
 (0)