CSI test: Simplify and improve readability

This commit is contained in:
Holger Weiss 2015-04-16 23:20:14 +02:00
parent 01b3defb86
commit b447839592
1 changed files with 21 additions and 20 deletions

View File

@ -1570,42 +1570,38 @@ carbons_slave(Config) ->
disconnect(Config). disconnect(Config).
client_state_master(Config) -> client_state_master(Config) ->
true = ?config(csi, Config),
Peer = ?config(slave, Config), Peer = ?config(slave, Config),
Presence = #presence{to = Peer}, Presence = #presence{to = Peer},
Message = #message{to = Peer, thread = <<"1">>, ChatState = #message{to = Peer, thread = <<"1">>,
sub_els = [#chatstate{type = active}]}, sub_els = [#chatstate{type = active}]},
Message = ChatState#message{body = [#text{data = <<"body">>}]},
%% Wait for the slave to become inactive.
wait_for_slave(Config), wait_for_slave(Config),
%% Should be dropped: %% Should be dropped:
send(Config, Message), send(Config, ChatState),
%% Should be queued (but see below): %% Should be queued (but see below):
send(Config, Presence#presence{type = unavailable}),
%% Should replace the previous presence in the queue:
send(Config, Presence), send(Config, Presence),
%% Should be sent immediately, together with the previous presence: %% Should replace the previous presence in the queue:
send(Config, Message#message{body = [#text{data = <<"body">>}]}),
%% Should be queued:
send(Config, Presence#presence{type = unavailable}), send(Config, Presence#presence{type = unavailable}),
%% Should be sent immediately, together with the previous presence:
send(Config, Message),
%% Wait for the slave to become active. %% Wait for the slave to become active.
wait_for_slave(Config), wait_for_slave(Config),
%% Should be sent immediately, as the client is active again. %% Should be delivered, as the client is active again:
send(Config, Message), send(Config, ChatState),
disconnect(Config). disconnect(Config).
client_state_slave(Config) -> client_state_slave(Config) ->
true = ?config(csi, Config),
Peer = ?config(master, Config), Peer = ?config(master, Config),
send(Config, #csi{type = inactive}), change_client_state(Config, inactive),
send_recv(
Config,
#iq{type = get, sub_els = [#ping{}], to = server_jid(Config)}),
wait_for_master(Config), wait_for_master(Config),
?recv1(#presence{from = Peer, sub_els = [#vcard_xupdate{}|_]}),
?recv1(#message{from = Peer, thread = <<"1">>, sub_els = [#chatstate{type = active}],
body = [#text{data = <<"body">>}]}),
send(Config, #csi{type = active}),
%% The server now flushes the queue, so we receive the following presence.
?recv1(#presence{from = Peer, type = unavailable, ?recv1(#presence{from = Peer, type = unavailable,
sub_els = [#delay{}, #legacy_delay{}]}), sub_els = [#delay{}, #legacy_delay{}]}),
?recv1(#message{from = Peer, thread = <<"1">>,
body = [#text{data = <<"body">>}],
sub_els = [#chatstate{type = active}]}),
change_client_state(Config, active),
wait_for_master(Config), wait_for_master(Config),
?recv1(#message{from = Peer, thread = <<"1">>, ?recv1(#message{from = Peer, thread = <<"1">>,
sub_els = [#chatstate{type = active}]}), sub_els = [#chatstate{type = active}]}),
@ -1614,6 +1610,11 @@ client_state_slave(Config) ->
%%%=================================================================== %%%===================================================================
%%% Aux functions %%% Aux functions
%%%=================================================================== %%%===================================================================
change_client_state(Config, NewState) ->
send(Config, #csi{type = NewState}),
send_recv(Config, #iq{type = get, to = server_jid(Config),
sub_els = [#ping{}]}).
bookmark_conference() -> bookmark_conference() ->
#bookmark_conference{name = <<"Some name">>, #bookmark_conference{name = <<"Some name">>,
autojoin = true, autojoin = true,