mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
refactor(push): retire the push service delivery experiment (#3000)
This commit is contained in:
1 parent
2a9e25c788
commit
5b280898c5
83 files changed
+1882
-10066
No files matched your search
@@ -8,10 +8,7 @@ init_creates_tables_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
?assertNotEqual(undefined, ets:whereis(push_user_guild_settings)),
|
||||
?assertNotEqual(undefined, ets:whereis(push_subscriptions)),
|
||||
?assertNotEqual(undefined, ets:whereis(push_blocked_ids)),
|
||||
?assertNotEqual(undefined, ets:whereis(push_badge_counts)),
|
||||
?assertNotEqual(undefined, ets:whereis(push_endpoint_verdicts)),
|
||||
cleanup_tables().
|
||||
|
||||
init_idempotent_test() ->
|
||||
@@ -31,16 +28,6 @@ user_guild_settings_test() ->
|
||||
?assertEqual(undefined, push_ets_cache:get_user_guild_settings(1, 2)),
|
||||
cleanup_tables().
|
||||
|
||||
subscriptions_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
?assertEqual(undefined, push_ets_cache:get_subscriptions(1)),
|
||||
ok = seed_subscriptions(1, [sub1, sub2]),
|
||||
?assertEqual([sub1, sub2], push_ets_cache:get_subscriptions(1)),
|
||||
ok = push_ets_cache:delete_subscriptions(1),
|
||||
?assertEqual(undefined, push_ets_cache:get_subscriptions(1)),
|
||||
cleanup_tables().
|
||||
|
||||
blocked_ids_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
@@ -49,46 +36,28 @@ blocked_ids_test() ->
|
||||
?assertEqual([2, 3], push_ets_cache:get_blocked_ids(1)),
|
||||
cleanup_tables().
|
||||
|
||||
badge_count_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
?assertEqual(undefined, push_ets_cache:get_badge_count(1)),
|
||||
ok = seed_badge_count(1, 5, 1000),
|
||||
?assertEqual({5, 1000}, push_ets_cache:get_badge_count(1)),
|
||||
ok = push_ets_cache:delete_badge_count(1),
|
||||
?assertEqual(undefined, push_ets_cache:get_badge_count(1)),
|
||||
cleanup_tables().
|
||||
|
||||
badge_count_keeps_fresher_timestamp_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
First = push_ets_cache:reserve_badge_counts([1]),
|
||||
ok = push_ets_cache:put_badge_count(1, 5, 2000, First),
|
||||
ok = push_ets_cache:put_badge_count(1, 9, 1000, First),
|
||||
?assertEqual({5, 2000}, push_ets_cache:get_badge_count(1)),
|
||||
ok = seed_badge_count(1, 7, 3000),
|
||||
?assertEqual({7, 3000}, push_ets_cache:get_badge_count(1)),
|
||||
ok = seed_badge_count(1, 8, 3000),
|
||||
?assertEqual({8, 3000}, push_ets_cache:get_badge_count(1)),
|
||||
cleanup_tables().
|
||||
|
||||
cache_stats_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
ok = seed_subscriptions(1, []),
|
||||
ok = seed_subscriptions(2, []),
|
||||
ok = push_ets_cache:put_blocked_ids(1, []),
|
||||
ok = push_ets_cache:put_blocked_ids(2, []),
|
||||
Stats = push_ets_cache:cache_stats(),
|
||||
?assertEqual(2, maps:get(push_subscriptions_size, Stats)),
|
||||
?assertEqual(0, maps:get(user_guild_settings_size, Stats)),
|
||||
?assertEqual(
|
||||
#{blocked_ids_size => 2, user_guild_settings_size => 0},
|
||||
Stats
|
||||
),
|
||||
cleanup_tables().
|
||||
|
||||
evict_tables_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
lists:foreach(fun(I) -> ok = seed_subscriptions(I, []) end, lists:seq(1, 10)),
|
||||
?assertEqual(10, push_ets_cache:table_size(push_subscriptions)),
|
||||
ok = push_ets_cache:evict_tables(#{subscriptions => 5}),
|
||||
?assertEqual(5, push_ets_cache:table_size(push_subscriptions)),
|
||||
lists:foreach(
|
||||
fun(I) -> ok = push_ets_cache:put_user_guild_settings(I, 1, #{}) end,
|
||||
lists:seq(1, 10)
|
||||
),
|
||||
?assertEqual(10, push_ets_cache:table_size(push_user_guild_settings)),
|
||||
ok = push_ets_cache:evict_tables(#{user_guild_settings => 5}),
|
||||
?assertEqual(5, push_ets_cache:table_size(push_user_guild_settings)),
|
||||
cleanup_tables().
|
||||
|
||||
rebalance_evicts_remote_owned_entries_test() ->
|
||||
@@ -100,92 +69,19 @@ rebalance_evicts_remote_owned_entries_test() ->
|
||||
RoleMap = #{push => Members, all => Members},
|
||||
persistent_term:put({gateway_cluster_membership, members}, Members),
|
||||
persistent_term:put({gateway_cluster_membership, members_by_role}, RoleMap),
|
||||
ok = seed_subscriptions(LocalUserId, [local]),
|
||||
ok = seed_subscriptions(RemoteUserId, [remote]),
|
||||
ok = push_ets_cache:put_blocked_ids(LocalUserId, [1]),
|
||||
ok = push_ets_cache:put_blocked_ids(RemoteUserId, [2]),
|
||||
ok = push_ets_cache:put_user_guild_settings(LocalUserId, 10, #{local => true}),
|
||||
ok = push_ets_cache:put_user_guild_settings(RemoteUserId, 10, #{remote => true}),
|
||||
ok = push_ets_cache:rebalance(),
|
||||
?assertEqual([local], push_ets_cache:get_subscriptions(LocalUserId)),
|
||||
?assertEqual(undefined, push_ets_cache:get_subscriptions(RemoteUserId)),
|
||||
?assertEqual([1], push_ets_cache:get_blocked_ids(LocalUserId)),
|
||||
?assertEqual(undefined, push_ets_cache:get_blocked_ids(RemoteUserId)),
|
||||
?assertEqual(#{local => true}, push_ets_cache:get_user_guild_settings(LocalUserId, 10)),
|
||||
?assertEqual(undefined, push_ets_cache:get_user_guild_settings(RemoteUserId, 10)),
|
||||
persistent_term:erase({gateway_cluster_membership, members}),
|
||||
persistent_term:erase({gateway_cluster_membership, members_by_role}),
|
||||
cleanup_tables().
|
||||
|
||||
endpoint_verdict_round_trip_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
?assertEqual(undefined, push_ets_cache:get_endpoint_verdict(<<"push.example.com">>)),
|
||||
ok = push_ets_cache:put_endpoint_verdict(<<"push.example.com">>, ok, 300),
|
||||
?assertEqual({ok, ok}, push_ets_cache:get_endpoint_verdict(<<"push.example.com">>)),
|
||||
ok = push_ets_cache:put_endpoint_verdict(
|
||||
<<"bad.example.com">>, {error, endpoint_blocked}, 30
|
||||
),
|
||||
?assertEqual(
|
||||
{ok, {error, endpoint_blocked}},
|
||||
push_ets_cache:get_endpoint_verdict(<<"bad.example.com">>)
|
||||
),
|
||||
cleanup_tables().
|
||||
|
||||
endpoint_verdicts_expire_and_are_reclaimed_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
ok = push_ets_cache:put_endpoint_verdict(<<"stale.example.com">>, ok, 300),
|
||||
Stale = erlang:system_time(second) - 1,
|
||||
true = ets:insert(push_endpoint_verdicts, {<<"stale.example.com">>, ok, Stale}),
|
||||
?assertEqual(undefined, push_ets_cache:get_endpoint_verdict(<<"stale.example.com">>)),
|
||||
ok = push_ets_cache:evict_tables(#{}),
|
||||
?assertEqual([], ets:lookup(push_endpoint_verdicts, <<"stale.example.com">>)),
|
||||
cleanup_tables().
|
||||
|
||||
an_oversized_host_is_never_cached_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
Oversized = binary:copy(<<"a">>, 254),
|
||||
ok = push_ets_cache:put_endpoint_verdict(Oversized, ok, 300),
|
||||
?assertEqual(undefined, push_ets_cache:get_endpoint_verdict(Oversized)),
|
||||
?assertEqual(0, push_ets_cache:table_size(push_endpoint_verdicts)),
|
||||
AtLimit = binary:copy(<<"a">>, 253),
|
||||
ok = push_ets_cache:put_endpoint_verdict(AtLimit, ok, 300),
|
||||
?assertEqual({ok, ok}, push_ets_cache:get_endpoint_verdict(AtLimit)),
|
||||
cleanup_tables().
|
||||
|
||||
endpoint_verdicts_stay_bounded_under_max_length_hosts_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
lists:foreach(fun seed_max_length_verdict/1, lists:seq(1, 20000)),
|
||||
Size = push_ets_cache:table_size(push_endpoint_verdicts),
|
||||
?assert(Size >= 1500),
|
||||
?assert(Size =< 2048),
|
||||
Bytes = ets:info(push_endpoint_verdicts, memory) * erlang:system_info(wordsize),
|
||||
?assert(Bytes =< 4 * 1024 * 1024),
|
||||
cleanup_tables().
|
||||
|
||||
seed_max_length_verdict(N) ->
|
||||
Suffix = integer_to_binary(N),
|
||||
Host = <<(binary:copy(<<"a">>, 253 - byte_size(Suffix)))/binary, Suffix/binary>>,
|
||||
ok = push_ets_cache:put_endpoint_verdict(Host, ok, 300),
|
||||
?assert(push_ets_cache:table_size(push_endpoint_verdicts) =< 2048).
|
||||
|
||||
endpoint_verdicts_are_reported_in_cache_stats_test() ->
|
||||
cleanup_tables(),
|
||||
ok = push_ets_cache:init(),
|
||||
ok = push_ets_cache:put_endpoint_verdict(<<"push.example.com">>, ok, 300),
|
||||
Stats = push_ets_cache:cache_stats(),
|
||||
?assertEqual(1, maps:get(endpoint_verdicts_size, Stats)),
|
||||
cleanup_tables().
|
||||
|
||||
seed_subscriptions(UserId, Subscriptions) ->
|
||||
push_ets_cache:put_subscriptions(
|
||||
UserId, Subscriptions, push_ets_cache:reserve_subscriptions([UserId])
|
||||
).
|
||||
|
||||
seed_badge_count(UserId, Count, CachedAt) ->
|
||||
push_ets_cache:put_badge_count(
|
||||
UserId, Count, CachedAt, push_ets_cache:reserve_badge_counts([UserId])
|
||||
).
|
||||
|
||||
find_split_user_ids(Members, RemoteNode) ->
|
||||
Local =
|
||||
hd([
|
||||
@@ -203,11 +99,7 @@ find_split_user_ids(Members, RemoteNode) ->
|
||||
|
||||
cleanup_tables() ->
|
||||
delete_table(push_user_guild_settings),
|
||||
delete_table(push_subscriptions),
|
||||
delete_table(push_blocked_ids),
|
||||
delete_table(push_badge_counts),
|
||||
delete_table(push_bearer_tokens),
|
||||
delete_table(push_endpoint_verdicts),
|
||||
ok.
|
||||
|
||||
delete_table(Table) ->
|
||||
|
||||
Reference in new issue
Block a user