Skip to content

Commit

Permalink
refactor(tests): use MockUDPUpstreamServer.WithDelay where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Dec 1, 2023
1 parent 8ad83d0 commit adb970a
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions resolver/strict_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,9 @@ var _ = Describe("StrictResolver", Label("strictResolver"), func() {
})
When("first upstream times-out", func() {
BeforeEach(func() {
testUpstream1 = NewMockUDPUpstreamServer().WithAnswerFn(func(request *dns.Msg) (response *dns.Msg) {
response, err := util.NewMsgWithAnswer("example.com", 123, A, "123.124.122.1")
time.Sleep(2 * timeout)

Expect(err).To(Succeed())

return response
})
testUpstream1 = NewMockUDPUpstreamServer().
WithAnswerRR("example.com 123 IN A 123.124.122.1").
WithDelay(2 * timeout)

testUpstream2 := NewMockUDPUpstreamServer().WithAnswerRR("example.com 123 IN A 123.124.122.2")

Expand All @@ -192,23 +187,13 @@ var _ = Describe("StrictResolver", Label("strictResolver"), func() {
})
When("all upstreams timeout", func() {
JustBeforeEach(func() {
testUpstream1 = NewMockUDPUpstreamServer().WithAnswerFn(func(request *dns.Msg) (response *dns.Msg) {
response, err := util.NewMsgWithAnswer("example.com", 123, A, "123.124.122.1")
time.Sleep(2 * timeout)

Expect(err).To(Succeed())

return response
})

testUpstream2 = NewMockUDPUpstreamServer().WithAnswerFn(func(request *dns.Msg) (response *dns.Msg) {
response, err := util.NewMsgWithAnswer("example.com", 123, A, "123.124.122.2")
time.Sleep(2 * timeout)

Expect(err).To(Succeed())
testUpstream1 = NewMockUDPUpstreamServer().
WithAnswerRR("example.com 123 IN A 123.124.122.1").
WithDelay(2 * timeout)

return response
})
testUpstream2 = NewMockUDPUpstreamServer().
WithAnswerRR("example.com 123 IN A 123.124.122.2").
WithDelay(2 * timeout)

upstreams = []config.Upstream{testUpstream1.Start(), testUpstream2.Start()}
})
Expand Down

0 comments on commit adb970a

Please sign in to comment.