From 2b51fbb6d6261901073a0f92815f8cf756442831 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 5 Nov 2020 12:51:19 -0600 Subject: [PATCH] Adding a federation test for community deletes / removes. --- api_tests/src/community.spec.ts | 77 ++++++++++++++------ api_tests/src/shared.ts | 11 +++ docker/federation/start-local-instances.bash | 12 ++- 3 files changed, 75 insertions(+), 25 deletions(-) diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index e01d673d1..7c33f82fd 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -8,7 +8,10 @@ import { createCommunity, deleteCommunity, removeCommunity, + getCommunity, + followCommunity, delay, + longDelay, } from './shared'; import { Community, @@ -55,6 +58,21 @@ test('Create community', async () => { test('Delete community', async () => { let communityRes = await createCommunity(beta); await delay(); + + // Cache the community on Alpha + let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`; + let search = await searchForCommunity(alpha, searchShort); + let communityOnAlpha = search.communities[0]; + assertCommunityFederation(communityOnAlpha, communityRes.community); + await delay(); + + // Follow the community from alpha + let follow = await followCommunity(alpha, true, communityOnAlpha.id); + + // Make sure the follow response went through + expect(follow.community.local).toBe(false); + await delay(); + let deleteCommunityRes = await deleteCommunity( beta, true, @@ -64,11 +82,9 @@ test('Delete community', async () => { await delay(); // Make sure it got deleted on A - let search = await searchForBetaCommunity(alpha); - let communityA = search.communities[0]; - // TODO this fails currently, because no updates are pushed - // expect(communityA.deleted).toBe(true); - // assertCommunityFederation(communityA, communityRes.community); + let communityOnAlphaDeleted = await getCommunity(alpha, communityOnAlpha.id); + expect(communityOnAlphaDeleted.community.deleted).toBe(true); + await delay(); // Undelete let undeleteCommunityRes = await deleteCommunity( @@ -80,29 +96,39 @@ test('Delete community', async () => { await delay(); // Make sure it got undeleted on A - let search2 = await searchForBetaCommunity(alpha); - let communityA2 = search2.communities[0]; - // TODO this fails currently, because no updates are pushed - // expect(communityA2.deleted).toBe(false); - // assertCommunityFederation(communityA2, undeleteCommunityRes.community); + let communityOnAlphaUnDeleted = await getCommunity(alpha, communityOnAlpha.id); + expect(communityOnAlphaUnDeleted.community.deleted).toBe(false); }); test('Remove community', async () => { let communityRes = await createCommunity(beta); await delay(); + + // Cache the community on Alpha + let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`; + let search = await searchForCommunity(alpha, searchShort); + let communityOnAlpha = search.communities[0]; + assertCommunityFederation(communityOnAlpha, communityRes.community); + await delay(); + + // Follow the community from alpha + let follow = await followCommunity(alpha, true, communityOnAlpha.id); + + // Make sure the follow response went through + expect(follow.community.local).toBe(false); + await delay(); + let removeCommunityRes = await removeCommunity( beta, true, communityRes.community.id ); expect(removeCommunityRes.community.removed).toBe(true); + await delay(); - // Make sure it got removed on A - let search = await searchForBetaCommunity(alpha); - let communityA = search.communities[0]; - // TODO this fails currently, because no updates are pushed - // expect(communityA.removed).toBe(true); - // assertCommunityFederation(communityA, communityRes.community); + // Make sure it got Removed on A + let communityOnAlphaRemoved = await getCommunity(alpha, communityOnAlpha.id); + expect(communityOnAlphaRemoved.community.removed).toBe(true); await delay(); // unremove @@ -114,15 +140,18 @@ test('Remove community', async () => { expect(unremoveCommunityRes.community.removed).toBe(false); await delay(); - // Make sure it got unremoved on A - let search2 = await searchForBetaCommunity(alpha); - let communityA2 = search2.communities[0]; - // TODO this fails currently, because no updates are pushed - // expect(communityA2.removed).toBe(false); - // assertCommunityFederation(communityA2, unremoveCommunityRes.community); + // Make sure it got undeleted on A + let communityOnAlphaUnRemoved = await getCommunity(alpha, communityOnAlpha.id); + expect(communityOnAlphaUnRemoved.community.removed).toBe(false); }); test('Search for beta community', async () => { - let search = await searchForBetaCommunity(alpha); - expect(search.communities[0].name).toBe('main'); + let communityRes = await createCommunity(beta); + expect(communityRes.community.name).toBeDefined(); + await delay(); + + let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`; + let search = await searchForCommunity(alpha, searchShort); + let communityOnAlpha = search.communities[0]; + assertCommunityFederation(communityOnAlpha, communityRes.community); }); diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 6aa5cfc4e..3c9cc5d86 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -20,6 +20,7 @@ import { RemoveCommentForm, SearchForm, CommentResponse, + GetCommunityForm, CommunityForm, DeleteCommunityForm, RemoveCommunityForm, @@ -402,6 +403,16 @@ export async function createCommunity( return api.client.createCommunity(form); } +export async function getCommunity( + api: API, + id: number, +): Promise { + let form: GetCommunityForm = { + id, + }; + return api.client.getCommunity(form); +} + export async function deleteCommunity( api: API, deleted: boolean, diff --git a/docker/federation/start-local-instances.bash b/docker/federation/start-local-instances.bash index 6814fdd79..3c374e37e 100755 --- a/docker/federation/start-local-instances.bash +++ b/docker/federation/start-local-instances.bash @@ -8,4 +8,14 @@ for Item in alpha beta gamma delta epsilon ; do sudo chown -R 991:991 volumes/pictrs_$Item done -sudo docker-compose up +sudo docker-compose up -d + +echo "Waiting for Lemmy to start..." +while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8541/api/v1/site')" != "200" ]]; do sleep 1; done +while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8551/api/v1/site')" != "200" ]]; do sleep 1; done +while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8561/api/v1/site')" != "200" ]]; do sleep 1; done +while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8571/api/v1/site')" != "200" ]]; do sleep 1; done +while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8581/api/v1/site')" != "200" ]]; do sleep 1; done +echo "All instances started." + +sudo docker-compose logs -f