Pull request 1948: imp-test

Squashed commit of the following:

commit d2e61b0a2406a503d9d7bcd12612ed7e04c1fac6
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Aug 1 18:02:29 2023 +0300

    client: imp addrproc test

commit f7cf0fb1549299b00fdbe400bb4a96c73530bfe0
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Aug 1 17:23:12 2023 +0300

    dnsforward: rm mutex
This commit is contained in:
Ainar Garipov 2023-08-01 19:10:41 +03:00
parent 2cbc5e5f9d
commit fe0edc0065
4 changed files with 17 additions and 15 deletions

View File

@ -58,6 +58,12 @@ type DefaultAddrProcConfig struct {
// immediately by [NewDefaultAddrProc].
InitialAddresses []netip.Addr
// CatchPanics, if true, makes the address processor catch and log panics.
//
// TODO(a.garipov): Consider better ways to do this or apply this method to
// other parts of the codebase.
CatchPanics bool
// UseRDNS, if true, enables resolving of client IP addresses using reverse
// DNS.
UseRDNS bool
@ -151,7 +157,7 @@ func NewDefaultAddrProc(c *DefaultAddrProcConfig) (p *DefaultAddrProc) {
p.whois = newWHOIS(c.DialContext)
}
go p.process()
go p.process(c.CatchPanics)
for _, ip := range c.InitialAddresses {
p.Process(ip)
@ -214,8 +220,10 @@ func (p *DefaultAddrProc) Process(ip netip.Addr) {
// process processes the incoming client IP-address information. It is intended
// to be used as a goroutine. Once clientIPs is closed, process exits.
func (p *DefaultAddrProc) process() {
func (p *DefaultAddrProc) process(catchPanics bool) {
if catchPanics {
defer log.OnPanic("addrProcessor.process")
}
log.Info("clients: processing addresses")

View File

@ -2,6 +2,7 @@ package client_test
import (
"context"
"fmt"
"io"
"net"
"net/netip"
@ -112,6 +113,7 @@ func TestDefaultAddrProc_Process_rDNS(t *testing.T) {
AddressUpdater: &aghtest.AddressUpdater{
OnUpdateAddress: newOnUpdateAddress(tc.wantUpd, updIPCh, updHostCh, updInfoCh),
},
CatchPanics: false,
UseRDNS: true,
UsePrivateRDNS: tc.usePrivate,
UseWHOIS: false,
@ -146,8 +148,8 @@ func newOnUpdateAddress(
infos chan<- *whois.Info,
) (f func(ip netip.Addr, host string, info *whois.Info)) {
return func(ip netip.Addr, host string, info *whois.Info) {
if !want {
panic("got unexpected update")
if !want && (host != "" || info != nil) {
panic(fmt.Errorf("got unexpected update for %v with %q and %v", ip, host, info))
}
ips <- ip
@ -222,6 +224,7 @@ func TestDefaultAddrProc_Process_WHOIS(t *testing.T) {
AddressUpdater: &aghtest.AddressUpdater{
OnUpdateAddress: newOnUpdateAddress(tc.wantUpd, updIPCh, updHostCh, updInfoCh),
},
CatchPanics: false,
UseRDNS: false,
UsePrivateRDNS: false,
UseWHOIS: true,

View File

@ -72,13 +72,6 @@ func startDeferStop(t *testing.T, s *Server) {
testutil.CleanupAndRequireSuccess(t, s.Stop)
}
// packageUpstreamVariableMu is used to serialize access to the package-level
// variables of package upstream.
//
// TODO(s.chzhen): Move these parameters to upstream options and remove this
// crutch.
var packageUpstreamVariableMu = &sync.Mutex{}
func createTestServer(
t *testing.T,
filterConf *filtering.Config,
@ -87,9 +80,6 @@ func createTestServer(
) (s *Server) {
t.Helper()
packageUpstreamVariableMu.Lock()
defer packageUpstreamVariableMu.Unlock()
rules := `||nxdomain.example.org
||NULL.example.org^
127.0.0.1 host.example.org

View File

@ -254,6 +254,7 @@ func newServerConfig(
Exchanger: Context.dnsServer,
AddressUpdater: &Context.clients,
InitialAddresses: initialAddresses,
CatchPanics: true,
UseRDNS: config.Clients.Sources.RDNS,
UseWHOIS: config.Clients.Sources.WHOIS,
}