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:
parent
2cbc5e5f9d
commit
fe0edc0065
|
@ -58,6 +58,12 @@ type DefaultAddrProcConfig struct {
|
||||||
// immediately by [NewDefaultAddrProc].
|
// immediately by [NewDefaultAddrProc].
|
||||||
InitialAddresses []netip.Addr
|
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
|
// UseRDNS, if true, enables resolving of client IP addresses using reverse
|
||||||
// DNS.
|
// DNS.
|
||||||
UseRDNS bool
|
UseRDNS bool
|
||||||
|
@ -151,7 +157,7 @@ func NewDefaultAddrProc(c *DefaultAddrProcConfig) (p *DefaultAddrProc) {
|
||||||
p.whois = newWHOIS(c.DialContext)
|
p.whois = newWHOIS(c.DialContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
go p.process()
|
go p.process(c.CatchPanics)
|
||||||
|
|
||||||
for _, ip := range c.InitialAddresses {
|
for _, ip := range c.InitialAddresses {
|
||||||
p.Process(ip)
|
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
|
// process processes the incoming client IP-address information. It is intended
|
||||||
// to be used as a goroutine. Once clientIPs is closed, process exits.
|
// to be used as a goroutine. Once clientIPs is closed, process exits.
|
||||||
func (p *DefaultAddrProc) process() {
|
func (p *DefaultAddrProc) process(catchPanics bool) {
|
||||||
defer log.OnPanic("addrProcessor.process")
|
if catchPanics {
|
||||||
|
defer log.OnPanic("addrProcessor.process")
|
||||||
|
}
|
||||||
|
|
||||||
log.Info("clients: processing addresses")
|
log.Info("clients: processing addresses")
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package client_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
@ -112,6 +113,7 @@ func TestDefaultAddrProc_Process_rDNS(t *testing.T) {
|
||||||
AddressUpdater: &aghtest.AddressUpdater{
|
AddressUpdater: &aghtest.AddressUpdater{
|
||||||
OnUpdateAddress: newOnUpdateAddress(tc.wantUpd, updIPCh, updHostCh, updInfoCh),
|
OnUpdateAddress: newOnUpdateAddress(tc.wantUpd, updIPCh, updHostCh, updInfoCh),
|
||||||
},
|
},
|
||||||
|
CatchPanics: false,
|
||||||
UseRDNS: true,
|
UseRDNS: true,
|
||||||
UsePrivateRDNS: tc.usePrivate,
|
UsePrivateRDNS: tc.usePrivate,
|
||||||
UseWHOIS: false,
|
UseWHOIS: false,
|
||||||
|
@ -146,8 +148,8 @@ func newOnUpdateAddress(
|
||||||
infos chan<- *whois.Info,
|
infos chan<- *whois.Info,
|
||||||
) (f func(ip netip.Addr, host string, info *whois.Info)) {
|
) (f func(ip netip.Addr, host string, info *whois.Info)) {
|
||||||
return func(ip netip.Addr, host string, info *whois.Info) {
|
return func(ip netip.Addr, host string, info *whois.Info) {
|
||||||
if !want {
|
if !want && (host != "" || info != nil) {
|
||||||
panic("got unexpected update")
|
panic(fmt.Errorf("got unexpected update for %v with %q and %v", ip, host, info))
|
||||||
}
|
}
|
||||||
|
|
||||||
ips <- ip
|
ips <- ip
|
||||||
|
@ -222,6 +224,7 @@ func TestDefaultAddrProc_Process_WHOIS(t *testing.T) {
|
||||||
AddressUpdater: &aghtest.AddressUpdater{
|
AddressUpdater: &aghtest.AddressUpdater{
|
||||||
OnUpdateAddress: newOnUpdateAddress(tc.wantUpd, updIPCh, updHostCh, updInfoCh),
|
OnUpdateAddress: newOnUpdateAddress(tc.wantUpd, updIPCh, updHostCh, updInfoCh),
|
||||||
},
|
},
|
||||||
|
CatchPanics: false,
|
||||||
UseRDNS: false,
|
UseRDNS: false,
|
||||||
UsePrivateRDNS: false,
|
UsePrivateRDNS: false,
|
||||||
UseWHOIS: true,
|
UseWHOIS: true,
|
||||||
|
|
|
@ -72,13 +72,6 @@ func startDeferStop(t *testing.T, s *Server) {
|
||||||
testutil.CleanupAndRequireSuccess(t, s.Stop)
|
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(
|
func createTestServer(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
filterConf *filtering.Config,
|
filterConf *filtering.Config,
|
||||||
|
@ -87,9 +80,6 @@ func createTestServer(
|
||||||
) (s *Server) {
|
) (s *Server) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
packageUpstreamVariableMu.Lock()
|
|
||||||
defer packageUpstreamVariableMu.Unlock()
|
|
||||||
|
|
||||||
rules := `||nxdomain.example.org
|
rules := `||nxdomain.example.org
|
||||||
||NULL.example.org^
|
||NULL.example.org^
|
||||||
127.0.0.1 host.example.org
|
127.0.0.1 host.example.org
|
||||||
|
|
|
@ -254,6 +254,7 @@ func newServerConfig(
|
||||||
Exchanger: Context.dnsServer,
|
Exchanger: Context.dnsServer,
|
||||||
AddressUpdater: &Context.clients,
|
AddressUpdater: &Context.clients,
|
||||||
InitialAddresses: initialAddresses,
|
InitialAddresses: initialAddresses,
|
||||||
|
CatchPanics: true,
|
||||||
UseRDNS: config.Clients.Sources.RDNS,
|
UseRDNS: config.Clients.Sources.RDNS,
|
||||||
UseWHOIS: config.Clients.Sources.WHOIS,
|
UseWHOIS: config.Clients.Sources.WHOIS,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue