mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-21 12:35:33 +03:00
all: imp code
This commit is contained in:
parent
1ad99ee3cb
commit
0b4311ac26
3 changed files with 18 additions and 19 deletions
|
@ -236,7 +236,7 @@ func (p *DefaultAddrProc) Process(ctx context.Context, ip netip.Addr) {
|
|||
// to be used as a goroutine. Once clientIPs is closed, process exits.
|
||||
func (p *DefaultAddrProc) process(ctx context.Context, catchPanics bool) {
|
||||
if catchPanics {
|
||||
slogutil.RecoverAndLog(ctx, p.logger)
|
||||
defer slogutil.RecoverAndLog(ctx, p.logger)
|
||||
}
|
||||
|
||||
p.logger.InfoContext(ctx, "processing addresses")
|
||||
|
|
|
@ -21,6 +21,17 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// testStorage is a helper function that returns initialized storage.
|
||||
func testStorage(tb testing.TB) (s *client.Storage) {
|
||||
ctx := testutil.ContextWithTimeout(tb, testTimeout)
|
||||
s, err := client.NewStorage(ctx, &client.StorageConfig{
|
||||
Logger: slogutil.NewDiscardLogger(),
|
||||
})
|
||||
require.NoError(tb, err)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// testHostsContainer is a mock implementation of the [client.HostsContainer]
|
||||
// interface.
|
||||
type testHostsContainer struct {
|
||||
|
@ -571,11 +582,7 @@ func TestStorage_Add(t *testing.T) {
|
|||
}
|
||||
|
||||
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
||||
s, err := client.NewStorage(ctx, &client.StorageConfig{
|
||||
Logger: slogutil.NewDiscardLogger(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
s := testStorage(t)
|
||||
tags := s.AllowedTags()
|
||||
require.NotZero(t, len(tags))
|
||||
require.True(t, slices.IsSorted(tags))
|
||||
|
@ -586,7 +593,7 @@ func TestStorage_Add(t *testing.T) {
|
|||
_, ok = slices.BinarySearch(tags, notAllowedTag)
|
||||
require.False(t, ok)
|
||||
|
||||
err = s.Add(ctx, existingClient)
|
||||
err := s.Add(ctx, existingClient)
|
||||
require.NoError(t, err)
|
||||
|
||||
testCases := []struct {
|
||||
|
@ -706,12 +713,8 @@ func TestStorage_RemoveByName(t *testing.T) {
|
|||
}
|
||||
|
||||
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
||||
s, err := client.NewStorage(ctx, &client.StorageConfig{
|
||||
Logger: slogutil.NewDiscardLogger(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
err = s.Add(ctx, existingClient)
|
||||
s := testStorage(t)
|
||||
err := s.Add(ctx, existingClient)
|
||||
require.NoError(t, err)
|
||||
|
||||
testCases := []struct {
|
||||
|
@ -735,11 +738,7 @@ func TestStorage_RemoveByName(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("duplicate_remove", func(t *testing.T) {
|
||||
s, err = client.NewStorage(ctx, &client.StorageConfig{
|
||||
Logger: slogutil.NewDiscardLogger(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
s = testStorage(t)
|
||||
err = s.Add(ctx, existingClient)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -115,10 +115,10 @@ func Main(clientBuildFS fs.FS) {
|
|||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
|
||||
|
||||
go func() {
|
||||
ctx := context.Background()
|
||||
for {
|
||||
sig := <-signals
|
||||
log.Info("Received signal %q", sig)
|
||||
ctx := context.Background()
|
||||
switch sig {
|
||||
case syscall.SIGHUP:
|
||||
Context.clients.storage.ReloadARP(ctx)
|
||||
|
|
Loading…
Reference in a new issue