From 382790cf7f7735e706d448daf444cee947d3ec9e Mon Sep 17 00:00:00 2001 From: kim Date: Thu, 25 Apr 2024 15:25:33 +0100 Subject: [PATCH] add logging to worker processing functions in testrig, don't start workers in unexpected places --- testrig/mediahandler.go | 1 - testrig/processor.go | 5 +---- testrig/util.go | 32 ++++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/testrig/mediahandler.go b/testrig/mediahandler.go index 430e87eb0..d61ba854d 100644 --- a/testrig/mediahandler.go +++ b/testrig/mediahandler.go @@ -24,6 +24,5 @@ import ( // NewTestMediaManager returns a media handler with the default test config, and the given db and storage. func NewTestMediaManager(state *state.State) *media.Manager { - StartNoopWorkers(state) // ensure started return media.NewManager(state) } diff --git a/testrig/processor.go b/testrig/processor.go index d71ac0ede..a1bab4f9a 100644 --- a/testrig/processor.go +++ b/testrig/processor.go @@ -31,8 +31,5 @@ import ( // The passed in state will have its worker functions set appropriately, // but the state will not be initialized. func NewTestProcessor(state *state.State, federator *federation.Federator, emailSender email.Sender, mediaManager *media.Manager) *processing.Processor { - p := processing.NewProcessor(cleaner.New(state), typeutils.NewConverter(state), federator, NewTestOauthServer(state.DB), mediaManager, state, emailSender) - state.Workers.Client.Process = p.Workers().ProcessFromClientAPI - state.Workers.Federator.Process = p.Workers().ProcessFromFediAPI - return p + return processing.NewProcessor(cleaner.New(state), typeutils.NewConverter(state), federator, NewTestOauthServer(state.DB), mediaManager, state, emailSender) } diff --git a/testrig/util.go b/testrig/util.go index 2e52f7008..5947e42de 100644 --- a/testrig/util.go +++ b/testrig/util.go @@ -27,7 +27,10 @@ import ( "os" "time" + "codeberg.org/gruf/go-byteutil" + "codeberg.org/gruf/go-kv/format" "github.com/superseriousbusiness/gotosocial/internal/filter/visibility" + "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/messages" tlprocessor "github.com/superseriousbusiness/gotosocial/internal/processing/timeline" "github.com/superseriousbusiness/gotosocial/internal/processing/workers" @@ -39,8 +42,15 @@ import ( // Starts workers on the provided state using noop processing functions. // Useful when you *don't* want to trigger side effects in a test. func StartNoopWorkers(state *state.State) { - state.Workers.Client.Process = func(context.Context, *messages.FromClientAPI) error { return nil } - state.Workers.Federator.Process = func(context.Context, *messages.FromFediAPI) error { return nil } + state.Workers.Client.Process = func(ctx context.Context, msg *messages.FromClientAPI) error { + log.Debugf(ctx, "Workers{}.Client{}.Noop(%s)", dump(msg)) + return nil // noop + } + + state.Workers.Federator.Process = func(ctx context.Context, msg *messages.FromFediAPI) error { + log.Debugf(ctx, "Workers{}.Federator{}.Noop(%s)", dump(msg)) + return nil // noop + } state.Workers.Client.Init(messages.ClientMsgIndices()) state.Workers.Federator.Init(messages.FederatorMsgIndices()) @@ -56,8 +66,15 @@ func StartNoopWorkers(state *state.State) { // Starts workers on the provided state using processing functions from the given // workers processor. Useful when you *do* want to trigger side effects in a test. func StartWorkers(state *state.State, processor *workers.Processor) { - state.Workers.Client.Process = processor.ProcessFromClientAPI - state.Workers.Federator.Process = processor.ProcessFromFediAPI + state.Workers.Client.Process = func(ctx context.Context, msg *messages.FromClientAPI) error { + log.Debugf(ctx, "Workers{}.Client{}.Process(%s)", dump(msg)) + return processor.ProcessFromClientAPI(ctx, msg) + } + + state.Workers.Federator.Process = func(ctx context.Context, msg *messages.FromFediAPI) error { + log.Debugf(ctx, "Workers{}.Federator{}.Process(%s)", dump(msg)) + return processor.ProcessFromFediAPI(ctx, msg) + } state.Workers.Client.Init(messages.ClientMsgIndices()) state.Workers.Federator.Init(messages.FederatorMsgIndices()) @@ -244,3 +261,10 @@ func WaitFor(condition func() bool) bool { } } } + +// dump returns debug output of 'v'. +func dump(v any) string { + var buf byteutil.Buffer + format.Append(&buf, v) + return buf.String() +}