replace async client API / federator msg processing with worker pools (#497)

* replace async client API / federator msg processing with worker pools
* appease our lord-and-saviour, the linter
This commit is contained in:
kim 2022-04-28 13:23:11 +01:00 committed by GitHub
commit 420e2fb22b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 573 additions and 336 deletions

View file

@ -28,14 +28,17 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/internal/worker"
"github.com/superseriousbusiness/gotosocial/testrig"
)
type FederatingDBTestSuite struct {
suite.Suite
db db.DB
tc typeutils.TypeConverter
federatingDB federatingdb.DB
db db.DB
tc typeutils.TypeConverter
fedWorker *worker.Worker[messages.FromFederator]
fromFederator chan messages.FromFederator
federatingDB federatingdb.DB
testTokens map[string]*gtsmodel.Token
testClients map[string]*gtsmodel.Client
@ -62,10 +65,17 @@ func (suite *FederatingDBTestSuite) SetupSuite() {
func (suite *FederatingDBTestSuite) SetupTest() {
testrig.InitTestLog()
testrig.InitTestConfig()
suite.fedWorker = worker.New[messages.FromFederator](-1, -1)
suite.fromFederator = make(chan messages.FromFederator, 10)
suite.fedWorker.SetProcessor(func(ctx context.Context, msg messages.FromFederator) error {
suite.fromFederator <- msg
return nil
})
_ = suite.fedWorker.Start()
suite.db = testrig.NewTestDB()
suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.federatingDB = testrig.NewTestFederatingDB(suite.db)
suite.federatingDB = testrig.NewTestFederatingDB(suite.db, suite.fedWorker)
testrig.StandardDBSetup(suite.db, suite.testAccounts)
}
@ -73,10 +83,9 @@ func (suite *FederatingDBTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
}
func createTestContext(receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account, fromFederatorChan chan messages.FromFederator) context.Context {
func createTestContext(receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account) context.Context {
ctx := context.Background()
ctx = context.WithValue(ctx, ap.ContextReceivingAccount, receivingAccount)
ctx = context.WithValue(ctx, ap.ContextRequestingAccount, requestingAccount)
ctx = context.WithValue(ctx, ap.ContextFromFederatorChan, fromFederatorChan)
return ctx
}