summaryrefslogtreecommitdiff
path: root/internal/federation
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-08-31 17:31:21 +0200
committerLibravatar GitHub <noreply@github.com>2022-08-31 17:31:21 +0200
commit0245c606d77c8b99833ccc2c0923a298fb482236 (patch)
tree16311e89656894f09cfaeb8b0f21b5ac9e4de502 /internal/federation
parent[feature] add rate limit middleware (#741) (diff)
downloadgotosocial-0245c606d77c8b99833ccc2c0923a298fb482236.tar.xz
[chore] Test fixes (#788)
* use 'test' value for testrig storage backend * update test dependency * add WaitFor func in testrig * use WaitFor function instead of time.Sleep * tidy up tests * make SentMessages a sync.map * go fmt
Diffstat (limited to 'internal/federation')
-rw-r--r--internal/federation/dereferencing/media_test.go12
-rw-r--r--internal/federation/federatingactor_test.go20
2 files changed, 21 insertions, 11 deletions
diff --git a/internal/federation/dereferencing/media_test.go b/internal/federation/dereferencing/media_test.go
index 26d5c0c49..1c460b69e 100644
--- a/internal/federation/dereferencing/media_test.go
+++ b/internal/federation/dereferencing/media_test.go
@@ -20,13 +20,12 @@ package dereferencing_test
import (
"context"
- "fmt"
"testing"
- "time"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
+ "github.com/superseriousbusiness/gotosocial/testrig"
)
type AttachmentTestSuite struct {
@@ -128,12 +127,11 @@ func (suite *AttachmentTestSuite) TestDereferenceAttachmentAsync() {
suite.NoError(err)
attachmentID := processingMedia.AttachmentID()
- // wait for the media to finish processing
- for finished := processingMedia.Finished(); !finished; finished = processingMedia.Finished() {
- time.Sleep(10 * time.Millisecond)
- fmt.Printf("\n\nnot finished yet...\n\n")
+ if !testrig.WaitFor(func() bool {
+ return processingMedia.Finished()
+ }) {
+ suite.FailNow("timed out waiting for media to be processed")
}
- fmt.Printf("\n\nfinished!\n\n")
// now get the attachment from the database
attachment, err := suite.db.GetAttachmentByID(ctx, attachmentID)
diff --git a/internal/federation/federatingactor_test.go b/internal/federation/federatingactor_test.go
index 59687345a..bab38abe2 100644
--- a/internal/federation/federatingactor_test.go
+++ b/internal/federation/federatingactor_test.go
@@ -115,10 +115,22 @@ func (suite *FederatingActorTestSuite) TestSendRemoteFollower() {
suite.NotNil(activity)
// because we added 1 remote follower for zork, there should be a url in sentMessage
- suite.Len(httpClient.SentMessages, 1)
- msg, ok := httpClient.SentMessages[testRemoteAccount.InboxURI]
- suite.True(ok)
- suite.Equal(`{"@context":"https://www.w3.org/ns/activitystreams","actor":"http://localhost:8080/users/the_mighty_zork","id":"http://localhost:8080/whatever_some_create","object":{"attributedTo":"http://localhost:8080/users/the_mighty_zork","content":"boobies","id":"http://localhost:8080/users/the_mighty_zork/statuses/01G1TR6BADACCZWQMNF9X21TV5","published":"2022-06-02T12:22:21+02:00","tag":[],"to":"http://localhost:8080/users/the_mighty_zork/followers","type":"Note","url":"http://localhost:8080/@the_mighty_zork/statuses/01G1TR6BADACCZWQMNF9X21TV5"},"published":"2022-06-02T12:22:21+02:00","to":"http://localhost:8080/users/the_mighty_zork/followers","type":"Create"}`, string(msg))
+ var sent [][]byte
+ if !testrig.WaitFor(func() bool {
+ sentI, ok := httpClient.SentMessages.Load(testRemoteAccount.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(`{"@context":"https://www.w3.org/ns/activitystreams","actor":"http://localhost:8080/users/the_mighty_zork","id":"http://localhost:8080/whatever_some_create","object":{"attributedTo":"http://localhost:8080/users/the_mighty_zork","content":"boobies","id":"http://localhost:8080/users/the_mighty_zork/statuses/01G1TR6BADACCZWQMNF9X21TV5","published":"2022-06-02T12:22:21+02:00","tag":[],"to":"http://localhost:8080/users/the_mighty_zork/followers","type":"Note","url":"http://localhost:8080/@the_mighty_zork/statuses/01G1TR6BADACCZWQMNF9X21TV5"},"published":"2022-06-02T12:22:21+02:00","to":"http://localhost:8080/users/the_mighty_zork/followers","type":"Create"}`, string(sent[0]))
}
func TestFederatingActorTestSuite(t *testing.T) {