[chore] Fix conflict in workers tests (#2880)

* [chore] Fix conflict in workers tests

* commenty-wenty
This commit is contained in:
tobi 2024-04-29 11:43:18 +02:00 committed by GitHub
parent 1375a86919
commit 40ece19055
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 224 additions and 134 deletions

View file

@ -31,7 +31,9 @@
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id" "github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/messages" "github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/superseriousbusiness/gotosocial/internal/stream" "github.com/superseriousbusiness/gotosocial/internal/stream"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/internal/util" "github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/testrig" "github.com/superseriousbusiness/gotosocial/testrig"
) )
@ -42,6 +44,7 @@ type FromClientAPITestSuite struct {
func (suite *FromClientAPITestSuite) newStatus( func (suite *FromClientAPITestSuite) newStatus(
ctx context.Context, ctx context.Context,
state *state.State,
account *gtsmodel.Account, account *gtsmodel.Account,
visibility gtsmodel.Visibility, visibility gtsmodel.Visibility,
replyToStatus *gtsmodel.Status, replyToStatus *gtsmodel.Status,
@ -86,7 +89,7 @@ func (suite *FromClientAPITestSuite) newStatus(
TargetAccountID: replyToStatus.AccountID, TargetAccountID: replyToStatus.AccountID,
} }
if err := suite.db.PutMention(ctx, mention); err != nil { if err := state.DB.PutMention(ctx, mention); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
newStatus.Mentions = []*gtsmodel.Mention{mention} newStatus.Mentions = []*gtsmodel.Mention{mention}
@ -103,7 +106,7 @@ func (suite *FromClientAPITestSuite) newStatus(
// Put the status in the db, to mimic what would // Put the status in the db, to mimic what would
// have already happened earlier up the flow. // have already happened earlier up the flow.
if err := suite.db.PutStatus(ctx, newStatus); err != nil { if err := state.DB.PutStatus(ctx, newStatus); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
@ -143,10 +146,11 @@ func (suite *FromClientAPITestSuite) checkStreamed(
func (suite *FromClientAPITestSuite) statusJSON( func (suite *FromClientAPITestSuite) statusJSON(
ctx context.Context, ctx context.Context,
typeConverter *typeutils.Converter,
status *gtsmodel.Status, status *gtsmodel.Status,
requestingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account,
) string { ) string {
apiStatus, err := suite.typeconverter.StatusToAPIStatus( apiStatus, err := typeConverter.StatusToAPIStatus(
ctx, ctx,
status, status,
requestingAccount, requestingAccount,
@ -164,19 +168,27 @@ func (suite *FromClientAPITestSuite) statusJSON(
} }
func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithNotification() { func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithNotification() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
var ( var (
ctx = context.Background() ctx = context.Background()
postingAccount = suite.testAccounts["admin_account"] postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"] receivingAccount = suite.testAccounts["local_account_1"]
testList = suite.testLists["local_account_1_list_1"] testList = suite.testLists["local_account_1_list_1"]
streams = suite.openStreams(ctx, receivingAccount, []string{testList.ID}) streams = suite.openStreams(ctx,
homeStream = streams[stream.TimelineHome] testStructs.Processor,
listStream = streams[stream.TimelineList+":"+testList.ID] receivingAccount,
notifStream = streams[stream.TimelineNotifications] []string{testList.ID},
)
homeStream = streams[stream.TimelineHome]
listStream = streams[stream.TimelineList+":"+testList.ID]
notifStream = streams[stream.TimelineNotifications]
// Admin account posts a new top-level status. // Admin account posts a new top-level status.
status = suite.newStatus( status = suite.newStatus(
ctx, ctx,
testStructs.State,
postingAccount, postingAccount,
gtsmodel.VisibilityPublic, gtsmodel.VisibilityPublic,
nil, nil,
@ -190,12 +202,12 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithNotification() {
*follow = *suite.testFollows["local_account_1_admin_account"] *follow = *suite.testFollows["local_account_1_admin_account"]
follow.Notify = util.Ptr(true) follow.Notify = util.Ptr(true)
if err := suite.db.UpdateFollow(ctx, follow); err != nil { if err := testStructs.State.DB.UpdateFollow(ctx, follow); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
// Process the new status. // Process the new status.
if err := suite.processor.Workers().ProcessFromClientAPI( if err := testStructs.Processor.Workers().ProcessFromClientAPI(
ctx, ctx,
&messages.FromClientAPI{ &messages.FromClientAPI{
APObjectType: ap.ObjectNote, APObjectType: ap.ObjectNote,
@ -209,6 +221,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithNotification() {
statusJSON := suite.statusJSON( statusJSON := suite.statusJSON(
ctx, ctx,
testStructs.TypeConverter,
status, status,
receivingAccount, receivingAccount,
) )
@ -233,7 +246,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithNotification() {
var notif *gtsmodel.Notification var notif *gtsmodel.Notification
if !testrig.WaitFor(func() bool { if !testrig.WaitFor(func() bool {
var err error var err error
notif, err = suite.db.GetNotification( notif, err = testStructs.State.DB.GetNotification(
ctx, ctx,
gtsmodel.NotificationStatus, gtsmodel.NotificationStatus,
receivingAccount.ID, receivingAccount.ID,
@ -245,7 +258,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithNotification() {
suite.FailNow("timed out waiting for new status notification") suite.FailNow("timed out waiting for new status notification")
} }
apiNotif, err := suite.typeconverter.NotificationToAPINotification(ctx, notif) apiNotif, err := testStructs.TypeConverter.NotificationToAPINotification(ctx, notif)
if err != nil { if err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
@ -265,12 +278,15 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithNotification() {
} }
func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() { func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
var ( var (
ctx = context.Background() ctx = context.Background()
postingAccount = suite.testAccounts["admin_account"] postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"] receivingAccount = suite.testAccounts["local_account_1"]
testList = suite.testLists["local_account_1_list_1"] testList = suite.testLists["local_account_1_list_1"]
streams = suite.openStreams(ctx, receivingAccount, []string{testList.ID}) streams = suite.openStreams(ctx, testStructs.Processor, receivingAccount, []string{testList.ID})
homeStream = streams[stream.TimelineHome] homeStream = streams[stream.TimelineHome]
listStream = streams[stream.TimelineList+":"+testList.ID] listStream = streams[stream.TimelineList+":"+testList.ID]
@ -281,6 +297,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() {
// post should also show in the list stream. // post should also show in the list stream.
status = suite.newStatus( status = suite.newStatus(
ctx, ctx,
testStructs.State,
postingAccount, postingAccount,
gtsmodel.VisibilityPublic, gtsmodel.VisibilityPublic,
suite.testStatuses["local_account_2_status_1"], suite.testStatuses["local_account_2_status_1"],
@ -289,7 +306,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() {
) )
// Process the new status. // Process the new status.
if err := suite.processor.Workers().ProcessFromClientAPI( if err := testStructs.Processor.Workers().ProcessFromClientAPI(
ctx, ctx,
&messages.FromClientAPI{ &messages.FromClientAPI{
APObjectType: ap.ObjectNote, APObjectType: ap.ObjectNote,
@ -303,6 +320,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() {
statusJSON := suite.statusJSON( statusJSON := suite.statusJSON(
ctx, ctx,
testStructs.TypeConverter,
status, status,
receivingAccount, receivingAccount,
) )
@ -325,6 +343,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() {
} }
func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() { func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
var ( var (
ctx = context.Background() ctx = context.Background()
postingAccount = suite.testAccounts["admin_account"] postingAccount = suite.testAccounts["admin_account"]
@ -335,6 +356,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() {
// for this, but zork mutes this thread. // for this, but zork mutes this thread.
status = suite.newStatus( status = suite.newStatus(
ctx, ctx,
testStructs.State,
postingAccount, postingAccount,
gtsmodel.VisibilityPublic, gtsmodel.VisibilityPublic,
suite.testStatuses["local_account_1_status_1"], suite.testStatuses["local_account_1_status_1"],
@ -348,12 +370,12 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() {
) )
// Store the thread mute before processing new status. // Store the thread mute before processing new status.
if err := suite.db.PutThreadMute(ctx, threadMute); err != nil { if err := testStructs.State.DB.PutThreadMute(ctx, threadMute); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
// Process the new status. // Process the new status.
if err := suite.processor.Workers().ProcessFromClientAPI( if err := testStructs.Processor.Workers().ProcessFromClientAPI(
ctx, ctx,
&messages.FromClientAPI{ &messages.FromClientAPI{
APObjectType: ap.ObjectNote, APObjectType: ap.ObjectNote,
@ -366,7 +388,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() {
} }
// Ensure no notification received. // Ensure no notification received.
notif, err := suite.db.GetNotification( notif, err := testStructs.State.DB.GetNotification(
ctx, ctx,
gtsmodel.NotificationMention, gtsmodel.NotificationMention,
receivingAccount.ID, receivingAccount.ID,
@ -379,6 +401,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() {
} }
func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() { func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
var ( var (
ctx = context.Background() ctx = context.Background()
postingAccount = suite.testAccounts["admin_account"] postingAccount = suite.testAccounts["admin_account"]
@ -389,6 +414,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() {
// for this, but zork mutes this thread. // for this, but zork mutes this thread.
status = suite.newStatus( status = suite.newStatus(
ctx, ctx,
testStructs.State,
postingAccount, postingAccount,
gtsmodel.VisibilityPublic, gtsmodel.VisibilityPublic,
nil, nil,
@ -402,12 +428,12 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() {
) )
// Store the thread mute before processing new status. // Store the thread mute before processing new status.
if err := suite.db.PutThreadMute(ctx, threadMute); err != nil { if err := testStructs.State.DB.PutThreadMute(ctx, threadMute); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
// Process the new status. // Process the new status.
if err := suite.processor.Workers().ProcessFromClientAPI( if err := testStructs.Processor.Workers().ProcessFromClientAPI(
ctx, ctx,
&messages.FromClientAPI{ &messages.FromClientAPI{
APObjectType: ap.ActivityAnnounce, APObjectType: ap.ActivityAnnounce,
@ -420,7 +446,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() {
} }
// Ensure no notification received. // Ensure no notification received.
notif, err := suite.db.GetNotification( notif, err := testStructs.State.DB.GetNotification(
ctx, ctx,
gtsmodel.NotificationReblog, gtsmodel.NotificationReblog,
receivingAccount.ID, receivingAccount.ID,
@ -433,6 +459,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() {
} }
func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyListOnlyOK() { func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyListOnlyOK() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
// We're modifying the test list so take a copy. // We're modifying the test list so take a copy.
testList := new(gtsmodel.List) testList := new(gtsmodel.List)
*testList = *suite.testLists["local_account_1_list_1"] *testList = *suite.testLists["local_account_1_list_1"]
@ -441,13 +470,14 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
ctx = context.Background() ctx = context.Background()
postingAccount = suite.testAccounts["admin_account"] postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"] receivingAccount = suite.testAccounts["local_account_1"]
streams = suite.openStreams(ctx, receivingAccount, []string{testList.ID}) streams = suite.openStreams(ctx, testStructs.Processor, receivingAccount, []string{testList.ID})
homeStream = streams[stream.TimelineHome] homeStream = streams[stream.TimelineHome]
listStream = streams[stream.TimelineList+":"+testList.ID] listStream = streams[stream.TimelineList+":"+testList.ID]
// Admin account posts a reply to turtle. // Admin account posts a reply to turtle.
status = suite.newStatus( status = suite.newStatus(
ctx, ctx,
testStructs.State,
postingAccount, postingAccount,
gtsmodel.VisibilityPublic, gtsmodel.VisibilityPublic,
suite.testStatuses["local_account_2_status_1"], suite.testStatuses["local_account_2_status_1"],
@ -460,12 +490,12 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
// and admin are in the same list, this means the reply // and admin are in the same list, this means the reply
// should be shown in the list. // should be shown in the list.
testList.RepliesPolicy = gtsmodel.RepliesPolicyList testList.RepliesPolicy = gtsmodel.RepliesPolicyList
if err := suite.db.UpdateList(ctx, testList, "replies_policy"); err != nil { if err := testStructs.State.DB.UpdateList(ctx, testList, "replies_policy"); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
// Process the new status. // Process the new status.
if err := suite.processor.Workers().ProcessFromClientAPI( if err := testStructs.Processor.Workers().ProcessFromClientAPI(
ctx, ctx,
&messages.FromClientAPI{ &messages.FromClientAPI{
APObjectType: ap.ObjectNote, APObjectType: ap.ObjectNote,
@ -479,6 +509,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
statusJSON := suite.statusJSON( statusJSON := suite.statusJSON(
ctx, ctx,
testStructs.TypeConverter,
status, status,
receivingAccount, receivingAccount,
) )
@ -501,6 +532,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
} }
func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyListOnlyNo() { func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyListOnlyNo() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
// We're modifying the test list so take a copy. // We're modifying the test list so take a copy.
testList := new(gtsmodel.List) testList := new(gtsmodel.List)
*testList = *suite.testLists["local_account_1_list_1"] *testList = *suite.testLists["local_account_1_list_1"]
@ -509,13 +543,14 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
ctx = context.Background() ctx = context.Background()
postingAccount = suite.testAccounts["admin_account"] postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"] receivingAccount = suite.testAccounts["local_account_1"]
streams = suite.openStreams(ctx, receivingAccount, []string{testList.ID}) streams = suite.openStreams(ctx, testStructs.Processor, receivingAccount, []string{testList.ID})
homeStream = streams[stream.TimelineHome] homeStream = streams[stream.TimelineHome]
listStream = streams[stream.TimelineList+":"+testList.ID] listStream = streams[stream.TimelineList+":"+testList.ID]
// Admin account posts a reply to turtle. // Admin account posts a reply to turtle.
status = suite.newStatus( status = suite.newStatus(
ctx, ctx,
testStructs.State,
postingAccount, postingAccount,
gtsmodel.VisibilityPublic, gtsmodel.VisibilityPublic,
suite.testStatuses["local_account_2_status_1"], suite.testStatuses["local_account_2_status_1"],
@ -528,17 +563,17 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
// about to remove turtle from the same list as admin, // about to remove turtle from the same list as admin,
// so the new post should not be streamed to the list. // so the new post should not be streamed to the list.
testList.RepliesPolicy = gtsmodel.RepliesPolicyList testList.RepliesPolicy = gtsmodel.RepliesPolicyList
if err := suite.db.UpdateList(ctx, testList, "replies_policy"); err != nil { if err := testStructs.State.DB.UpdateList(ctx, testList, "replies_policy"); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
// Remove turtle from the list. // Remove turtle from the list.
if err := suite.db.DeleteListEntry(ctx, suite.testListEntries["local_account_1_list_1_entry_1"].ID); err != nil { if err := testStructs.State.DB.DeleteListEntry(ctx, suite.testListEntries["local_account_1_list_1_entry_1"].ID); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
// Process the new status. // Process the new status.
if err := suite.processor.Workers().ProcessFromClientAPI( if err := testStructs.Processor.Workers().ProcessFromClientAPI(
ctx, ctx,
&messages.FromClientAPI{ &messages.FromClientAPI{
APObjectType: ap.ObjectNote, APObjectType: ap.ObjectNote,
@ -552,6 +587,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
statusJSON := suite.statusJSON( statusJSON := suite.statusJSON(
ctx, ctx,
testStructs.TypeConverter,
status, status,
receivingAccount, receivingAccount,
) )
@ -574,6 +610,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
} }
func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyListRepliesPolicyNone() { func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyListRepliesPolicyNone() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
// We're modifying the test list so take a copy. // We're modifying the test list so take a copy.
testList := new(gtsmodel.List) testList := new(gtsmodel.List)
*testList = *suite.testLists["local_account_1_list_1"] *testList = *suite.testLists["local_account_1_list_1"]
@ -582,13 +621,14 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyListRepliesPoli
ctx = context.Background() ctx = context.Background()
postingAccount = suite.testAccounts["admin_account"] postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"] receivingAccount = suite.testAccounts["local_account_1"]
streams = suite.openStreams(ctx, receivingAccount, []string{testList.ID}) streams = suite.openStreams(ctx, testStructs.Processor, receivingAccount, []string{testList.ID})
homeStream = streams[stream.TimelineHome] homeStream = streams[stream.TimelineHome]
listStream = streams[stream.TimelineList+":"+testList.ID] listStream = streams[stream.TimelineList+":"+testList.ID]
// Admin account posts a reply to turtle. // Admin account posts a reply to turtle.
status = suite.newStatus( status = suite.newStatus(
ctx, ctx,
testStructs.State,
postingAccount, postingAccount,
gtsmodel.VisibilityPublic, gtsmodel.VisibilityPublic,
suite.testStatuses["local_account_2_status_1"], suite.testStatuses["local_account_2_status_1"],
@ -601,12 +641,12 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyListRepliesPoli
// show any replies, the post should not // show any replies, the post should not
// be streamed to the list. // be streamed to the list.
testList.RepliesPolicy = gtsmodel.RepliesPolicyNone testList.RepliesPolicy = gtsmodel.RepliesPolicyNone
if err := suite.db.UpdateList(ctx, testList, "replies_policy"); err != nil { if err := testStructs.State.DB.UpdateList(ctx, testList, "replies_policy"); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
// Process the new status. // Process the new status.
if err := suite.processor.Workers().ProcessFromClientAPI( if err := testStructs.Processor.Workers().ProcessFromClientAPI(
ctx, ctx,
&messages.FromClientAPI{ &messages.FromClientAPI{
APObjectType: ap.ObjectNote, APObjectType: ap.ObjectNote,
@ -620,6 +660,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyListRepliesPoli
statusJSON := suite.statusJSON( statusJSON := suite.statusJSON(
ctx, ctx,
testStructs.TypeConverter,
status, status,
receivingAccount, receivingAccount,
) )
@ -642,18 +683,22 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyListRepliesPoli
} }
func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoost() { func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoost() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
var ( var (
ctx = context.Background() ctx = context.Background()
postingAccount = suite.testAccounts["admin_account"] postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"] receivingAccount = suite.testAccounts["local_account_1"]
testList = suite.testLists["local_account_1_list_1"] testList = suite.testLists["local_account_1_list_1"]
streams = suite.openStreams(ctx, receivingAccount, []string{testList.ID}) streams = suite.openStreams(ctx, testStructs.Processor, receivingAccount, []string{testList.ID})
homeStream = streams[stream.TimelineHome] homeStream = streams[stream.TimelineHome]
listStream = streams[stream.TimelineList+":"+testList.ID] listStream = streams[stream.TimelineList+":"+testList.ID]
// Admin account boosts a post by turtle. // Admin account boosts a post by turtle.
status = suite.newStatus( status = suite.newStatus(
ctx, ctx,
testStructs.State,
postingAccount, postingAccount,
gtsmodel.VisibilityPublic, gtsmodel.VisibilityPublic,
nil, nil,
@ -662,7 +707,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoost() {
) )
// Process the new status. // Process the new status.
if err := suite.processor.Workers().ProcessFromClientAPI( if err := testStructs.Processor.Workers().ProcessFromClientAPI(
ctx, ctx,
&messages.FromClientAPI{ &messages.FromClientAPI{
APObjectType: ap.ActivityAnnounce, APObjectType: ap.ActivityAnnounce,
@ -676,6 +721,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoost() {
statusJSON := suite.statusJSON( statusJSON := suite.statusJSON(
ctx, ctx,
testStructs.TypeConverter,
status, status,
receivingAccount, receivingAccount,
) )
@ -698,18 +744,22 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoost() {
} }
func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostNoReblogs() { func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostNoReblogs() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
var ( var (
ctx = context.Background() ctx = context.Background()
postingAccount = suite.testAccounts["admin_account"] postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"] receivingAccount = suite.testAccounts["local_account_1"]
testList = suite.testLists["local_account_1_list_1"] testList = suite.testLists["local_account_1_list_1"]
streams = suite.openStreams(ctx, receivingAccount, []string{testList.ID}) streams = suite.openStreams(ctx, testStructs.Processor, receivingAccount, []string{testList.ID})
homeStream = streams[stream.TimelineHome] homeStream = streams[stream.TimelineHome]
listStream = streams[stream.TimelineList+":"+testList.ID] listStream = streams[stream.TimelineList+":"+testList.ID]
// Admin account boosts a post by turtle. // Admin account boosts a post by turtle.
status = suite.newStatus( status = suite.newStatus(
ctx, ctx,
testStructs.State,
postingAccount, postingAccount,
gtsmodel.VisibilityPublic, gtsmodel.VisibilityPublic,
nil, nil,
@ -722,12 +772,12 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostNoReblogs() {
follow := new(gtsmodel.Follow) follow := new(gtsmodel.Follow)
*follow = *suite.testFollows["local_account_1_admin_account"] *follow = *suite.testFollows["local_account_1_admin_account"]
follow.ShowReblogs = util.Ptr(false) follow.ShowReblogs = util.Ptr(false)
if err := suite.db.UpdateFollow(ctx, follow, "show_reblogs"); err != nil { if err := testStructs.State.DB.UpdateFollow(ctx, follow, "show_reblogs"); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
// Process the new status. // Process the new status.
if err := suite.processor.Workers().ProcessFromClientAPI( if err := testStructs.Processor.Workers().ProcessFromClientAPI(
ctx, ctx,
&messages.FromClientAPI{ &messages.FromClientAPI{
APObjectType: ap.ActivityAnnounce, APObjectType: ap.ActivityAnnounce,
@ -757,24 +807,27 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostNoReblogs() {
} }
func (suite *FromClientAPITestSuite) TestProcessStatusDelete() { func (suite *FromClientAPITestSuite) TestProcessStatusDelete() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
var ( var (
ctx = context.Background() ctx = context.Background()
deletingAccount = suite.testAccounts["local_account_1"] deletingAccount = suite.testAccounts["local_account_1"]
receivingAccount = suite.testAccounts["local_account_2"] receivingAccount = suite.testAccounts["local_account_2"]
deletedStatus = suite.testStatuses["local_account_1_status_1"] deletedStatus = suite.testStatuses["local_account_1_status_1"]
boostOfDeletedStatus = suite.testStatuses["admin_account_status_4"] boostOfDeletedStatus = suite.testStatuses["admin_account_status_4"]
streams = suite.openStreams(ctx, receivingAccount, nil) streams = suite.openStreams(ctx, testStructs.Processor, receivingAccount, nil)
homeStream = streams[stream.TimelineHome] homeStream = streams[stream.TimelineHome]
) )
// Delete the status from the db first, to mimic what // Delete the status from the db first, to mimic what
// would have already happened earlier up the flow // would have already happened earlier up the flow
if err := suite.db.DeleteStatusByID(ctx, deletedStatus.ID); err != nil { if err := testStructs.State.DB.DeleteStatusByID(ctx, deletedStatus.ID); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
// Process the status delete. // Process the status delete.
if err := suite.processor.Workers().ProcessFromClientAPI( if err := testStructs.Processor.Workers().ProcessFromClientAPI(
ctx, ctx,
&messages.FromClientAPI{ &messages.FromClientAPI{
APObjectType: ap.ObjectNote, APObjectType: ap.ObjectNote,
@ -806,7 +859,7 @@ func (suite *FromClientAPITestSuite) TestProcessStatusDelete() {
// Boost should no longer be in the database. // Boost should no longer be in the database.
if !testrig.WaitFor(func() bool { if !testrig.WaitFor(func() bool {
_, err := suite.db.GetStatusByID(ctx, boostOfDeletedStatus.ID) _, err := testStructs.State.DB.GetStatusByID(ctx, boostOfDeletedStatus.ID)
return errors.Is(err, db.ErrNoEntries) return errors.Is(err, db.ErrNoEntries)
}) { }) {
suite.FailNow("timed out waiting for status delete") suite.FailNow("timed out waiting for status delete")

View file

@ -42,6 +42,9 @@ type FromFediAPITestSuite struct {
// remote_account_1 boosts the first status of local_account_1 // remote_account_1 boosts the first status of local_account_1
func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() { func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
boostedStatus := suite.testStatuses["local_account_1_status_1"] boostedStatus := suite.testStatuses["local_account_1_status_1"]
boostingAccount := suite.testAccounts["remote_account_1"] boostingAccount := suite.testAccounts["remote_account_1"]
announceStatus := &gtsmodel.Status{} announceStatus := &gtsmodel.Status{}
@ -54,7 +57,7 @@ func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
announceStatus.Account = boostingAccount announceStatus.Account = boostingAccount
announceStatus.Visibility = boostedStatus.Visibility announceStatus.Visibility = boostedStatus.Visibility
err := suite.processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{ err := testStructs.Processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{
APObjectType: ap.ActivityAnnounce, APObjectType: ap.ActivityAnnounce,
APActivityType: ap.ActivityCreate, APActivityType: ap.ActivityCreate,
GTSModel: announceStatus, GTSModel: announceStatus,
@ -66,7 +69,7 @@ func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
// side effects should be triggered // side effects should be triggered
// 1. status should have an ID, and be in the database // 1. status should have an ID, and be in the database
suite.NotEmpty(announceStatus.ID) suite.NotEmpty(announceStatus.ID)
_, err = suite.db.GetStatusByID(context.Background(), announceStatus.ID) _, err = testStructs.State.DB.GetStatusByID(context.Background(), announceStatus.ID)
suite.NoError(err) suite.NoError(err)
// 2. a notification should exist for the announce // 2. a notification should exist for the announce
@ -77,7 +80,7 @@ func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
}, },
} }
notif := &gtsmodel.Notification{} notif := &gtsmodel.Notification{}
err = suite.db.GetWhere(context.Background(), where, notif) err = testStructs.State.DB.GetWhere(context.Background(), where, notif)
suite.NoError(err) suite.NoError(err)
suite.Equal(gtsmodel.NotificationReblog, notif.NotificationType) suite.Equal(gtsmodel.NotificationReblog, notif.NotificationType)
suite.Equal(boostedStatus.AccountID, notif.TargetAccountID) suite.Equal(boostedStatus.AccountID, notif.TargetAccountID)
@ -87,6 +90,9 @@ func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
} }
func (suite *FromFediAPITestSuite) TestProcessReplyMention() { func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
repliedAccount := suite.testAccounts["local_account_1"] repliedAccount := suite.testAccounts["local_account_1"]
repliedStatus := suite.testStatuses["local_account_1_status_1"] repliedStatus := suite.testStatuses["local_account_1_status_1"]
replyingAccount := suite.testAccounts["remote_account_1"] replyingAccount := suite.testAccounts["remote_account_1"]
@ -97,7 +103,7 @@ func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
replyingAccount.FetchedAt = time.Now() replyingAccount.FetchedAt = time.Now()
replyingAccount.SuspendedAt = time.Time{} replyingAccount.SuspendedAt = time.Time{}
replyingAccount.SuspensionOrigin = "" replyingAccount.SuspensionOrigin = ""
err := suite.state.DB.UpdateAccount(context.Background(), err := testStructs.State.DB.UpdateAccount(context.Background(),
replyingAccount, replyingAccount,
"fetched_at", "fetched_at",
"suspended_at", "suspended_at",
@ -111,11 +117,11 @@ func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
ap.AppendInReplyTo(replyingStatusable, testrig.URLMustParse(repliedStatus.URI)) ap.AppendInReplyTo(replyingStatusable, testrig.URLMustParse(repliedStatus.URI))
// Open a websocket stream to later test the streamed status reply. // Open a websocket stream to later test the streamed status reply.
wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), repliedAccount, stream.TimelineHome) wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), repliedAccount, stream.TimelineHome)
suite.NoError(errWithCode) suite.NoError(errWithCode)
// Send the replied status off to the fedi worker to be further processed. // Send the replied status off to the fedi worker to be further processed.
err = suite.processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{ err = testStructs.Processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{
APObjectType: ap.ObjectNote, APObjectType: ap.ObjectNote,
APActivityType: ap.ActivityCreate, APActivityType: ap.ActivityCreate,
APObject: replyingStatusable, APObject: replyingStatusable,
@ -126,12 +132,12 @@ func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
// side effects should be triggered // side effects should be triggered
// 1. status should be in the database // 1. status should be in the database
replyingStatus, err := suite.state.DB.GetStatusByURI(context.Background(), replyingURI) replyingStatus, err := testStructs.State.DB.GetStatusByURI(context.Background(), replyingURI)
suite.NoError(err) suite.NoError(err)
// 2. a notification should exist for the mention // 2. a notification should exist for the mention
var notif gtsmodel.Notification var notif gtsmodel.Notification
err = suite.db.GetWhere(context.Background(), []db.Where{ err = testStructs.State.DB.GetWhere(context.Background(), []db.Where{
{Key: "status_id", Value: replyingStatus.ID}, {Key: "status_id", Value: replyingStatus.ID},
}, &notif) }, &notif)
suite.NoError(err) suite.NoError(err)
@ -156,11 +162,14 @@ func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
} }
func (suite *FromFediAPITestSuite) TestProcessFave() { func (suite *FromFediAPITestSuite) TestProcessFave() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
favedAccount := suite.testAccounts["local_account_1"] favedAccount := suite.testAccounts["local_account_1"]
favedStatus := suite.testStatuses["local_account_1_status_1"] favedStatus := suite.testStatuses["local_account_1_status_1"]
favingAccount := suite.testAccounts["remote_account_1"] favingAccount := suite.testAccounts["remote_account_1"]
wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), favedAccount, stream.TimelineNotifications) wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), favedAccount, stream.TimelineNotifications)
suite.NoError(errWithCode) suite.NoError(errWithCode)
fave := &gtsmodel.StatusFave{ fave := &gtsmodel.StatusFave{
@ -176,10 +185,10 @@ func (suite *FromFediAPITestSuite) TestProcessFave() {
URI: favingAccount.URI + "/faves/aaaaaaaaaaaa", URI: favingAccount.URI + "/faves/aaaaaaaaaaaa",
} }
err := suite.db.Put(context.Background(), fave) err := testStructs.State.DB.Put(context.Background(), fave)
suite.NoError(err) suite.NoError(err)
err = suite.processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{ err = testStructs.Processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{
APObjectType: ap.ActivityLike, APObjectType: ap.ActivityLike,
APActivityType: ap.ActivityCreate, APActivityType: ap.ActivityCreate,
GTSModel: fave, GTSModel: fave,
@ -202,7 +211,7 @@ func (suite *FromFediAPITestSuite) TestProcessFave() {
} }
notif := &gtsmodel.Notification{} notif := &gtsmodel.Notification{}
err = suite.db.GetWhere(context.Background(), where, notif) err = testStructs.State.DB.GetWhere(context.Background(), where, notif)
suite.NoError(err) suite.NoError(err)
suite.Equal(gtsmodel.NotificationFave, notif.NotificationType) suite.Equal(gtsmodel.NotificationFave, notif.NotificationType)
suite.Equal(fave.TargetAccountID, notif.TargetAccountID) suite.Equal(fave.TargetAccountID, notif.TargetAccountID)
@ -225,12 +234,15 @@ func (suite *FromFediAPITestSuite) TestProcessFave() {
// This tests for an issue we were seeing where Misskey sends out faves to inboxes of people that don't own // This tests for an issue we were seeing where Misskey sends out faves to inboxes of people that don't own
// the fave, but just follow the actor who received the fave. // the fave, but just follow the actor who received the fave.
func (suite *FromFediAPITestSuite) TestProcessFaveWithDifferentReceivingAccount() { func (suite *FromFediAPITestSuite) TestProcessFaveWithDifferentReceivingAccount() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
receivingAccount := suite.testAccounts["local_account_2"] receivingAccount := suite.testAccounts["local_account_2"]
favedAccount := suite.testAccounts["local_account_1"] favedAccount := suite.testAccounts["local_account_1"]
favedStatus := suite.testStatuses["local_account_1_status_1"] favedStatus := suite.testStatuses["local_account_1_status_1"]
favingAccount := suite.testAccounts["remote_account_1"] favingAccount := suite.testAccounts["remote_account_1"]
wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), receivingAccount, stream.TimelineHome) wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), receivingAccount, stream.TimelineHome)
suite.NoError(errWithCode) suite.NoError(errWithCode)
fave := &gtsmodel.StatusFave{ fave := &gtsmodel.StatusFave{
@ -246,10 +258,10 @@ func (suite *FromFediAPITestSuite) TestProcessFaveWithDifferentReceivingAccount(
URI: favingAccount.URI + "/faves/aaaaaaaaaaaa", URI: favingAccount.URI + "/faves/aaaaaaaaaaaa",
} }
err := suite.db.Put(context.Background(), fave) err := testStructs.State.DB.Put(context.Background(), fave)
suite.NoError(err) suite.NoError(err)
err = suite.processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{ err = testStructs.Processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{
APObjectType: ap.ActivityLike, APObjectType: ap.ActivityLike,
APActivityType: ap.ActivityCreate, APActivityType: ap.ActivityCreate,
GTSModel: fave, GTSModel: fave,
@ -272,7 +284,7 @@ func (suite *FromFediAPITestSuite) TestProcessFaveWithDifferentReceivingAccount(
} }
notif := &gtsmodel.Notification{} notif := &gtsmodel.Notification{}
err = suite.db.GetWhere(context.Background(), where, notif) err = testStructs.State.DB.GetWhere(context.Background(), where, notif)
suite.NoError(err) suite.NoError(err)
suite.Equal(gtsmodel.NotificationFave, notif.NotificationType) suite.Equal(gtsmodel.NotificationFave, notif.NotificationType)
suite.Equal(fave.TargetAccountID, notif.TargetAccountID) suite.Equal(fave.TargetAccountID, notif.TargetAccountID)
@ -287,6 +299,9 @@ func (suite *FromFediAPITestSuite) TestProcessFaveWithDifferentReceivingAccount(
} }
func (suite *FromFediAPITestSuite) TestProcessAccountDelete() { func (suite *FromFediAPITestSuite) TestProcessAccountDelete() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
ctx := context.Background() ctx := context.Background()
deletedAccount := suite.testAccounts["remote_account_1"] deletedAccount := suite.testAccounts["remote_account_1"]
@ -304,7 +319,7 @@ func (suite *FromFediAPITestSuite) TestProcessAccountDelete() {
URI: fmt.Sprintf("%s/follows/01FGRY72ASHBSET64353DPHK9T", deletedAccount.URI), URI: fmt.Sprintf("%s/follows/01FGRY72ASHBSET64353DPHK9T", deletedAccount.URI),
Notify: util.Ptr(false), Notify: util.Ptr(false),
} }
err := suite.db.Put(ctx, zorkFollowSatan) err := testStructs.State.DB.Put(ctx, zorkFollowSatan)
suite.NoError(err) suite.NoError(err)
satanFollowZork := &gtsmodel.Follow{ satanFollowZork := &gtsmodel.Follow{
@ -317,11 +332,11 @@ func (suite *FromFediAPITestSuite) TestProcessAccountDelete() {
URI: fmt.Sprintf("%s/follows/01FGRYAVAWWPP926J175QGM0WV", receivingAccount.URI), URI: fmt.Sprintf("%s/follows/01FGRYAVAWWPP926J175QGM0WV", receivingAccount.URI),
Notify: util.Ptr(false), Notify: util.Ptr(false),
} }
err = suite.db.Put(ctx, satanFollowZork) err = testStructs.State.DB.Put(ctx, satanFollowZork)
suite.NoError(err) suite.NoError(err)
// now they are mufos! // now they are mufos!
err = suite.processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{ err = testStructs.Processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{
APObjectType: ap.ObjectProfile, APObjectType: ap.ObjectProfile,
APActivityType: ap.ActivityDelete, APActivityType: ap.ActivityDelete,
GTSModel: deletedAccount, GTSModel: deletedAccount,
@ -333,20 +348,20 @@ func (suite *FromFediAPITestSuite) TestProcessAccountDelete() {
// local account 2 blocked foss_satan, that block should be gone now // local account 2 blocked foss_satan, that block should be gone now
testBlock := suite.testBlocks["local_account_2_block_remote_account_1"] testBlock := suite.testBlocks["local_account_2_block_remote_account_1"]
dbBlock := &gtsmodel.Block{} dbBlock := &gtsmodel.Block{}
err = suite.db.GetByID(ctx, testBlock.ID, dbBlock) err = testStructs.State.DB.GetByID(ctx, testBlock.ID, dbBlock)
suite.ErrorIs(err, db.ErrNoEntries) suite.ErrorIs(err, db.ErrNoEntries)
// the mufos should be gone now too // the mufos should be gone now too
satanFollowsZork, err := suite.db.IsFollowing(ctx, deletedAccount.ID, receivingAccount.ID) satanFollowsZork, err := testStructs.State.DB.IsFollowing(ctx, deletedAccount.ID, receivingAccount.ID)
suite.NoError(err) suite.NoError(err)
suite.False(satanFollowsZork) suite.False(satanFollowsZork)
zorkFollowsSatan, err := suite.db.IsFollowing(ctx, receivingAccount.ID, deletedAccount.ID) zorkFollowsSatan, err := testStructs.State.DB.IsFollowing(ctx, receivingAccount.ID, deletedAccount.ID)
suite.NoError(err) suite.NoError(err)
suite.False(zorkFollowsSatan) suite.False(zorkFollowsSatan)
// no statuses from foss satan should be left in the database // no statuses from foss satan should be left in the database
if !testrig.WaitFor(func() bool { if !testrig.WaitFor(func() bool {
s, err := suite.db.GetAccountStatuses(ctx, deletedAccount.ID, 0, false, false, "", "", false, false) s, err := testStructs.State.DB.GetAccountStatuses(ctx, deletedAccount.ID, 0, false, false, "", "", false, false)
return s == nil && err == db.ErrNoEntries return s == nil && err == db.ErrNoEntries
}) { }) {
suite.FailNow("timeout waiting for statuses to be deleted") suite.FailNow("timeout waiting for statuses to be deleted")
@ -356,7 +371,7 @@ func (suite *FromFediAPITestSuite) TestProcessAccountDelete() {
// account data should be zeroed. // account data should be zeroed.
if !testrig.WaitFor(func() bool { if !testrig.WaitFor(func() bool {
dbAccount, err = suite.db.GetAccountByID(ctx, deletedAccount.ID) dbAccount, err = testStructs.State.DB.GetAccountByID(ctx, deletedAccount.ID)
return err == nil && dbAccount.DisplayName == "" return err == nil && dbAccount.DisplayName == ""
}) { }) {
suite.FailNow("timeout waiting for statuses to be deleted") suite.FailNow("timeout waiting for statuses to be deleted")
@ -375,6 +390,9 @@ func (suite *FromFediAPITestSuite) TestProcessAccountDelete() {
} }
func (suite *FromFediAPITestSuite) TestProcessFollowRequestLocked() { func (suite *FromFediAPITestSuite) TestProcessFollowRequestLocked() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
ctx := context.Background() ctx := context.Background()
originAccount := suite.testAccounts["remote_account_1"] originAccount := suite.testAccounts["remote_account_1"]
@ -382,7 +400,7 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestLocked() {
// target is a locked account // target is a locked account
targetAccount := suite.testAccounts["local_account_2"] targetAccount := suite.testAccounts["local_account_2"]
wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), targetAccount, stream.TimelineHome) wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), targetAccount, stream.TimelineHome)
suite.NoError(errWithCode) suite.NoError(errWithCode)
// put the follow request in the database as though it had passed through the federating db already // put the follow request in the database as though it had passed through the federating db already
@ -399,10 +417,10 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestLocked() {
Notify: util.Ptr(false), Notify: util.Ptr(false),
} }
err := suite.db.Put(ctx, satanFollowRequestTurtle) err := testStructs.State.DB.Put(ctx, satanFollowRequestTurtle)
suite.NoError(err) suite.NoError(err)
err = suite.processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{ err = testStructs.Processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{
APObjectType: ap.ActivityFollow, APObjectType: ap.ActivityFollow,
APActivityType: ap.ActivityCreate, APActivityType: ap.ActivityCreate,
GTSModel: satanFollowRequestTurtle, GTSModel: satanFollowRequestTurtle,
@ -425,10 +443,13 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestLocked() {
suite.Equal(originAccount.ID, notif.Account.ID) suite.Equal(originAccount.ID, notif.Account.ID)
// no messages should have been sent out, since we didn't need to federate an accept // no messages should have been sent out, since we didn't need to federate an accept
suite.Empty(&suite.httpClient.SentMessages) suite.Empty(testStructs.HTTPClient.SentMessages)
} }
func (suite *FromFediAPITestSuite) TestProcessFollowRequestUnlocked() { func (suite *FromFediAPITestSuite) TestProcessFollowRequestUnlocked() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
ctx := context.Background() ctx := context.Background()
originAccount := suite.testAccounts["remote_account_1"] originAccount := suite.testAccounts["remote_account_1"]
@ -436,7 +457,7 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestUnlocked() {
// target is an unlocked account // target is an unlocked account
targetAccount := suite.testAccounts["local_account_1"] targetAccount := suite.testAccounts["local_account_1"]
wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), targetAccount, stream.TimelineHome) wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), targetAccount, stream.TimelineHome)
suite.NoError(errWithCode) suite.NoError(errWithCode)
// put the follow request in the database as though it had passed through the federating db already // put the follow request in the database as though it had passed through the federating db already
@ -453,10 +474,10 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestUnlocked() {
Notify: util.Ptr(false), Notify: util.Ptr(false),
} }
err := suite.db.Put(ctx, satanFollowRequestTurtle) err := testStructs.State.DB.Put(ctx, satanFollowRequestTurtle)
suite.NoError(err) suite.NoError(err)
err = suite.processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{ err = testStructs.Processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{
APObjectType: ap.ActivityFollow, APObjectType: ap.ActivityFollow,
APActivityType: ap.ActivityCreate, APActivityType: ap.ActivityCreate,
GTSModel: satanFollowRequestTurtle, GTSModel: satanFollowRequestTurtle,
@ -482,7 +503,7 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestUnlocked() {
// an accept message should be sent to satan's inbox // an accept message should be sent to satan's inbox
var sent []byte var sent []byte
if !testrig.WaitFor(func() bool { if !testrig.WaitFor(func() bool {
delivery, ok := suite.state.Workers.Delivery.Queue.Pop() delivery, ok := testStructs.State.Workers.Delivery.Queue.Pop()
if !ok { if !ok {
return false return false
} }
@ -527,12 +548,15 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestUnlocked() {
// TestCreateStatusFromIRI checks if a forwarded status can be dereferenced by the processor. // TestCreateStatusFromIRI checks if a forwarded status can be dereferenced by the processor.
func (suite *FromFediAPITestSuite) TestCreateStatusFromIRI() { func (suite *FromFediAPITestSuite) TestCreateStatusFromIRI() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
ctx := context.Background() ctx := context.Background()
receivingAccount := suite.testAccounts["local_account_1"] receivingAccount := suite.testAccounts["local_account_1"]
statusCreator := suite.testAccounts["remote_account_2"] statusCreator := suite.testAccounts["remote_account_2"]
err := suite.processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{ err := testStructs.Processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{
APObjectType: ap.ObjectNote, APObjectType: ap.ObjectNote,
APActivityType: ap.ActivityCreate, APActivityType: ap.ActivityCreate,
GTSModel: nil, // gtsmodel is nil because this is a forwarded status -- we want to dereference it using the iri GTSModel: nil, // gtsmodel is nil because this is a forwarded status -- we want to dereference it using the iri
@ -543,12 +567,15 @@ func (suite *FromFediAPITestSuite) TestCreateStatusFromIRI() {
suite.NoError(err) suite.NoError(err)
// status should now be in the database, attributed to remote_account_2 // status should now be in the database, attributed to remote_account_2
s, err := suite.db.GetStatusByURI(context.Background(), "http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1") s, err := testStructs.State.DB.GetStatusByURI(context.Background(), "http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1")
suite.NoError(err) suite.NoError(err)
suite.Equal(statusCreator.URI, s.AccountURI) suite.Equal(statusCreator.URI, s.AccountURI)
} }
func (suite *FromFediAPITestSuite) TestMoveAccount() { func (suite *FromFediAPITestSuite) TestMoveAccount() {
testStructs := suite.SetupTestStructs()
defer suite.TearDownTestStructs(testStructs)
// We're gonna migrate foss_satan to our local admin account. // We're gonna migrate foss_satan to our local admin account.
ctx := context.Background() ctx := context.Background()
receivingAcct := suite.testAccounts["local_account_1"] receivingAcct := suite.testAccounts["local_account_1"]
@ -562,12 +589,12 @@ func (suite *FromFediAPITestSuite) TestMoveAccount() {
// Set alsoKnownAs on the admin account. // Set alsoKnownAs on the admin account.
targetAcct.AlsoKnownAsURIs = []string{requestingAcct.URI} targetAcct.AlsoKnownAsURIs = []string{requestingAcct.URI}
if err := suite.state.DB.UpdateAccount(ctx, targetAcct, "also_known_as_uris"); err != nil { if err := testStructs.State.DB.UpdateAccount(ctx, targetAcct, "also_known_as_uris"); err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
// Remove existing follow from zork to admin account. // Remove existing follow from zork to admin account.
if err := suite.state.DB.DeleteFollowByID( if err := testStructs.State.DB.DeleteFollowByID(
ctx, ctx,
suite.testFollows["local_account_1_admin_account"].ID, suite.testFollows["local_account_1_admin_account"].ID,
); err != nil { ); err != nil {
@ -575,7 +602,7 @@ func (suite *FromFediAPITestSuite) TestMoveAccount() {
} }
// Have Zork follow foss_satan instead. // Have Zork follow foss_satan instead.
if err := suite.state.DB.PutFollow(ctx, &gtsmodel.Follow{ if err := testStructs.State.DB.PutFollow(ctx, &gtsmodel.Follow{
ID: "01HRA0XZYFZC5MNWTKEBR58SSE", ID: "01HRA0XZYFZC5MNWTKEBR58SSE",
URI: "http://localhost:8080/users/the_mighty_zork/follows/01HRA0XZYFZC5MNWTKEBR58SSE", URI: "http://localhost:8080/users/the_mighty_zork/follows/01HRA0XZYFZC5MNWTKEBR58SSE",
AccountID: receivingAcct.ID, AccountID: receivingAcct.ID,
@ -585,7 +612,7 @@ func (suite *FromFediAPITestSuite) TestMoveAccount() {
} }
// Process the Move. // Process the Move.
err := suite.processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{ err := testStructs.Processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{
APObjectType: ap.ObjectProfile, APObjectType: ap.ObjectProfile,
APActivityType: ap.ActivityMove, APActivityType: ap.ActivityMove,
GTSModel: &gtsmodel.Move{ GTSModel: &gtsmodel.Move{
@ -601,14 +628,14 @@ func (suite *FromFediAPITestSuite) TestMoveAccount() {
suite.NoError(err) suite.NoError(err)
// Zork should now be following admin account. // Zork should now be following admin account.
follows, err := suite.state.DB.IsFollowing(ctx, receivingAcct.ID, targetAcct.ID) follows, err := testStructs.State.DB.IsFollowing(ctx, receivingAcct.ID, targetAcct.ID)
if err != nil { if err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
suite.True(follows) suite.True(follows)
// Move should be in the DB. // Move should be in the DB.
move, err := suite.state.DB.GetMoveByURI(ctx, "https://fossbros-anonymous.io/users/foss_satan/moves/01HRA064871MR8HGVSAFJ333GM") move, err := testStructs.State.DB.GetMoveByURI(ctx, "https://fossbros-anonymous.io/users/foss_satan/moves/01HRA064871MR8HGVSAFJ333GM")
if err != nil { if err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }

View file

@ -22,18 +22,12 @@
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/cleaner" "github.com/superseriousbusiness/gotosocial/internal/cleaner"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"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/oauth" "github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/state" "github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/stream" "github.com/superseriousbusiness/gotosocial/internal/stream"
"github.com/superseriousbusiness/gotosocial/internal/transport"
"github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/testrig" "github.com/superseriousbusiness/gotosocial/testrig"
) )
@ -41,16 +35,6 @@
type WorkersTestSuite struct { type WorkersTestSuite struct {
// standard suite interfaces // standard suite interfaces
suite.Suite suite.Suite
db db.DB
storage *storage.Driver
state state.State
mediaManager *media.Manager
typeconverter *typeutils.Converter
httpClient *testrig.MockHTTPClient
transportController transport.Controller
federator *federation.Federator
oauthServer oauth.Server
emailSender email.Sender
// standard suite models // standard suite models
testTokens map[string]*gtsmodel.Token testTokens map[string]*gtsmodel.Token
@ -68,8 +52,22 @@ type WorkersTestSuite struct {
testActivities map[string]testrig.ActivityWithSignature testActivities map[string]testrig.ActivityWithSignature
testLists map[string]*gtsmodel.List testLists map[string]*gtsmodel.List
testListEntries map[string]*gtsmodel.ListEntry testListEntries map[string]*gtsmodel.ListEntry
}
processor *processing.Processor // TestStructs encapsulates structs needed to
// run one test in this package. Each test should
// call SetupTestStructs to get a new TestStructs,
// and defer TearDownTestStructs to close it when
// the test is complete. The reason for doing things
// this way here is to prevent the tests in this
// package from overwriting one another's processors
// and worker queues, which was causing issues
// when running all tests at once.
type TestStructs struct {
State *state.State
Processor *processing.Processor
HTTPClient *testrig.MockHTTPClient
TypeConverter *typeutils.Converter
} }
func (suite *WorkersTestSuite) SetupSuite() { func (suite *WorkersTestSuite) SetupSuite() {
@ -96,48 +94,12 @@ func (suite *WorkersTestSuite) SetupSuite() {
} }
func (suite *WorkersTestSuite) SetupTest() { func (suite *WorkersTestSuite) SetupTest() {
suite.state.Caches.Init()
testrig.InitTestConfig() testrig.InitTestConfig()
testrig.InitTestLog() testrig.InitTestLog()
suite.db = testrig.NewTestDB(&suite.state)
suite.state.DB = suite.db
suite.testActivities = testrig.NewTestActivities(suite.testAccounts) suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
suite.storage = testrig.NewInMemoryStorage()
suite.state.Storage = suite.storage
suite.typeconverter = typeutils.NewConverter(&suite.state)
testrig.StartTimelines(
&suite.state,
visibility.NewFilter(&suite.state),
suite.typeconverter,
)
suite.httpClient = testrig.NewMockHTTPClient(nil, "../../../testrig/media")
suite.httpClient.TestRemotePeople = testrig.NewTestFediPeople()
suite.httpClient.TestRemoteStatuses = testrig.NewTestFediStatuses()
suite.transportController = testrig.NewTestTransportController(&suite.state, suite.httpClient)
suite.mediaManager = testrig.NewTestMediaManager(&suite.state)
suite.federator = testrig.NewTestFederator(&suite.state, suite.transportController, suite.mediaManager)
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
suite.emailSender = testrig.NewEmailSender("../../../web/template/", nil)
suite.processor = processing.NewProcessor(cleaner.New(&suite.state), suite.typeconverter, suite.federator, suite.oauthServer, suite.mediaManager, &suite.state, suite.emailSender)
testrig.StartWorkers(&suite.state, suite.processor.Workers())
testrig.StandardDBSetup(suite.db, suite.testAccounts)
testrig.StandardStorageSetup(suite.storage, "../../../testrig/media")
} }
func (suite *WorkersTestSuite) TearDownTest() { func (suite *WorkersTestSuite) openStreams(ctx context.Context, processor *processing.Processor, account *gtsmodel.Account, listIDs []string) map[string]*stream.Stream {
testrig.StandardDBTeardown(suite.db)
testrig.StandardStorageTeardown(suite.storage)
testrig.StopWorkers(&suite.state)
}
func (suite *WorkersTestSuite) openStreams(ctx context.Context, account *gtsmodel.Account, listIDs []string) map[string]*stream.Stream {
streams := make(map[string]*stream.Stream) streams := make(map[string]*stream.Stream)
for _, streamType := range []string{ for _, streamType := range []string{
@ -145,7 +107,7 @@ func (suite *WorkersTestSuite) openStreams(ctx context.Context, account *gtsmode
stream.TimelinePublic, stream.TimelinePublic,
stream.TimelineNotifications, stream.TimelineNotifications,
} { } {
stream, err := suite.processor.Stream().Open(ctx, account, streamType) stream, err := processor.Stream().Open(ctx, account, streamType)
if err != nil { if err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
@ -156,7 +118,7 @@ func (suite *WorkersTestSuite) openStreams(ctx context.Context, account *gtsmode
for _, listID := range listIDs { for _, listID := range listIDs {
streamType := stream.TimelineList + ":" + listID streamType := stream.TimelineList + ":" + listID
stream, err := suite.processor.Stream().Open(ctx, account, streamType) stream, err := processor.Stream().Open(ctx, account, streamType)
if err != nil { if err != nil {
suite.FailNow(err.Error()) suite.FailNow(err.Error())
} }
@ -166,3 +128,51 @@ func (suite *WorkersTestSuite) openStreams(ctx context.Context, account *gtsmode
return streams return streams
} }
func (suite *WorkersTestSuite) SetupTestStructs() *TestStructs {
state := state.State{}
state.Caches.Init()
db := testrig.NewTestDB(&state)
state.DB = db
storage := testrig.NewInMemoryStorage()
state.Storage = storage
typeconverter := typeutils.NewConverter(&state)
testrig.StartTimelines(
&state,
visibility.NewFilter(&state),
typeconverter,
)
httpClient := testrig.NewMockHTTPClient(nil, "../../../testrig/media")
httpClient.TestRemotePeople = testrig.NewTestFediPeople()
httpClient.TestRemoteStatuses = testrig.NewTestFediStatuses()
transportController := testrig.NewTestTransportController(&state, httpClient)
mediaManager := testrig.NewTestMediaManager(&state)
federator := testrig.NewTestFederator(&state, transportController, mediaManager)
oauthServer := testrig.NewTestOauthServer(db)
emailSender := testrig.NewEmailSender("../../../web/template/", nil)
processor := processing.NewProcessor(cleaner.New(&state), typeconverter, federator, oauthServer, mediaManager, &state, emailSender)
testrig.StartWorkers(&state, processor.Workers())
testrig.StandardDBSetup(db, suite.testAccounts)
testrig.StandardStorageSetup(storage, "../../../testrig/media")
return &TestStructs{
State: &state,
Processor: processor,
HTTPClient: httpClient,
TypeConverter: typeconverter,
}
}
func (suite *WorkersTestSuite) TearDownTestStructs(testStructs *TestStructs) {
testrig.StandardDBTeardown(testStructs.State.DB)
testrig.StandardStorageTeardown(testStructs.State.Storage)
testrig.StopWorkers(testStructs.State)
}