fix account test suite queue popping logic, ensure noop workers do not pull from queue
This commit is contained in:
parent
1f9a077c7b
commit
951d591f4f
|
@ -18,6 +18,9 @@
|
||||||
package account_test
|
package account_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/email"
|
"github.com/superseriousbusiness/gotosocial/internal/email"
|
||||||
|
@ -25,6 +28,7 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/filter/visibility"
|
"github.com/superseriousbusiness/gotosocial/internal/filter/visibility"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/media"
|
"github.com/superseriousbusiness/gotosocial/internal/media"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/processing/account"
|
"github.com/superseriousbusiness/gotosocial/internal/processing/account"
|
||||||
|
@ -64,6 +68,13 @@ type AccountStandardTestSuite struct {
|
||||||
accountProcessor account.Processor
|
accountProcessor account.Processor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *AccountStandardTestSuite) getClientMsg(timeout time.Duration) (*messages.FromClientAPI, bool) {
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx, cncl := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cncl()
|
||||||
|
return suite.state.Workers.Client.Queue.PopCtx(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *AccountStandardTestSuite) SetupSuite() {
|
func (suite *AccountStandardTestSuite) SetupSuite() {
|
||||||
suite.testTokens = testrig.NewTestTokens()
|
suite.testTokens = testrig.NewTestTokens()
|
||||||
suite.testClients = testrig.NewTestClients()
|
suite.testClients = testrig.NewTestClients()
|
||||||
|
|
|
@ -20,6 +20,7 @@ package account_test
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||||
|
@ -150,7 +151,7 @@ func (suite *FollowTestSuite) TestFollowRequestLocal() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// There should be a message going to the worker.
|
// There should be a message going to the worker.
|
||||||
cMsg := suite.checkClientAPIChan()
|
cMsg, _ := suite.getClientMsg(5 * time.Second)
|
||||||
suite.Equal(ap.ActivityCreate, cMsg.APActivityType)
|
suite.Equal(ap.ActivityCreate, cMsg.APActivityType)
|
||||||
suite.Equal(ap.ActivityFollow, cMsg.APObjectType)
|
suite.Equal(ap.ActivityFollow, cMsg.APObjectType)
|
||||||
suite.Equal(requestingAccount.ID, cMsg.Origin.ID)
|
suite.Equal(requestingAccount.ID, cMsg.Origin.ID)
|
||||||
|
|
|
@ -71,7 +71,7 @@ func (suite *MoveTestSuite) TestMoveAccountOK() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// There should be a message going to the worker.
|
// There should be a message going to the worker.
|
||||||
cMsg := suite.checkClientAPIChan()
|
cMsg, _ := suite.getClientMsg(5 * time.Second)
|
||||||
move, ok := cMsg.GTSModel.(*gtsmodel.Move)
|
move, ok := cMsg.GTSModel.(*gtsmodel.Move)
|
||||||
if !ok {
|
if !ok {
|
||||||
suite.FailNow("", "could not cast %T to *gtsmodel.Move", move)
|
suite.FailNow("", "could not cast %T to *gtsmodel.Move", move)
|
||||||
|
|
|
@ -26,27 +26,12 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountUpdateTestSuite struct {
|
type AccountUpdateTestSuite struct {
|
||||||
AccountStandardTestSuite
|
AccountStandardTestSuite
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *AccountStandardTestSuite) checkClientAPIChan() *messages.FromClientAPI {
|
|
||||||
select {
|
|
||||||
case <-suite.state.Workers.Client.Queue.Wait():
|
|
||||||
case <-time.After(5 * time.Second):
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, ok := suite.state.Workers.Client.Queue.Pop()
|
|
||||||
if !ok {
|
|
||||||
suite.FailNow("no queued message")
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *AccountUpdateTestSuite) TestAccountUpdateSimple() {
|
func (suite *AccountUpdateTestSuite) TestAccountUpdateSimple() {
|
||||||
testAccount := >smodel.Account{}
|
testAccount := >smodel.Account{}
|
||||||
*testAccount = *suite.testAccounts["local_account_1"]
|
*testAccount = *suite.testAccounts["local_account_1"]
|
||||||
|
@ -75,7 +60,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateSimple() {
|
||||||
suite.Equal(noteExpected, apiAccount.Note)
|
suite.Equal(noteExpected, apiAccount.Note)
|
||||||
|
|
||||||
// We should have an update in the client api channel.
|
// We should have an update in the client api channel.
|
||||||
msg := suite.checkClientAPIChan()
|
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||||
|
|
||||||
// Profile update.
|
// Profile update.
|
||||||
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
||||||
|
@ -125,7 +110,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMention() {
|
||||||
suite.Equal(noteExpected, apiAccount.Note)
|
suite.Equal(noteExpected, apiAccount.Note)
|
||||||
|
|
||||||
// We should have an update in the client api channel.
|
// We should have an update in the client api channel.
|
||||||
msg := suite.checkClientAPIChan()
|
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||||
|
|
||||||
// Profile update.
|
// Profile update.
|
||||||
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
||||||
|
@ -181,7 +166,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMarkdownNote() {
|
||||||
suite.Equal(noteExpected, apiAccount.Note)
|
suite.Equal(noteExpected, apiAccount.Note)
|
||||||
|
|
||||||
// We should have an update in the client api channel.
|
// We should have an update in the client api channel.
|
||||||
msg := suite.checkClientAPIChan()
|
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||||
|
|
||||||
// Profile update.
|
// Profile update.
|
||||||
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
||||||
|
@ -266,7 +251,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithFields() {
|
||||||
suite.EqualValues(emojisExpected, apiAccount.Emojis)
|
suite.EqualValues(emojisExpected, apiAccount.Emojis)
|
||||||
|
|
||||||
// We should have an update in the client api channel.
|
// We should have an update in the client api channel.
|
||||||
msg := suite.checkClientAPIChan()
|
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||||
|
|
||||||
// Profile update.
|
// Profile update.
|
||||||
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
||||||
|
@ -323,7 +308,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateNoteNotFields() {
|
||||||
suite.Equal(fieldsBefore, len(apiAccount.Fields))
|
suite.Equal(fieldsBefore, len(apiAccount.Fields))
|
||||||
|
|
||||||
// We should have an update in the client api channel.
|
// We should have an update in the client api channel.
|
||||||
msg := suite.checkClientAPIChan()
|
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||||
|
|
||||||
// Profile update.
|
// Profile update.
|
||||||
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
||||||
|
|
|
@ -42,25 +42,23 @@ import (
|
||||||
// Starts workers on the provided state using noop processing functions.
|
// Starts workers on the provided state using noop processing functions.
|
||||||
// Useful when you *don't* want to trigger side effects in a test.
|
// Useful when you *don't* want to trigger side effects in a test.
|
||||||
func StartNoopWorkers(state *state.State) {
|
func StartNoopWorkers(state *state.State) {
|
||||||
state.Workers.Client.Process = func(ctx context.Context, msg *messages.FromClientAPI) error {
|
state.Workers.Client.Process = func(ctx context.Context, msg *messages.FromClientAPI) error { return nil }
|
||||||
log.Debugf(ctx, "Workers{}.Client{}.Noop(%s)", dump(msg))
|
state.Workers.Federator.Process = func(ctx context.Context, msg *messages.FromFediAPI) error { return nil }
|
||||||
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.Client.Init(messages.ClientMsgIndices())
|
||||||
state.Workers.Federator.Init(messages.FederatorMsgIndices())
|
state.Workers.Federator.Init(messages.FederatorMsgIndices())
|
||||||
state.Workers.Delivery.Init(nil)
|
state.Workers.Delivery.Init(nil)
|
||||||
|
|
||||||
|
// Specifically do NOT start the workers
|
||||||
|
// as caller may require queue contents.
|
||||||
|
// (i.e. don't want workers pulling)
|
||||||
|
// _ = state.Workers.Client.Start(1)
|
||||||
|
// _ = state.Workers.Federator.Start(1)
|
||||||
|
// _ = state.Workers.Dereference.Start(1)
|
||||||
|
// _ = state.Workers.Media.Start(1)
|
||||||
|
//
|
||||||
|
// (except for the scheduler, that's fine)
|
||||||
_ = state.Workers.Scheduler.Start()
|
_ = state.Workers.Scheduler.Start()
|
||||||
_ = state.Workers.Client.Start(1)
|
|
||||||
_ = state.Workers.Federator.Start(1)
|
|
||||||
_ = state.Workers.Dereference.Start(1)
|
|
||||||
_ = state.Workers.Media.Start(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starts workers on the provided state using processing functions from the given
|
// Starts workers on the provided state using processing functions from the given
|
||||||
|
|
Loading…
Reference in New Issue