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/federation/federatingactor_test.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'internal/federation/federatingactor_test.go') 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) { -- cgit v1.2.3