diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/api/client/lists/lists_test.go | 4 | ||||
| -rw-r--r-- | internal/cache/cache.go | 21 | ||||
| -rw-r--r-- | internal/cache/util.go | 18 | ||||
| -rw-r--r-- | internal/config/util.go | 39 | ||||
| -rw-r--r-- | internal/transport/delivery/worker_test.go | 9 |
5 files changed, 18 insertions, 73 deletions
diff --git a/internal/api/client/lists/lists_test.go b/internal/api/client/lists/lists_test.go index 65242db25..a4afa24bb 100644 --- a/internal/api/client/lists/lists_test.go +++ b/internal/api/client/lists/lists_test.go @@ -76,7 +76,9 @@ func (suite *ListsStandardTestSuite) SetupSuite() { func (suite *ListsStandardTestSuite) SetupTest() { suite.state.Caches.Init() - suite.state.Caches.Start() + if err := suite.state.Caches.Start(); err != nil { + panic("error starting caches: " + err.Error()) + } testrig.StartNoopWorkers(&suite.state) testrig.InitTestConfig() diff --git a/internal/cache/cache.go b/internal/cache/cache.go index e57fbb569..88e4f870a 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -23,6 +23,7 @@ import ( "codeberg.org/gruf/go-cache/v3/ttl" "github.com/superseriousbusiness/gotosocial/internal/cache/headerfilter" "github.com/superseriousbusiness/gotosocial/internal/config" + "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/log" ) @@ -124,16 +125,18 @@ func (c *Caches) Init() { // Start will start any caches that require a background // routine, which usually means any kind of TTL caches. -func (c *Caches) Start() { +func (c *Caches) Start() error { log.Infof(nil, "start: %p", c) - tryUntil("starting webfinger cache", 5, func() bool { - return c.Webfinger.Start(5 * time.Minute) - }) + if !c.Webfinger.Start(5 * time.Minute) { + return gtserror.New("could not start webfinger cache") + } - tryUntil("starting statusesFilterableFields cache", 5, func() bool { - return c.StatusesFilterableFields.Start(5 * time.Minute) - }) + if !c.StatusesFilterableFields.Start(5 * time.Minute) { + return gtserror.New("could not start statusesFilterableFields cache") + } + + return nil } // Stop will stop any caches that require a background @@ -141,8 +144,8 @@ func (c *Caches) Start() { func (c *Caches) Stop() { log.Infof(nil, "stop: %p", c) - tryUntil("stopping webfinger cache", 5, c.Webfinger.Stop) - tryUntil("stopping statusesFilterableFields cache", 5, c.StatusesFilterableFields.Stop) + _ = c.Webfinger.Stop() + _ = c.StatusesFilterableFields.Stop() } // Sweep will sweep all the available caches to ensure none diff --git a/internal/cache/util.go b/internal/cache/util.go index fde2f9ada..ceb053e34 100644 --- a/internal/cache/util.go +++ b/internal/cache/util.go @@ -19,11 +19,9 @@ package cache import ( "errors" - "time" errorsv2 "codeberg.org/gruf/go-errors/v2" "github.com/superseriousbusiness/gotosocial/internal/db" - "github.com/superseriousbusiness/gotosocial/internal/log" ) // SentinelError is an error that can be returned and checked against to indicate a non-permanent @@ -51,19 +49,3 @@ type nocopy struct{} func (*nocopy) Lock() {} func (*nocopy) Unlock() {} - -// tryUntil will attempt to call 'do' for 'count' attempts, before panicking with 'msg'. -func tryUntil(msg string, count int, do func() bool) { - for i := 0; i < count; i++ { - if do() { - // success. - return - } - - // Sleep for a little before retry (a bcakoff). - time.Sleep(time.Millisecond * 1 << (i + 1)) - } - - // panic on total failure as this shouldn't happen. - log.Panicf(nil, "failed %s after %d tries", msg, count) -} diff --git a/internal/config/util.go b/internal/config/util.go deleted file mode 100644 index a9df08b3c..000000000 --- a/internal/config/util.go +++ /dev/null @@ -1,39 +0,0 @@ -// GoToSocial -// Copyright (C) GoToSocial Authors admin@gotosocial.org -// SPDX-License-Identifier: AGPL-3.0-or-later -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. - -package config - -import ( - "net/netip" - - "github.com/superseriousbusiness/gotosocial/internal/log" -) - -func MustParseIPPrefixes(in []string) []netip.Prefix { - prefs := make([]netip.Prefix, 0, len(in)) - - for _, i := range in { - pref, err := netip.ParsePrefix(i) - if err != nil { - log.Panicf(nil, "error parsing ip prefix from %q: %v", i, err) - } - - prefs = append(prefs, pref) - } - - return prefs -} diff --git a/internal/transport/delivery/worker_test.go b/internal/transport/delivery/worker_test.go index 192ffcd37..72f485e68 100644 --- a/internal/transport/delivery/worker_test.go +++ b/internal/transport/delivery/worker_test.go @@ -24,11 +24,11 @@ import ( "math/rand" "net" "net/http" + "net/netip" "strconv" "strings" "testing" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/httpclient" "github.com/superseriousbusiness/gotosocial/internal/queue" "github.com/superseriousbusiness/gotosocial/internal/transport/delivery" @@ -44,11 +44,8 @@ func TestDeliveryWorkerPool(t *testing.T) { func testDeliveryWorkerPool(t *testing.T, sz int, input []*testrequest) { wp := new(delivery.WorkerPool) - wp.Init(httpclient.New(httpclient.Config{ - AllowRanges: config.MustParseIPPrefixes([]string{ - "127.0.0.0/8", - }), - })) + allowLocal := []netip.Prefix{netip.MustParsePrefix("127.0.0.0/8")} + wp.Init(httpclient.New(httpclient.Config{AllowRanges: allowLocal})) wp.Start(sz) defer wp.Stop() test(t, &wp.Queue, input) |
