25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Improve private and MAM tests in order to reflect

database backends with limited capabilities
This commit is contained in:
Evgeny Khramtsov 2019-01-14 19:33:23 +03:00
parent 1b0d481f41
commit 63259f5cc9
2 changed files with 51 additions and 27 deletions

View File

@ -377,7 +377,7 @@ recv_fin(Config, I, QueryID, NS, IsComplete) when NS == ?NS_MAM_1; NS == ?NS_MAM
complete = Complete, complete = Complete,
rsm = RSM}]} = recv_iq(Config), rsm = RSM}]} = recv_iq(Config),
ct:comment("Checking if complete is ~s", [IsComplete]), ct:comment("Checking if complete is ~s", [IsComplete]),
Complete = IsComplete, ?match(IsComplete, Complete),
RSM; RSM;
recv_fin(Config, I, QueryID, ?NS_MAM_TMP = NS, _IsComplete) -> recv_fin(Config, I, QueryID, ?NS_MAM_TMP = NS, _IsComplete) ->
ct:comment("Receiving fin iq for namespace '~s'", [NS]), ct:comment("Receiving fin iq for namespace '~s'", [NS]),
@ -394,7 +394,7 @@ recv_fin(Config, _, QueryID, ?NS_MAM_0 = NS, IsComplete) ->
complete = Complete, complete = Complete,
rsm = RSM} = xmpp:get_subtag(FinMsg, #mam_fin{xmlns = NS}), rsm = RSM} = xmpp:get_subtag(FinMsg, #mam_fin{xmlns = NS}),
ct:comment("Checking if complete is ~s", [IsComplete]), ct:comment("Checking if complete is ~s", [IsComplete]),
Complete = IsComplete, ?match(IsComplete, Complete),
RSM. RSM.
send_messages_to_room(Config, Range) -> send_messages_to_room(Config, Range) ->
@ -417,7 +417,6 @@ recv_messages_from_room(Config, Range) ->
MyNickJID = jid:replace_resource(Room, MyNick), MyNickJID = jid:replace_resource(Room, MyNick),
MyJID = my_jid(Config), MyJID = my_jid(Config),
QID = p1_rand:get_string(), QID = p1_rand:get_string(),
Count = length(Range),
I = send(Config, #iq{type = set, to = Room, I = send(Config, #iq{type = set, to = Room,
sub_els = [#mam_query{xmlns = ?NS_MAM_2, id = QID}]}), sub_els = [#mam_query{xmlns = ?NS_MAM_2, id = QID}]}),
lists:foreach( lists:foreach(
@ -440,8 +439,9 @@ recv_messages_from_room(Config, Range) ->
#iq{from = Room, id = I, type = result, #iq{from = Room, id = I, type = result,
sub_els = [#mam_fin{xmlns = ?NS_MAM_2, sub_els = [#mam_fin{xmlns = ?NS_MAM_2,
id = QID, id = QID,
rsm = #rsm_set{count = Count}, rsm = RSM,
complete = true}]} = recv_iq(Config). complete = true}]} = recv_iq(Config),
match_rsm_count(RSM, length(Range)).
query_all(Config, From, To) -> query_all(Config, From, To) ->
lists:foreach( lists:foreach(
@ -454,7 +454,8 @@ query_all(Config, From, To, NS) ->
Range = lists:seq(1, 5), Range = lists:seq(1, 5),
ID = send_query(Config, #mam_query{xmlns = NS, id = QID}), ID = send_query(Config, #mam_query{xmlns = NS, id = QID}),
recv_archived_messages(Config, From, To, QID, Range), recv_archived_messages(Config, From, To, QID, Range),
#rsm_set{count = 5} = recv_fin(Config, ID, QID, NS, _Complete = true). RSM = recv_fin(Config, ID, QID, NS, _Complete = true),
match_rsm_count(RSM, 5).
query_with(Config, From, To) -> query_with(Config, From, To) ->
lists:foreach( lists:foreach(
@ -480,7 +481,8 @@ query_with(Config, From, To, NS) ->
end, end,
ID = send_query(Config, Query), ID = send_query(Config, Query),
recv_archived_messages(Config, From, To, QID, Range), recv_archived_messages(Config, From, To, QID, Range),
#rsm_set{count = 5} = recv_fin(Config, ID, QID, NS, true) RSM = recv_fin(Config, ID, QID, NS, true),
match_rsm_count(RSM, 5)
end, [Peer, BarePeer]). end, [Peer, BarePeer]).
query_rsm_max(Config, From, To) -> query_rsm_max(Config, From, To) ->
@ -498,7 +500,8 @@ query_rsm_max(Config, From, To, NS) ->
ID = send_query(Config, Query), ID = send_query(Config, Query),
recv_archived_messages(Config, From, To, QID, Range), recv_archived_messages(Config, From, To, QID, Range),
IsComplete = Max >= 5, IsComplete = Max >= 5,
#rsm_set{count = 5} = recv_fin(Config, ID, QID, NS, IsComplete) RSM = recv_fin(Config, ID, QID, NS, IsComplete),
match_rsm_count(RSM, 5)
end, lists:seq(0, 6)). end, lists:seq(0, 6)).
query_rsm_after(Config, From, To) -> query_rsm_after(Config, From, To) ->
@ -517,8 +520,9 @@ query_rsm_after(Config, From, To, NS) ->
rsm = #rsm_set{'after' = After}}, rsm = #rsm_set{'after' = After}},
ID = send_query(Config, Query), ID = send_query(Config, Query),
recv_archived_messages(Config, From, To, QID, Range), recv_archived_messages(Config, From, To, QID, Range),
#rsm_set{count = 5, first = First} = RSM = #rsm_set{first = First} =
recv_fin(Config, ID, QID, NS, true), recv_fin(Config, ID, QID, NS, true),
match_rsm_count(RSM, 5),
First First
end, #rsm_first{data = undefined}, end, #rsm_first{data = undefined},
[lists:seq(N, 5) || N <- lists:seq(1, 6)]). [lists:seq(N, 5) || N <- lists:seq(1, 6)]).
@ -539,7 +543,15 @@ query_rsm_before(Config, From, To, NS) ->
rsm = #rsm_set{before = Before}}, rsm = #rsm_set{before = Before}},
ID = send_query(Config, Query), ID = send_query(Config, Query),
recv_archived_messages(Config, From, To, QID, Range), recv_archived_messages(Config, From, To, QID, Range),
#rsm_set{count = 5, last = Last} = RSM = #rsm_set{last = Last} =
recv_fin(Config, ID, QID, NS, true), recv_fin(Config, ID, QID, NS, true),
match_rsm_count(RSM, 5),
Last Last
end, <<"">>, lists:reverse([lists:seq(1, N) || N <- lists:seq(0, 5)])). end, <<"">>, lists:reverse([lists:seq(1, N) || N <- lists:seq(0, 5)])).
match_rsm_count(#rsm_set{count = undefined}, _) ->
%% The backend doesn't support counting
ok;
match_rsm_count(#rsm_set{count = Count1}, Count2) ->
ct:comment("Checking if RSM 'count' is ~p", [Count2]),
?match(Count2, Count1).

View File

@ -24,7 +24,7 @@
%% API %% API
-compile(export_all). -compile(export_all).
-import(suite, [my_jid/1, is_feature_advertised/3, -import(suite, [my_jid/1, server_jid/1, is_feature_advertised/3,
send_recv/2, disconnect/1]). send_recv/2, disconnect/1]).
-include("suite.hrl"). -include("suite.hrl").
@ -43,9 +43,15 @@ single_cases() ->
single_test(test_published)]}. single_test(test_published)]}.
test_features(Config) -> test_features(Config) ->
Server = jid:encode(server_jid(Config)),
MyJID = my_jid(Config), MyJID = my_jid(Config),
true = is_feature_advertised(Config, ?NS_BOOKMARKS_CONVERSION_0, case gen_mod:is_loaded(Server, mod_pubsub) of
jid:remove_resource(MyJID)), true ->
true = is_feature_advertised(Config, ?NS_BOOKMARKS_CONVERSION_0,
jid:remove_resource(MyJID));
false ->
ok
end,
disconnect(Config). disconnect(Config).
test_no_namespace(Config) -> test_no_namespace(Config) ->
@ -73,20 +79,26 @@ test_set_get(Config) ->
disconnect(Config). disconnect(Config).
test_published(Config) -> test_published(Config) ->
Storage = bookmark_storage(), Server = jid:encode(server_jid(Config)),
Node = xmpp:get_ns(Storage), case gen_mod:is_loaded(Server, mod_pubsub) of
#iq{type = result, true ->
sub_els = [#pubsub{items = #ps_items{node = Node, items = Items}}]} = Storage = bookmark_storage(),
send_recv( Node = xmpp:get_ns(Storage),
Config, #iq{type = result,
#iq{type = get, sub_els = [#pubsub{items = #ps_items{node = Node, items = Items}}]} =
sub_els = [#pubsub{items = #ps_items{node = Node}}]}), send_recv(
[#ps_item{sub_els = [StorageXMLIn]}] = Items, Config,
Storage = xmpp:decode(StorageXMLIn), #iq{type = get,
#iq{type = result, sub_els = []} = sub_els = [#pubsub{items = #ps_items{node = Node}}]}),
send_recv(Config, [#ps_item{sub_els = [StorageXMLIn]}] = Items,
#iq{type = set, Storage = xmpp:decode(StorageXMLIn),
sub_els = [#pubsub_owner{delete = {Node, <<>>}}]}), #iq{type = result, sub_els = []} =
send_recv(Config,
#iq{type = set,
sub_els = [#pubsub_owner{delete = {Node, <<>>}}]});
false ->
ok
end,
disconnect(Config). disconnect(Config).
%%%=================================================================== %%%===================================================================