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
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/email"
|
||||
|
@ -25,6 +28,7 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/filter/visibility"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/media"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/processing/account"
|
||||
|
@ -64,6 +68,13 @@ type AccountStandardTestSuite struct {
|
|||
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() {
|
||||
suite.testTokens = testrig.NewTestTokens()
|
||||
suite.testClients = testrig.NewTestClients()
|
||||
|
|
|
@ -20,6 +20,7 @@ package account_test
|
|||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
|
@ -150,7 +151,7 @@ func (suite *FollowTestSuite) TestFollowRequestLocal() {
|
|||
}
|
||||
|
||||
// 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.ActivityFollow, cMsg.APObjectType)
|
||||
suite.Equal(requestingAccount.ID, cMsg.Origin.ID)
|
||||
|
|
|
@ -71,7 +71,7 @@ func (suite *MoveTestSuite) TestMoveAccountOK() {
|
|||
}
|
||||
|
||||
// There should be a message going to the worker.
|
||||
cMsg := suite.checkClientAPIChan()
|
||||
cMsg, _ := suite.getClientMsg(5 * time.Second)
|
||||
move, ok := cMsg.GTSModel.(*gtsmodel.Move)
|
||||
if !ok {
|
||||
suite.FailNow("", "could not cast %T to *gtsmodel.Move", move)
|
||||
|
|
|
@ -26,27 +26,12 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||
)
|
||||
|
||||
type AccountUpdateTestSuite struct {
|
||||
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() {
|
||||
testAccount := >smodel.Account{}
|
||||
*testAccount = *suite.testAccounts["local_account_1"]
|
||||
|
@ -75,7 +60,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateSimple() {
|
|||
suite.Equal(noteExpected, apiAccount.Note)
|
||||
|
||||
// We should have an update in the client api channel.
|
||||
msg := suite.checkClientAPIChan()
|
||||
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||
|
||||
// Profile update.
|
||||
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
||||
|
@ -125,7 +110,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMention() {
|
|||
suite.Equal(noteExpected, apiAccount.Note)
|
||||
|
||||
// We should have an update in the client api channel.
|
||||
msg := suite.checkClientAPIChan()
|
||||
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||
|
||||
// Profile update.
|
||||
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
||||
|
@ -181,7 +166,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMarkdownNote() {
|
|||
suite.Equal(noteExpected, apiAccount.Note)
|
||||
|
||||
// We should have an update in the client api channel.
|
||||
msg := suite.checkClientAPIChan()
|
||||
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||
|
||||
// Profile update.
|
||||
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
||||
|
@ -266,7 +251,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithFields() {
|
|||
suite.EqualValues(emojisExpected, apiAccount.Emojis)
|
||||
|
||||
// We should have an update in the client api channel.
|
||||
msg := suite.checkClientAPIChan()
|
||||
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||
|
||||
// Profile update.
|
||||
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
||||
|
@ -323,7 +308,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateNoteNotFields() {
|
|||
suite.Equal(fieldsBefore, len(apiAccount.Fields))
|
||||
|
||||
// We should have an update in the client api channel.
|
||||
msg := suite.checkClientAPIChan()
|
||||
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||
|
||||
// Profile update.
|
||||
suite.Equal(ap.ActivityUpdate, msg.APActivityType)
|
||||
|
|
|
@ -42,25 +42,23 @@ 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(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.Process = func(ctx context.Context, msg *messages.FromClientAPI) error { return nil }
|
||||
state.Workers.Federator.Process = func(ctx context.Context, msg *messages.FromFediAPI) error { return nil }
|
||||
|
||||
state.Workers.Client.Init(messages.ClientMsgIndices())
|
||||
state.Workers.Federator.Init(messages.FederatorMsgIndices())
|
||||
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.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
|
||||
|
|
Loading…
Reference in New Issue