From 0245c606d77c8b99833ccc2c0923a298fb482236 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 31 Aug 2022 17:31:21 +0200 Subject: [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 --- internal/processing/media/getfile_test.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'internal/processing/media/getfile_test.go') 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) -- cgit v1.2.3