From 124edf462cc649e6b0f3bca578df6cf5a4745d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Benkovsk=C3=BD?= Date: Wed, 1 May 2024 12:13:40 +0200 Subject: [PATCH] bump linter and run in readonly modules download mode --- .github/workflows/lint.yml | 5 ++--- .golangci.yml | 1 + pkg/dnsbench/benchmark.go | 13 +++++++------ pkg/dnsbench/benchmark_api_test.go | 24 ++++++++++++------------ pkg/dnsbench/benchmark_test.go | 2 +- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6958be3..b66d599 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.golangci.yml b/.golangci.yml index e8f013d..2587e98 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,6 @@ run: timeout: 5m + modules-download-mode: readonly linters: disable-all: true enable: diff --git a/pkg/dnsbench/benchmark.go b/pkg/dnsbench/benchmark.go index e05db96..7441ab1 100644 --- a/pkg/dnsbench/benchmark.go +++ b/pkg/dnsbench/benchmark.go @@ -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 @@ -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 { diff --git a/pkg/dnsbench/benchmark_api_test.go b/pkg/dnsbench/benchmark_api_test.go index b2df8f8..16d72ab 100644 --- a/pkg/dnsbench/benchmark_api_test.go +++ b/pkg/dnsbench/benchmark_api_test.go @@ -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) @@ -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 { @@ -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) @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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) @@ -1355,7 +1355,7 @@ func TestBenchmark_Requestlog(t *testing.T) { assert.Equal(t, "", 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) } diff --git a/pkg/dnsbench/benchmark_test.go b/pkg/dnsbench/benchmark_test.go index 1dd5cc7..2e531de 100644 --- a/pkg/dnsbench/benchmark_test.go +++ b/pkg/dnsbench/benchmark_test.go @@ -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) } }) }