From d52509a81f763b346ce4dbc8f772c2851c305766 Mon Sep 17 00:00:00 2001 From: Michael Renken Date: Sat, 25 Jun 2022 09:07:44 -0500 Subject: [PATCH] Fix tests - It looks like these tests were added a while back and have been broken for an indeterminate period of time. Since the GitHub workflow was added, this has translated into a bunch of failed actions. - I went ahead and fixed the broken tests. For the most part, it looks like there are missing mocks for the Lock, InboxForActor, and Unlock for each recipient. I made sure that this behavior does indeed exist in the code. - In addition, there was an extra "Host" header added to another test. --- pub/side_effect_actor_test.go | 160 ++++++++++++++++++++++++++++++++++ pub/transport_test.go | 1 + 2 files changed, 161 insertions(+) diff --git a/pub/side_effect_actor_test.go b/pub/side_effect_actor_test.go index eb620862..bf0a2315 100644 --- a/pub/side_effect_actor_test.go +++ b/pub/side_effect_actor_test.go @@ -1123,6 +1123,17 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + + // Inbox for first recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1162,6 +1173,17 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + + // Inbox for first recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1200,6 +1222,17 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + + // Inbox for first recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1239,6 +1272,17 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + + // Inbox for first recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1277,6 +1321,17 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + + // Inbox for first recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1316,6 +1371,17 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + + // Inbox for first recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1355,6 +1421,9 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + mockDb.EXPECT().Lock(ctx, mustParse(testAudienceIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testAudienceIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testAudienceIRI)) mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1394,6 +1463,9 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI4)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + mockDb.EXPECT().Lock(ctx, mustParse(testAudienceIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testAudienceIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testAudienceIRI)) mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1425,6 +1497,9 @@ func TestDeliver(t *testing.T) { mockFp.EXPECT().MaxDeliveryRecursionDepth(ctx).Return(1) mockTp.EXPECT().Dereference(ctx, mustParse(testAudienceIRI)).Return( mustSerializeToBytes(testCollectionOfActors), nil) + mockDb.EXPECT().Lock(ctx, mustParse(testAudienceIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testAudienceIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testAudienceIRI)) mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1478,6 +1553,47 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil).Times(4) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil).Times(4) + + // Inbox for first to + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second to + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + + // Inbox for first bto + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second bto + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + + // Inbox for first cc + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second cc + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + + // Inbox for first bcc + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second bcc + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1518,6 +1634,17 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + + // Inbox for first recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1554,6 +1681,17 @@ func TestDeliver(t *testing.T) { c.EXPECT().NewTransport(ctx, mustParse(testMyOutboxIRI), goFedUserAgent()).Return( mockTp, nil) mockFp.EXPECT().MaxDeliveryRecursionDepth(ctx).Return(1) + + // Inbox for first recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI)).Return( mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( @@ -1595,6 +1733,17 @@ func TestDeliver(t *testing.T) { []byte{}, fmt.Errorf("test error")) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + + // Inbox for first recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) @@ -1634,6 +1783,17 @@ func TestDeliver(t *testing.T) { mustSerializeToBytes(testFederatedPerson1), nil) mockTp.EXPECT().Dereference(ctx, mustParse(testFederatedActorIRI2)).Return( mustSerializeToBytes(testFederatedPerson2), nil) + + // Inbox for first recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI)) + + // Inbox for second recipient + mockDb.EXPECT().Lock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().InboxForActor(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Unlock(ctx, mustParse(testFederatedActorIRI2)) + mockDb.EXPECT().Lock(ctx, mustParse(testMyOutboxIRI)) mockDb.EXPECT().ActorForOutbox(ctx, mustParse(testMyOutboxIRI)).Return( mustParse(testPersonIRI), nil) diff --git a/pub/transport_test.go b/pub/transport_test.go index a349c7f5..04670850 100644 --- a/pub/transport_test.go +++ b/pub/transport_test.go @@ -65,6 +65,7 @@ func TestHttpSigTransportDereference(t *testing.T) { expectReq.Header.Add(acceptHeader, acceptHeaderValue) expectReq.Header.Add("Accept-Charset", "utf-8") expectReq.Header.Add("Date", nowDateHeader()) + expectReq.Header.Add("Host", "example.com") expectReq.Header.Add("User-Agent", fmt.Sprintf("%s %s", testAppAgent, goFedUserAgent())) respR := httptest.NewRecorder() respR.Write(testRespBody)