Fix/1019 correct count remote users
This commit is contained in:
parent
4948117fcf
commit
d6b0fce6e9
16 changed files with 564 additions and 7 deletions
104
test/user/synchronization_test.exs
Normal file
104
test/user/synchronization_test.exs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.User.SynchronizationTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.User
|
||||
alias Pleroma.User.Synchronization
|
||||
|
||||
setup do
|
||||
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "update following/followers counters" do
|
||||
user1 =
|
||||
insert(:user,
|
||||
local: false,
|
||||
ap_id: "http://localhost:4001/users/masto_closed"
|
||||
)
|
||||
|
||||
user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
|
||||
|
||||
users = User.external_users()
|
||||
assert length(users) == 2
|
||||
{user, %{}} = Synchronization.call(users, %{})
|
||||
assert user == List.last(users)
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 437
|
||||
assert following == 152
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 527
|
||||
assert following == 267
|
||||
end
|
||||
|
||||
test "don't check host if errors exist" do
|
||||
user1 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser1")
|
||||
|
||||
user2 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser2")
|
||||
|
||||
users = User.external_users()
|
||||
assert length(users) == 2
|
||||
|
||||
{user, %{"domain-with-errors" => 2}} =
|
||||
Synchronization.call(users, %{"domain-with-errors" => 2}, max_retries: 2)
|
||||
|
||||
assert user == List.last(users)
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
end
|
||||
|
||||
test "don't check host if errors appeared" do
|
||||
user1 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser1")
|
||||
|
||||
user2 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser2")
|
||||
|
||||
users = User.external_users()
|
||||
assert length(users) == 2
|
||||
|
||||
{user, %{"domain-with-errors" => 2}} = Synchronization.call(users, %{}, max_retries: 2)
|
||||
|
||||
assert user == List.last(users)
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
end
|
||||
|
||||
test "other users after error appeared" do
|
||||
user1 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser1")
|
||||
user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
|
||||
|
||||
users = User.external_users()
|
||||
assert length(users) == 2
|
||||
|
||||
{user, %{"domain-with-errors" => 2}} = Synchronization.call(users, %{}, max_retries: 2)
|
||||
assert user == List.last(users)
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 0
|
||||
assert following == 0
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 527
|
||||
assert following == 267
|
||||
end
|
||||
end
|
||||
49
test/user/synchronization_worker_test.exs
Normal file
49
test/user/synchronization_worker_test.exs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.User.SynchronizationWorkerTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config = Pleroma.Config.get([:instance, :external_user_synchronization])
|
||||
|
||||
for_update = [enabled: true, interval: 1000]
|
||||
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], for_update)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], config)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "sync follow counters" do
|
||||
user1 =
|
||||
insert(:user,
|
||||
local: false,
|
||||
ap_id: "http://localhost:4001/users/masto_closed"
|
||||
)
|
||||
|
||||
user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
|
||||
|
||||
{:ok, _} = Pleroma.User.SynchronizationWorker.start_link()
|
||||
:timer.sleep(1500)
|
||||
|
||||
%{follower_count: followers, following_count: following} =
|
||||
Pleroma.User.get_cached_user_info(user1)
|
||||
|
||||
assert followers == 437
|
||||
assert following == 152
|
||||
|
||||
%{follower_count: followers, following_count: following} =
|
||||
Pleroma.User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 527
|
||||
assert following == 267
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue