Skip to content

Commit

Permalink
Fix flaky unit tests (nginxinc#2364)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sjberman authored Aug 12, 2024
1 parent 21e0bad commit 95d64ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions internal/mode/static/state/dataplane/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3520,15 +3520,21 @@ func TestBuildStreamUpstreams(t *testing.T) {
}

fakeResolver := resolverfakes.FakeServiceResolver{}
fakeResolver.ResolveReturnsOnCall(0, nil, errors.New("error"))
fakeEndpoints := []resolver.Endpoint{
{Address: "1.1.1.1", Port: 80},
}
fakeResolver.ResolveReturnsOnCall(
1,
fakeEndpoints,
nil,
)

fakeResolver.ResolveStub = func(
_ context.Context,
nsName types.NamespacedName,
_ apiv1.ServicePort,
_ []discoveryV1.AddressType,
) ([]resolver.Endpoint, error) {
if nsName == secureAppKey.NamespacedName {
return nil, errors.New("error")
}
return fakeEndpoints, nil
}

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

Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/state/graph/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {

for _, pol := range processed {
g.Expect(pol.Valid).To(Equal(test.valid))
g.Expect(pol.Conditions).To(Equal(test.expConditions))
g.Expect(pol.Conditions).To(ConsistOf(test.expConditions))
}
})
}
Expand Down

0 comments on commit 95d64ba

Please sign in to comment.