Debian Codegraph @

internal/dnsperf/dnsperf_test.go

raw
1 package dnsperf
2
3 import (
4 "runtime"
5 "strings"
6 "testing"
7 )
8
9 const in = `DNS Performance Testing Tool
10 Version 2.14.0
11
12 [Status] Command line: dnsperf -s 127.0.0.1 -p 8053 -l 2 -c 8 -T 8 -d queries-files
13 [Status] Sending queries (to 127.0.0.1:8053)
14 [Status] Started at: Sun Aug 17 08:23:56 2025
15 [Status] Stopping after 2.000000 seconds
16 [Status] Testing complete (time limit)
17
18 Statistics:
19
20 Queries sent: 608050
21 Queries completed: 608050 (100.00%)
22 Queries lost: 0 (0.00%)
23
24 Response codes: NOERROR 608050 (100.00%)
25 Average packet size: request 32, response 92
26 Run time (s): 2.000322
27 Queries per second: 303976.059854
28
29 Average Latency (s): 0.000145 (min 0.000008, max 0.005024)
30 Latency StdDev (s): 0.000199
31 `
32
33 func TestQueriesPerSecond(t *testing.T) {
34 r := strings.NewReader(in)
35 qps, lost := queriesPerSecond(r)
36 if lost != 0 {
37 t.Errorf("expected %d lost queries, got %f", 0, lost)
38 }
39
40 if int(qps) != 303976 {
41 t.Errorf("expected %d queries per second, got %d", 303976, int(qps))
42 }
43 nsPerOp := 1e9 / qps
44 t.Logf("%s-%d\t%d\t\t\t%.1f ns/op\n", name, runtime.NumCPU(), int(qps), nsPerOp)
45 }