mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2026-10-27 07:14:13 +09:00
Pull request 2742: ADG-12585-modernize
Squashed commit of the following: commit 4b963c0a66cb845ec44bf21e50f39f57b1260427 Author: Ainar Garipov <a.garipov@adguard.com> Date: Tue Aug 4 18:17:38 2026 +0300 all: modernize; rm unused params; upd docs
This commit is contained in:
1 parent
091d9287fc
commit
b0e930c6bc
7 files changed
+24
-22
No files matched your search
@@ -12,7 +12,7 @@ import (
|
||||
func checkOtherDHCP(
|
||||
_ context.Context,
|
||||
_ *slog.Logger,
|
||||
ifaceName string,
|
||||
_ string,
|
||||
) (ok4, ok6 bool, err4, err6 error) {
|
||||
return false,
|
||||
false,
|
||||
|
||||
@@ -64,10 +64,10 @@ func TestNewHostsContainer(t *testing.T) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var eventsCalledCounter uint32
|
||||
var eventsCalledCounter atomic.Uint32
|
||||
eventsCh := make(chan struct{})
|
||||
onEvents := func() (e <-chan struct{}) {
|
||||
assert.Equal(t, uint32(1), atomic.AddUint32(&eventsCalledCounter, 1))
|
||||
assert.Equal(t, uint32(1), eventsCalledCounter.Add(1))
|
||||
|
||||
return eventsCh
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func TestNewHostsContainer(t *testing.T) {
|
||||
assert.NotNil(t, <-hc.Upd())
|
||||
|
||||
eventsCh <- struct{}{}
|
||||
assert.Equal(t, uint32(1), atomic.LoadUint32(&eventsCalledCounter))
|
||||
assert.Equal(t, uint32(1), eventsCalledCounter.Load())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// listenPacketReusable announces on the local network address additionally
|
||||
// configuring the socket to have a reusable binding.
|
||||
func listenPacketReusable(ifaceName, network, address string) (c net.PacketConn, err error) {
|
||||
func listenPacketReusable(ifaceName, _, address string) (c net.PacketConn, err error) {
|
||||
var port uint16
|
||||
_, port, err = netutil.SplitHostPort(address)
|
||||
if err != nil {
|
||||
|
||||
@@ -837,7 +837,7 @@ func TestBlockedRequest(t *testing.T) {
|
||||
func TestServerCustomClientUpstream(t *testing.T) {
|
||||
const defaultCacheSize = 1024 * 1024
|
||||
|
||||
var upsCalledCounter uint32
|
||||
var upsCalledCounter atomic.Uint32
|
||||
|
||||
forwardConf := ServerConfig{
|
||||
UDPListenAddrs: []*net.UDPAddr{{}},
|
||||
@@ -862,7 +862,7 @@ func TestServerCustomClientUpstream(t *testing.T) {
|
||||
)
|
||||
|
||||
ups := aghtest.NewUpstreamMock(func(req *dns.Msg) (resp *dns.Msg, err error) {
|
||||
atomic.AddUint32(&upsCalledCounter, 1)
|
||||
upsCalledCounter.Add(1)
|
||||
|
||||
return cmp.Or(
|
||||
aghtest.MatchedResponse(req, dns.TypeA, "host", "192.168.0.1"),
|
||||
@@ -902,11 +902,11 @@ func TestServerCustomClientUpstream(t *testing.T) {
|
||||
|
||||
assert.Equal(t, dns.RcodeSuccess, reply.Rcode)
|
||||
assert.Equal(t, net.IP{192, 168, 0, 1}, reply.Answer[0].(*dns.A).A)
|
||||
assert.Equal(t, uint32(1), atomic.LoadUint32(&upsCalledCounter))
|
||||
assert.Equal(t, uint32(1), upsCalledCounter.Load())
|
||||
|
||||
_, err = dns.Exchange(req, addr)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, uint32(1), atomic.LoadUint32(&upsCalledCounter))
|
||||
assert.Equal(t, uint32(1), upsCalledCounter.Load())
|
||||
}
|
||||
|
||||
// testCNAMEs is a map of names and CNAMEs necessary for the TestUpstream work.
|
||||
@@ -1576,10 +1576,10 @@ func TestPTRResponseFromHosts(t *testing.T) {
|
||||
OnHostByIP: func(ip netip.Addr) (host string) { return "" },
|
||||
}
|
||||
|
||||
var eventsCalledCounter uint32
|
||||
var eventsCalledCounter atomic.Uint32
|
||||
watcher := aghtest.NewFSWatcher()
|
||||
watcher.OnEvents = func() (e <-chan aghos.Event) {
|
||||
assert.Equal(t, uint32(1), atomic.AddUint32(&eventsCalledCounter, 1))
|
||||
assert.Equal(t, uint32(1), eventsCalledCounter.Add(1))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1593,7 +1593,7 @@ func TestPTRResponseFromHosts(t *testing.T) {
|
||||
hc, err := aghnet.NewHostsContainer(ctx, testLogger, testFS, watcher, hostsFilename)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
assert.Equal(t, uint32(1), atomic.LoadUint32(&eventsCalledCounter))
|
||||
assert.Equal(t, uint32(1), eventsCalledCounter.Load())
|
||||
})
|
||||
|
||||
flt, err := filtering.New(&filtering.Config{
|
||||
|
||||
@@ -169,7 +169,9 @@ type Config struct {
|
||||
//
|
||||
// It is of type uint32 to be accessed by atomic.
|
||||
//
|
||||
// TODO(e.burkov): Use atomic.Bool in Go 1.19.
|
||||
// TODO(e.burkov): Use *atomic.Bool once this entire package is refactored.
|
||||
// Do not use it until then, since *newConf = *oldConf will copy an atomic
|
||||
// bool by value, which is prohibited.
|
||||
enabled uint32
|
||||
|
||||
// FiltersUpdateIntervalHours is the time period to update filters
|
||||
|
||||
@@ -70,7 +70,8 @@ func newQLogFile(path string) (qf *qLogFile, err error) {
|
||||
// validateQLogLineIdx returns error if the line index is not valid to continue
|
||||
// search.
|
||||
func (q *qLogFile) validateQLogLineIdx(lineIdx, lastProbeLineIdx, ts, fSize int64) (err error) {
|
||||
if lineIdx == lastProbeLineIdx {
|
||||
switch lineIdx {
|
||||
case lastProbeLineIdx:
|
||||
if lineIdx == 0 {
|
||||
return errTSTooEarly
|
||||
}
|
||||
@@ -78,11 +79,11 @@ func (q *qLogFile) validateQLogLineIdx(lineIdx, lastProbeLineIdx, ts, fSize int6
|
||||
// If we're testing the same line twice then most likely the scope is
|
||||
// too narrow and we won't find anything anymore in any other file.
|
||||
return fmt.Errorf("looking up timestamp %d in %q: %w", ts, q.file.Name(), errTSNotFound)
|
||||
} else if lineIdx == fSize {
|
||||
case fSize:
|
||||
return errTSTooLate
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// seekTS performs binary search in the query log file looking for a record
|
||||
|
||||
@@ -45,10 +45,9 @@ func newTestStatsCtx(tb testing.TB, c Config) (s *StatsCtx) {
|
||||
}
|
||||
|
||||
func TestStats_races(t *testing.T) {
|
||||
var r uint32
|
||||
idGen := func() (id uint32) { return atomic.LoadUint32(&r) }
|
||||
var currentRound atomic.Uint32
|
||||
s := newTestStatsCtx(t, Config{
|
||||
UnitID: idGen,
|
||||
UnitID: currentRound.Load,
|
||||
Enabled: true,
|
||||
})
|
||||
|
||||
@@ -81,14 +80,14 @@ func TestStats_races(t *testing.T) {
|
||||
}
|
||||
|
||||
const (
|
||||
roundsNum = 3
|
||||
roundsNum uint32 = 3
|
||||
|
||||
writersNum = 10
|
||||
readersNum = 5
|
||||
)
|
||||
|
||||
for round := range roundsNum {
|
||||
atomic.StoreUint32(&r, uint32(round))
|
||||
currentRound.Store(round)
|
||||
|
||||
startWG, finWG := &sync.WaitGroup{}, &sync.WaitGroup{}
|
||||
waitCh := make(chan unit)
|
||||
|
||||
Reference in new issue
Block a user