Debian Codegraph @

cmd/reflect/reflect_test.go

raw
1 package main
2
3 import (
4 "context"
5 "fmt"
6 "log"
7 "os"
8 "os/exec"
9 "strings"
10 "testing"
11 "time"
12
13 "codeberg.org/miekg/dns/internal/dnsperf"
14 )
15
16 // TestReflect tests reflect's performance.
17 func TestReflect(t *testing.T) {
18 const count = 8
19 ports := [2]string{"8053", "8054"}
20 for p, network := range []string{"udp", "tcp"} {
21 t.Run("reflect-"+network, func(t *testing.T) {
22 timeout := count*2*time.Second + 5*time.Second // run reflect for longer than the test.
23 ctx, cancel := context.WithTimeout(context.Background(), timeout)
24
25 if _, err := os.Stat("./reflect"); err != nil {
26 t.Skip("no reflect binary found in .")
27 }
28
29 cmd := exec.CommandContext(ctx, "./reflect", "-port", ports[p])
30 go func() {
31 if err := cmd.Run(); err != nil {
32 if _, ok := err.(*exec.ExitError); !ok {
33 log.Fatal("no working reflect binary found in .")
34 }
35 }
36 }()
37
38 queries := strings.NewReader("whoami.miek.nl. A")
39 if err := dnsperf.Run(t, queries, fmt.Sprintf("127.0.0.1:%s", ports[p]), network, 2*time.Second, count); err != nil {
40 t.Fatal(err)
41 }
42 cancel()
43 t.Logf("canceled executing: %s", network)
44 time.Sleep(1 * time.Second)
45 })
46 }
47 }