summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/account_test.go43
-rw-r--r--internal/processing/followrequest_test.go39
-rw-r--r--internal/processing/fromfederator_test.go51
-rw-r--r--internal/processing/media/getfile_test.go23
4 files changed, 103 insertions, 53 deletions
diff --git a/internal/processing/account_test.go b/internal/processing/account_test.go
index b34358ba1..a9b492d06 100644
--- a/internal/processing/account_test.go
+++ b/internal/processing/account_test.go
@@ -29,6 +29,7 @@ import (
"github.com/superseriousbusiness/activity/pub"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/testrig"
)
type AccountTestSuite struct {
@@ -59,23 +60,30 @@ func (suite *AccountTestSuite) TestAccountDeleteLocal() {
suite.NoError(errWithCode)
// the delete should be federated outwards to the following account's inbox
- var sent []byte
- var ok bool
- for !ok {
- sent, ok = suite.httpClient.SentMessages[followingAccount.InboxURI]
- }
-
- suite.True(ok)
- delete := &struct {
+ var sent [][]byte
+ delete := new(struct {
Actor string `json:"actor"`
ID string `json:"id"`
Object string `json:"object"`
To string `json:"to"`
CC string `json:"cc"`
Type string `json:"type"`
- }{}
- err = json.Unmarshal(sent, delete)
- suite.NoError(err)
+ })
+
+ if !testrig.WaitFor(func() bool {
+ sentI, ok := suite.httpClient.SentMessages.Load(followingAccount.InboxURI)
+ if ok {
+ sent, ok = sentI.([][]byte)
+ if !ok {
+ panic("SentMessages entry was not [][]byte")
+ }
+ err = json.Unmarshal(sent[0], delete)
+ return err == nil
+ }
+ return false
+ }) {
+ suite.FailNow("timed out waiting for message")
+ }
suite.Equal(deletingAccount.URI, delete.Actor)
suite.Equal(deletingAccount.URI, delete.Object)
@@ -83,13 +91,12 @@ func (suite *AccountTestSuite) TestAccountDeleteLocal() {
suite.Equal(pub.PublicActivityPubIRI, delete.CC)
suite.Equal("Delete", delete.Type)
- // wait for the delete to go through
- time.Sleep(1 * time.Second)
-
- // the deleted account should be deleted
- dbAccount, err := suite.db.GetAccountByID(ctx, deletingAccount.ID)
- suite.NoError(err)
- suite.WithinDuration(dbAccount.SuspendedAt, time.Now(), 30*time.Second)
+ if !testrig.WaitFor(func() bool {
+ dbAccount, _ := suite.db.GetAccountByID(ctx, deletingAccount.ID)
+ return suite.WithinDuration(dbAccount.SuspendedAt, time.Now(), 30*time.Second)
+ }) {
+ suite.FailNow("timed out waiting for account to be deleted")
+ }
}
func TestAccountTestSuite(t *testing.T) {
diff --git a/internal/processing/followrequest_test.go b/internal/processing/followrequest_test.go
index 41e4f686e..5be615ab5 100644
--- a/internal/processing/followrequest_test.go
+++ b/internal/processing/followrequest_test.go
@@ -28,6 +28,7 @@ import (
"github.com/stretchr/testify/suite"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/testrig"
)
type FollowRequestTestSuite struct {
@@ -54,11 +55,22 @@ func (suite *FollowRequestTestSuite) TestFollowRequestAccept() {
relationship, errWithCode := suite.processor.FollowRequestAccept(context.Background(), suite.testAutheds["local_account_1"], requestingAccount.ID)
suite.NoError(errWithCode)
suite.EqualValues(&apimodel.Relationship{ID: "01FHMQX3GAABWSM0S2VZEC2SWC", Following: false, ShowingReblogs: false, Notifying: false, FollowedBy: true, Blocking: false, BlockedBy: false, Muting: false, MutingNotifications: false, Requested: false, DomainBlocking: false, Endorsed: false, Note: ""}, relationship)
- time.Sleep(1 * time.Second)
// accept should be sent to some_user
- sent, ok := suite.httpClient.SentMessages[requestingAccount.InboxURI]
- suite.True(ok)
+ var sent [][]byte
+ if !testrig.WaitFor(func() bool {
+ sentI, ok := suite.httpClient.SentMessages.Load(requestingAccount.InboxURI)
+ if ok {
+ sent, ok = sentI.([][]byte)
+ if !ok {
+ panic("SentMessages entry was not []byte")
+ }
+ return true
+ }
+ return false
+ }) {
+ suite.FailNow("timed out waiting for message")
+ }
accept := &struct {
Actor string `json:"actor"`
@@ -73,7 +85,7 @@ func (suite *FollowRequestTestSuite) TestFollowRequestAccept() {
To string `json:"to"`
Type string `json:"type"`
}{}
- err = json.Unmarshal(sent, accept)
+ err = json.Unmarshal(sent[0], accept)
suite.NoError(err)
suite.Equal(targetAccount.URI, accept.Actor)
@@ -106,11 +118,22 @@ func (suite *FollowRequestTestSuite) TestFollowRequestReject() {
relationship, errWithCode := suite.processor.FollowRequestReject(context.Background(), suite.testAutheds["local_account_1"], requestingAccount.ID)
suite.NoError(errWithCode)
suite.EqualValues(&apimodel.Relationship{ID: "01FHMQX3GAABWSM0S2VZEC2SWC", Following: false, ShowingReblogs: false, Notifying: false, FollowedBy: false, Blocking: false, BlockedBy: false, Muting: false, MutingNotifications: false, Requested: false, DomainBlocking: false, Endorsed: false, Note: ""}, relationship)
- time.Sleep(1 * time.Second)
// reject should be sent to some_user
- sent, ok := suite.httpClient.SentMessages[requestingAccount.InboxURI]
- suite.True(ok)
+ var sent [][]byte
+ if !testrig.WaitFor(func() bool {
+ sentI, ok := suite.httpClient.SentMessages.Load(requestingAccount.InboxURI)
+ if ok {
+ sent, ok = sentI.([][]byte)
+ if !ok {
+ panic("SentMessages entry was not []byte")
+ }
+ return true
+ }
+ return false
+ }) {
+ suite.FailNow("timed out waiting for message")
+ }
reject := &struct {
Actor string `json:"actor"`
@@ -125,7 +148,7 @@ func (suite *FollowRequestTestSuite) TestFollowRequestReject() {
To string `json:"to"`
Type string `json:"type"`
}{}
- err = json.Unmarshal(sent, reject)
+ err = json.Unmarshal(sent[0], reject)
suite.NoError(err)
suite.Equal(targetAccount.URI, reject.Actor)
diff --git a/internal/processing/fromfederator_test.go b/internal/processing/fromfederator_test.go
index 86b63dade..8489303e8 100644
--- a/internal/processing/fromfederator_test.go
+++ b/internal/processing/fromfederator_test.go
@@ -482,26 +482,22 @@ func (suite *FromFederatorTestSuite) TestProcessFollowRequestUnlocked() {
})
suite.NoError(err)
- // a notification should be streamed
- var msg *stream.Message
- select {
- case msg = <-wssStream.Messages:
- // fine
- case <-time.After(5 * time.Second):
- suite.FailNow("no message from wssStream")
+ // an accept message should be sent to satan's inbox
+ var sent [][]byte
+ if !testrig.WaitFor(func() bool {
+ sentI, ok := suite.httpClient.SentMessages.Load(originAccount.InboxURI)
+ if ok {
+ sent, ok = sentI.([][]byte)
+ if !ok {
+ panic("SentMessages entry was not []byte")
+ }
+ return true
+ }
+ return false
+ }) {
+ suite.FailNow("timed out waiting for message")
}
- suite.Equal(stream.EventTypeNotification, msg.Event)
- suite.NotEmpty(msg.Payload)
- suite.EqualValues([]string{stream.TimelineHome}, msg.Stream)
- notif := &model.Notification{}
- err = json.Unmarshal([]byte(msg.Payload), notif)
- suite.NoError(err)
- suite.Equal("follow", notif.Type)
- suite.Equal(originAccount.ID, notif.Account.ID)
- // an accept message should be sent to satan's inbox
- suite.Len(suite.httpClient.SentMessages, 1)
- acceptBytes := suite.httpClient.SentMessages[originAccount.InboxURI]
accept := &struct {
Actor string `json:"actor"`
ID string `json:"id"`
@@ -515,7 +511,7 @@ func (suite *FromFederatorTestSuite) TestProcessFollowRequestUnlocked() {
To string `json:"to"`
Type string `json:"type"`
}{}
- err = json.Unmarshal(acceptBytes, accept)
+ err = json.Unmarshal(sent[0], accept)
suite.NoError(err)
suite.Equal(targetAccount.URI, accept.Actor)
@@ -526,6 +522,23 @@ func (suite *FromFederatorTestSuite) TestProcessFollowRequestUnlocked() {
suite.Equal("Follow", accept.Object.Type)
suite.Equal(originAccount.URI, accept.To)
suite.Equal("Accept", accept.Type)
+
+ // a notification should be streamed
+ var msg *stream.Message
+ select {
+ case msg = <-wssStream.Messages:
+ // fine
+ case <-time.After(5 * time.Second):
+ suite.FailNow("no message from wssStream")
+ }
+ suite.Equal(stream.EventTypeNotification, msg.Event)
+ suite.NotEmpty(msg.Payload)
+ suite.EqualValues([]string{stream.TimelineHome}, msg.Stream)
+ notif := &model.Notification{}
+ err = json.Unmarshal([]byte(msg.Payload), notif)
+ suite.NoError(err)
+ suite.Equal("follow", notif.Type)
+ suite.Equal(originAccount.ID, notif.Account.ID)
}
// TestCreateStatusFromIRI checks if a forwarded status can be dereferenced by the processor.
diff --git a/internal/processing/media/getfile_test.go b/internal/processing/media/getfile_test.go
index 6ba06426f..a8a3568e7 100644
--- a/internal/processing/media/getfile_test.go
+++ b/internal/processing/media/getfile_test.go
@@ -23,10 +23,10 @@ import (
"io"
"path"
"testing"
- "time"
"github.com/stretchr/testify/suite"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/testrig"
)
@@ -99,10 +99,16 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncached() {
suite.Equal(suite.testRemoteAttachments[testAttachment.RemoteURL].Data, b)
suite.Equal(suite.testRemoteAttachments[testAttachment.RemoteURL].ContentType, content.ContentType)
suite.EqualValues(len(suite.testRemoteAttachments[testAttachment.RemoteURL].Data), content.ContentLength)
- time.Sleep(2 * time.Second) // wait a few seconds for the media manager to finish doing stuff
// the attachment should be updated in the database
- dbAttachment, err := suite.db.GetAttachmentByID(ctx, testAttachment.ID)
+ var dbAttachment *gtsmodel.MediaAttachment
+ if !testrig.WaitFor(func() bool {
+ dbAttachment, err = suite.db.GetAttachmentByID(ctx, testAttachment.ID)
+ return dbAttachment != nil
+ }) {
+ suite.FailNow("timed out waiting for updated attachment")
+ }
+
suite.NoError(err)
suite.True(*dbAttachment.Cached)
@@ -149,12 +155,13 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncachedInterrupted() {
suite.NoError(closer.Close())
}
- time.Sleep(2 * time.Second) // wait a few seconds for the media manager to finish doing stuff
-
// the attachment should still be updated in the database even though the caller hung up
- dbAttachment, err := suite.db.GetAttachmentByID(ctx, testAttachment.ID)
- suite.NoError(err)
- suite.True(*dbAttachment.Cached)
+ if !testrig.WaitFor(func() bool {
+ dbAttachment, _ := suite.db.GetAttachmentByID(ctx, testAttachment.ID)
+ return *dbAttachment.Cached
+ }) {
+ suite.FailNow("timed out waiting for attachment to be updated")
+ }
// the file should be back in storage at the same path as before
refreshedBytes, err := suite.storage.Get(ctx, testAttachment.File.Path)