[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:
tobi
2022-08-31 17:31:21 +02:00
committed by GitHub
parent bee8458a2d
commit 0245c606d7
30 changed files with 501 additions and 222 deletions

View File

@@ -27,6 +27,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/admin"
"github.com/superseriousbusiness/gotosocial/testrig"
)
type MediaCleanupTestSuite struct {
@@ -47,15 +48,15 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanup() {
// we should have OK because our request was valid
suite.Equal(http.StatusOK, recorder.Code)
// Wait for async task to finish
time.Sleep(1 * time.Second)
// Get media we prunes
prunedAttachment, err := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID)
suite.NoError(err)
// the media should no longer be cached
suite.False(*prunedAttachment.Cached)
// the attachment should be updated in the database
if !testrig.WaitFor(func() bool {
if prunedAttachment, _ := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID); prunedAttachment != nil {
return !*prunedAttachment.Cached
}
return false
}) {
suite.FailNow("timed out waiting for attachment to be pruned")
}
}
func (suite *MediaCleanupTestSuite) TestMediaCleanupNoArg() {
@@ -73,15 +74,14 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanupNoArg() {
// we should have OK because our request was valid
suite.Equal(http.StatusOK, recorder.Code)
// Wait for async task to finish
time.Sleep(1 * time.Second)
// Get media we prunes
prunedAttachment, err := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID)
suite.NoError(err)
// the media should no longer be cached
suite.False(*prunedAttachment.Cached)
if !testrig.WaitFor(func() bool {
if prunedAttachment, _ := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID); prunedAttachment != nil {
return !*prunedAttachment.Cached
}
return false
}) {
suite.FailNow("timed out waiting for attachment to be pruned")
}
}
func (suite *MediaCleanupTestSuite) TestMediaCleanupNotOldEnough() {
@@ -101,7 +101,7 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanupNotOldEnough() {
// Wait for async task to finish
time.Sleep(1 * time.Second)
// Get media we prunes
// Get media we pruned
prunedAttachment, err := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID)
suite.NoError(err)