Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

federation: parallel sending per instance #4623

Merged
merged 60 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
539f06a
federation: parallel sending
phiresky Apr 13, 2024
491daab
federation: some comments
phiresky Apr 13, 2024
987174a
lint and set force_write true when a request fails
phiresky Apr 15, 2024
a66aec6
inbox_urls return vec
phiresky Apr 15, 2024
a3d705f
split inbox functions into separate file
phiresky Apr 15, 2024
7eedcb7
cleanup
phiresky Apr 15, 2024
e719baf
extract sending task code to separate file
phiresky Apr 15, 2024
5e986ef
move federation concurrent config to config file
phiresky Apr 15, 2024
c1932f9
off by one issue
phiresky Apr 15, 2024
a7c7abd
improve msg
phiresky Apr 30, 2024
13ff059
fix both permanent stopping of federation queues and multiple creatio…
phiresky May 29, 2024
7cb4e82
Merge branch 'fix-dupe-activity-sending' into federation-send-parallel
phiresky May 29, 2024
10d3b7d
fix after merge
phiresky May 30, 2024
ffb99cd
Merge remote-tracking branch 'origin/main' into federation-send-parallel
phiresky May 30, 2024
a0b0a7a
lint fix
phiresky May 30, 2024
cdff275
Update crates/federate/src/send.rs
phiresky May 30, 2024
175133f
comment about reverse ordering
phiresky May 30, 2024
2acdc78
remove crashable, comment
phiresky May 30, 2024
9d87921
comment
phiresky May 30, 2024
5538794
move comment
phiresky May 30, 2024
7ee63f4
run federation tests twice
phiresky May 31, 2024
3784b7f
fix test run
phiresky May 31, 2024
c2d18d3
prettier
phiresky May 31, 2024
5a418ac
fix config default
phiresky May 31, 2024
c66bf26
upgrade rust to 1.78 to fix diesel cli
phiresky May 31, 2024
1c1018b
Merge remote-tracking branch 'origin/upgrade-rust' into federation-se…
phiresky May 31, 2024
101901b
fix clippy
phiresky May 31, 2024
dfccf3e
delay
phiresky Jun 3, 2024
2dd7b71
Merge branch 'main' into federation-send-parallel
phiresky Jun 4, 2024
2e2345e
Merge remote-tracking branch 'origin/main' into federation-send-parallel
phiresky Jun 24, 2024
e3fef89
add debug to make localhost urls not valid in ap crate, add some debu…
phiresky Jun 25, 2024
76c6487
federation tests: ensure server stop after test and random activity id
phiresky Jun 29, 2024
0f5b69c
ci fix
phiresky Jun 29, 2024
c2dab71
Merge remote-tracking branch 'origin/main' into federation-send-parallel
phiresky Jul 9, 2024
40b3c1a
add test to federate 100 events
phiresky Jul 9, 2024
a40fea3
fix send 100 test
phiresky Jul 10, 2024
dd9c89e
different data every time so activities are distinguishable
phiresky Jul 10, 2024
bef7190
allow out of order receives in test
phiresky Jul 11, 2024
69ead52
lint
phiresky Jul 11, 2024
0eec62f
Merge remote-tracking branch 'origin/main' into federation-send-parallel
phiresky Jul 15, 2024
dda528b
comment about https://github.com/LemmyNet/lemmy/pull/4623#discussion_…
phiresky Jul 15, 2024
694c293
move sender for clarity, add comment
phiresky Jul 15, 2024
9d470b7
move more things to members
phiresky Jul 15, 2024
10758ab
update test todo comment, use same env var as worker test but default…
phiresky Jul 15, 2024
373e619
remove else below continue
phiresky Jul 15, 2024
5ab598a
some more cleanup
phiresky Jul 15, 2024
4849ac0
handle todo about smooth exit
phiresky Jul 15, 2024
ec859fe
add federate inboxes collector tests
phiresky Jul 15, 2024
c32d05c
lint
phiresky Jul 15, 2024
481e39b
actor max length
phiresky Jul 15, 2024
9c85ce9
don't reset fail count if activity skipped
phiresky Jul 16, 2024
c60cf5a
fix some comments
phiresky Jul 16, 2024
b487fa0
reuse vars
phiresky Jul 16, 2024
80e0318
format
phiresky Jul 16, 2024
bda834e
Update .woodpecker.yml
phiresky Jul 17, 2024
d8f9152
fix recheck time
phiresky Jul 18, 2024
0abc7f4
fix inboxes tests under fast mode
phiresky Jul 18, 2024
20ab8e2
format
phiresky Jul 18, 2024
3a7ce9a
make i32 and ugly casts
phiresky Jul 19, 2024
305faeb
clippy
phiresky Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ steps:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
LEMMY_TEST_FAST_FEDERATION: "1"
commands:
- export LEMMY_CONFIG_LOCATION=../../config/config.hjson
- cargo test --workspace --no-fail-fast
Expand Down
122 changes: 121 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 46 additions & 21 deletions api_tests/src/follow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
betaUrl,
registerUser,
unfollows,
delay,
} from "./shared";

beforeAll(setupLogins);
Expand All @@ -21,39 +22,48 @@ test("Follow local community", async () => {
let user = await registerUser(beta, betaUrl);

let community = (await resolveBetaCommunity(user)).community!;
expect(community.counts.subscribers).toBe(1);
expect(community.counts.subscribers_local).toBe(1);
let follow = await followCommunity(user, true, community.community.id);

// Make sure the follow response went through
expect(follow.community_view.community.local).toBe(true);
expect(follow.community_view.subscribed).toBe("Subscribed");
expect(follow.community_view.counts.subscribers).toBe(2);
expect(follow.community_view.counts.subscribers_local).toBe(2);
expect(follow.community_view.counts.subscribers).toBe(
community.counts.subscribers + 1,
);
expect(follow.community_view.counts.subscribers_local).toBe(
community.counts.subscribers_local + 1,
);

// Test an unfollow
let unfollow = await followCommunity(user, false, community.community.id);
expect(unfollow.community_view.subscribed).toBe("NotSubscribed");
expect(unfollow.community_view.counts.subscribers).toBe(1);
expect(unfollow.community_view.counts.subscribers_local).toBe(1);
expect(unfollow.community_view.counts.subscribers).toBe(
community.counts.subscribers,
);
expect(unfollow.community_view.counts.subscribers_local).toBe(
community.counts.subscribers_local,
);
});

test("Follow federated community", async () => {
// It takes about 1 second for the community aggregates to federate
let betaCommunity = (
await delay(2000); // if this is the second test run, we don't have a way to wait for the correct number of subscribers
const betaCommunityInitial = (
await waitUntil(
() => resolveBetaCommunity(alpha),
c =>
c.community?.counts.subscribers === 1 &&
c.community.counts.subscribers_local === 0,
c => !!c.community && c.community?.counts.subscribers >= 1,
)
).community;
if (!betaCommunity) {
if (!betaCommunityInitial) {
throw "Missing beta community";
}
let follow = await followCommunity(alpha, true, betaCommunity.community.id);
let follow = await followCommunity(
alpha,
true,
betaCommunityInitial.community.id,
);
expect(follow.community_view.subscribed).toBe("Pending");
betaCommunity = (
const betaCommunity = (
await waitUntil(
() => resolveBetaCommunity(alpha),
c => c.community?.subscribed === "Subscribed",
Expand All @@ -64,20 +74,24 @@ test("Follow federated community", async () => {
expect(betaCommunity?.community.local).toBe(false);
expect(betaCommunity?.community.name).toBe("main");
expect(betaCommunity?.subscribed).toBe("Subscribed");
expect(betaCommunity?.counts.subscribers_local).toBe(1);
expect(betaCommunity?.counts.subscribers_local).toBe(
betaCommunityInitial.counts.subscribers_local + 1,
);

// check that unfollow was federated
let communityOnBeta1 = await resolveBetaCommunity(beta);
expect(communityOnBeta1.community?.counts.subscribers).toBe(2);
expect(communityOnBeta1.community?.counts.subscribers_local).toBe(1);
expect(communityOnBeta1.community?.counts.subscribers).toBe(
betaCommunityInitial.counts.subscribers + 1,
);

// Check it from local
let site = await getSite(alpha);
let remoteCommunityId = site.my_user?.follows.find(
c => c.community.local == false,
c =>
c.community.local == false &&
c.community.id === betaCommunityInitial.community.id,
)?.community.id;
expect(remoteCommunityId).toBeDefined();
expect(site.my_user?.follows.length).toBe(2);

if (!remoteCommunityId) {
throw "Missing remote community id";
Expand All @@ -89,10 +103,21 @@ test("Follow federated community", async () => {

// Make sure you are unsubbed locally
let siteUnfollowCheck = await getSite(alpha);
expect(siteUnfollowCheck.my_user?.follows.length).toBe(1);
expect(
siteUnfollowCheck.my_user?.follows.find(
c => c.community.id === betaCommunityInitial.community.id,
),
).toBe(undefined);

// check that unfollow was federated
let communityOnBeta2 = await resolveBetaCommunity(beta);
expect(communityOnBeta2.community?.counts.subscribers).toBe(1);
let communityOnBeta2 = await waitUntil(
() => resolveBetaCommunity(beta),
c =>
c.community?.counts.subscribers ===
betaCommunityInitial.counts.subscribers,
);
expect(communityOnBeta2.community?.counts.subscribers).toBe(
betaCommunityInitial.counts.subscribers,
);
expect(communityOnBeta2.community?.counts.subscribers_local).toBe(1);
});
30 changes: 20 additions & 10 deletions api_tests/src/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ beforeAll(async () => {

afterAll(unfollows);

async function assertPostFederation(postOne: PostView, postTwo: PostView) {
async function assertPostFederation(
postOne: PostView,
postTwo: PostView,
waitForMeta = true,
) {
// Link metadata is generated in background task and may not be ready yet at this time,
// so wait for it explicitly. For removed posts we cant refetch anything.
postOne = await waitForPost(beta, postOne.post, res => {
return res === null || res?.post.embed_title !== null;
});
postTwo = await waitForPost(
beta,
postTwo.post,
res => res === null || res?.post.embed_title !== null,
);
if (waitForMeta) {
postOne = await waitForPost(beta, postOne.post, res => {
return res === null || !!res?.post.embed_title;
});
postTwo = await waitForPost(
beta,
postTwo.post,
res => res === null || !!res?.post.embed_title,
);
}

expect(postOne?.post.ap_id).toBe(postTwo?.post.ap_id);
expect(postOne?.post.name).toBe(postTwo?.post.name);
Expand Down Expand Up @@ -408,7 +414,11 @@ test("Remove a post from admin and community on same instance", async () => {
p => p?.post_view.post.removed ?? false,
);
expect(alphaPost?.post_view.post.removed).toBe(true);
await assertPostFederation(alphaPost.post_view, removePostRes.post_view);
await assertPostFederation(
alphaPost.post_view,
removePostRes.post_view,
false,
);

// Undelete
let undeletedPost = await removePost(beta, false, betaPost.post);
Expand Down
6 changes: 5 additions & 1 deletion api_tests/src/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ test("Requests with invalid auth should be treated as unauthenticated", async ()
});

test("Create user with Arabic name", async () => {
let user = await registerUser(alpha, alphaUrl, "تجريب");
let user = await registerUser(
alpha,
alphaUrl,
"تجريب" + Math.random().toString().slice(2, 10), // less than actor_name_max_length
);

let site = await getSite(user);
expect(site.my_user).toBeDefined();
Expand Down
Loading