Skip to content

Commit

Permalink
Merge pull request #247 from Tantalor93/lintbump
Browse files Browse the repository at this point in the history
bump linter and run in readonly modules download mode
  • Loading branch information
Ondřej Benkovský authored May 1, 2024
2 parents 48522a2 + 124edf4 commit 68e7b43
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
cache: false
go-version-file: go.mod
- name: Lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v5
with:
version: v1.55.2
version: v1.57.2
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
run:
timeout: 5m
modules-download-mode: readonly
linters:
disable-all: true
enable:
Expand Down
13 changes: 7 additions & 6 deletions pkg/dnsbench/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,16 @@ func (b *Benchmark) Run(ctx context.Context) ([]*ResultStats, error) {

var i int64

// shadow & copy the query func, because for DoQ and DoH we want to share the client, for plain DNS and DoT we don't
// due to manual connection redialing on error, etc.
query := query
// for DoH and DoQ we want to share the client, for plain DNS and DoT we want to have each worker have separate connection
// that is maintained by the worker, this allows DoT and plain DNS protocols to supports counting queries per connection
// and granular control of the connection
workerQuery := query

if query == nil {
if workerQuery == nil {
dnsClient := b.getDNSClient()

var co *dns.Conn
query = func(ctx context.Context, s string, msg *dns.Msg) (*dns.Msg, error) {
workerQuery = func(ctx context.Context, _ string, msg *dns.Msg) (*dns.Msg, error) {
if co != nil && b.QperConn > 0 && i%b.QperConn == 0 {
co.Close()
co = nil
Expand Down Expand Up @@ -488,7 +489,7 @@ func (b *Benchmark) Run(ctx context.Context) ([]*ResultStats, error) {
start := time.Now()

reqTimeoutCtx, cancel := context.WithTimeout(ctx, b.RequestTimeout)
resp, err = query(reqTimeoutCtx, b.Server, &req)
resp, err = workerQuery(reqTimeoutCtx, b.Server, &req)
cancel()
dur := time.Since(start)
if b.RequestLogEnabled {
Expand Down
24 changes: 12 additions & 12 deletions pkg/dnsbench/benchmark_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestBenchmark_Run_PlainDNS_edns0(t *testing.T) {
s := NewServer(dnsbench.UDPTransport, nil, func(w dns.ResponseWriter, r *dns.Msg) {
opt := r.IsEdns0()
if assert.NotNil(t, opt) {
assert.EqualValues(t, opt.UDPSize(), 1024)
assert.EqualValues(t, 1024, opt.UDPSize())
}

ret := new(dns.Msg)
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestBenchmark_Run_PlainDNS_edns0_ednsopt(t *testing.T) {
s := NewServer(dnsbench.UDPTransport, nil, func(w dns.ResponseWriter, r *dns.Msg) {
opt := r.IsEdns0()
if assert.NotNil(t, opt) {
assert.EqualValues(t, opt.UDPSize(), 1024)
assert.EqualValues(t, 1024, opt.UDPSize())
expectedOpt := false
for _, v := range opt.Option {
if v.Option() == testOpt {
Expand Down Expand Up @@ -541,7 +541,7 @@ func TestBenchmark_Run_PlainDNS_download_external_datasource_using_http(t *testi
})
defer s.Close()

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte(`example.org`))
if err != nil {
panic(err)
Expand Down Expand Up @@ -574,7 +574,7 @@ func TestBenchmark_Run_PlainDNS_download_external_datasource_using_http(t *testi
}

func TestBenchmark_Run_PlainDNS_download_external_datasource_using_http_not_available(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
// close right away to get dead port
ts.Close()
Expand Down Expand Up @@ -603,7 +603,7 @@ func TestBenchmark_Run_PlainDNS_download_external_datasource_using_http_not_avai
}

func TestBenchmark_Run_PlainDNS_download_external_datasource_using_http_wrong_response(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusBadRequest)
}))
defer ts.Close()
Expand Down Expand Up @@ -910,7 +910,7 @@ func TestBenchmark_Run_worker_ratelimit(t *testing.T) {
}

func TestBenchmark_Run_PlainDNS_error(t *testing.T) {
s := NewServer(dnsbench.UDPTransport, nil, func(w dns.ResponseWriter, r *dns.Msg) {
s := NewServer(dnsbench.UDPTransport, nil, func(_ dns.ResponseWriter, _ *dns.Msg) {
})
defer s.Close()

Expand Down Expand Up @@ -961,7 +961,7 @@ func TestBenchmark_Run_DoT_error(t *testing.T) {
MinVersion: tls.VersionTLS12,
}

server := NewServer(dnsbench.TLSTransport, &config, func(w dns.ResponseWriter, r *dns.Msg) {
server := NewServer(dnsbench.TLSTransport, &config, func(_ dns.ResponseWriter, _ *dns.Msg) {
})
defer server.Close()

Expand Down Expand Up @@ -997,7 +997,7 @@ func TestBenchmark_Run_DoT_error(t *testing.T) {
}

func TestBenchmark_Run_DoH_error(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
}))
defer ts.Close()
Expand Down Expand Up @@ -1033,7 +1033,7 @@ func TestBenchmark_Run_DoH_error(t *testing.T) {
}

func TestBenchmark_Run_DoQ_error(t *testing.T) {
server := newDoQServer(func(r *dns.Msg) *dns.Msg {
server := newDoQServer(func(_ *dns.Msg) *dns.Msg {
return nil
})
server.start()
Expand Down Expand Up @@ -1340,11 +1340,11 @@ func TestBenchmark_Requestlog(t *testing.T) {

requestLogs := parseRequestLogs(t, requestLogFile)

workerIds := map[int]int{}
workerIDs := map[int]int{}
qtypes := map[string]int{}

for _, v := range requestLogs {
workerIds[v.worker]++
workerIDs[v.worker]++
qtypes[v.qtype]++

assert.Equal(t, "example.org.", v.qname)
Expand All @@ -1355,7 +1355,7 @@ func TestBenchmark_Requestlog(t *testing.T) {
assert.Equal(t, "<nil>", v.err)
assert.NotZero(t, v.duration)
}
assert.Equal(t, map[int]int{0: 2, 1: 2}, workerIds)
assert.Equal(t, map[int]int{0: 2, 1: 2}, workerIDs)
assert.Equal(t, map[string]int{"AAAA": 2, "A": 2}, qtypes)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/dnsbench/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestBenchmark_prepare(t *testing.T) {
require.Equal(t, tt.wantErr, err != nil)
if !tt.wantErr {
assert.Equal(t, tt.wantServer, tt.benchmark.Server)
assert.Equal(t, tt.wantRequestLogPath, tt.wantRequestLogPath)
assert.Equal(t, tt.wantRequestLogPath, tt.benchmark.RequestLogPath)
}
})
}
Expand Down

0 comments on commit 68e7b43

Please sign in to comment.