mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-02 11:12:24 -06:00
[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
This commit is contained in:
parent
bee8458a2d
commit
0245c606d7
30 changed files with 501 additions and 222 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue