aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2021-07-14 10:36:25 +0200
committerGravatar GitHub <noreply@github.com> 2021-07-14 10:36:25 +0200
commit39ab8402638201551bd13b54c312ffd2fe12c596 (patch)
treeaf9bf4b50eba863428ea268ae65b64e74a2c4f7e /test
parent21f1207afee6915c14e1109834e3fc0dfed9f420 (diff)
downloadcoredns-39ab8402638201551bd13b54c312ffd2fe12c596.tar.gz
coredns-39ab8402638201551bd13b54c312ffd2fe12c596.tar.zst
coredns-39ab8402638201551bd13b54c312ffd2fe12c596.zip
deflake TestMultiZoneBlockConfigs (#4751)
Deflake by retrying and adding random port numbers. We try 3 times to get an instance. Also fix a bug where server.Stop() was called even if the server creation failed - this was never hit due to t.Fatal() above it, but fix that nontheless. Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'test')
-rw-r--r--test/server_test.go30
1 files changed, 25 insertions, 5 deletions
diff --git a/test/server_test.go b/test/server_test.go
index 54e44722d..6fe147253 100644
--- a/test/server_test.go
+++ b/test/server_test.go
@@ -1,10 +1,13 @@
package test
import (
+ "fmt"
+ "math/rand"
"reflect"
"testing"
"unsafe"
+ "github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/miekg/dns"
@@ -113,16 +116,33 @@ func TestReverseExpansion(t *testing.T) {
}
func TestMultiZoneBlockConfigs(t *testing.T) {
- corefile := `.:40000 .:40001 .:40002 {
+ // We need fixed port numbers here to have multiple serving instances, using ".:0" wont work because that
+ // leads to a 'duplicate server instances' because '0' is used literary (only the kernel knows what port will
+ // be assigned).
+ //
+ // This makes the test flaky because we don't know if there are in-use or not. We add a random number to each base and
+ // retry when we fail to get a serving instance (up to 3 times).
+
+ var (
+ server *caddy.Instance
+ err error
+ )
+ for j := 0; j < 3; j++ {
+ corefile := `.:%d .:%d .:%d {
debug
}`
+ corefile = fmt.Sprintf(corefile, 40000+rand.Intn(9000), 50000+rand.Intn(9000), 60000+rand.Intn(9000))
- server, err := CoreDNSServer(corefile)
- defer server.Stop()
-
- if err != nil {
+ if server, err = CoreDNSServer(corefile); err != nil {
+ continue
+ }
+ t.Logf("Got running CoreDNS serving instance, after %d tries", j+1)
+ break // success
+ }
+ if server == nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
+ defer server.Stop()
// unsafe reflection to read unexported fields "context" and "configs" within context
ctxVal := reflect.ValueOf(server).Elem().FieldByName("context")