25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Improve stream management tests

This commit is contained in:
Evgeniy Khramtsov 2017-02-21 09:19:51 +03:00
parent adbd174959
commit e11bcf9c43

View File

@ -50,21 +50,22 @@ feature_enabled(Config) ->
enable(Config) -> enable(Config) ->
Server = ?config(server, Config), Server = ?config(server, Config),
ServerJID = jid:make(<<"">>, Server, <<"">>), ServerJID = jid:make(<<"">>, Server, <<"">>),
%% Send messages of type 'headline' so the server discards them silently ct:comment("Send messages of type 'headline' so the server discards them silently"),
Msg = #message{to = ServerJID, type = headline, Msg = #message{to = ServerJID, type = headline,
body = [#text{data = <<"body">>}]}, body = [#text{data = <<"body">>}]},
%% Enable the session management with resumption enabled ct:comment("Enable the session management with resumption enabled"),
send(Config, #sm_enable{resume = true, xmlns = ?NS_STREAM_MGMT_3}), send(Config, #sm_enable{resume = true, xmlns = ?NS_STREAM_MGMT_3}),
#sm_enabled{id = ID, resume = true} = recv(Config), #sm_enabled{id = ID, resume = true} = recv(Config),
%% Initial request; 'h' should be 0. ct:comment("Initial request; 'h' should be 0"),
send(Config, #sm_r{xmlns = ?NS_STREAM_MGMT_3}), send(Config, #sm_r{xmlns = ?NS_STREAM_MGMT_3}),
#sm_a{h = 0} = recv(Config), #sm_a{h = 0} = recv(Config),
%% sending two messages and requesting again; 'h' should be 3. ct:comment("Sending two messages and requesting again; 'h' should be 3"),
send(Config, Msg), send(Config, Msg),
send(Config, Msg), send(Config, Msg),
send(Config, Msg), send(Config, Msg),
send(Config, #sm_r{xmlns = ?NS_STREAM_MGMT_3}), send(Config, #sm_r{xmlns = ?NS_STREAM_MGMT_3}),
#sm_a{h = 3} = recv(Config), #sm_a{h = 3} = recv(Config),
ct:comment("Closing socket"),
close_socket(Config), close_socket(Config),
{save_config, set_opt(sm_previd, ID, Config)}. {save_config, set_opt(sm_previd, ID, Config)}.
@ -76,22 +77,30 @@ resume(Config) ->
MyJID = my_jid(Config), MyJID = my_jid(Config),
Txt = #text{data = <<"body">>}, Txt = #text{data = <<"body">>},
Msg = #message{from = ServerJID, to = MyJID, body = [Txt]}, Msg = #message{from = ServerJID, to = MyJID, body = [Txt]},
%% Route message. The message should be queued by the C2S process. ct:comment("Route message. The message should be queued by the C2S process"),
ejabberd_router:route(Msg), ejabberd_router:route(Msg),
ct:comment("Resuming the session"),
send(Config, #sm_resume{previd = ID, h = 0, xmlns = ?NS_STREAM_MGMT_3}), send(Config, #sm_resume{previd = ID, h = 0, xmlns = ?NS_STREAM_MGMT_3}),
#sm_resumed{previd = ID, h = 3} = recv(Config), #sm_resumed{previd = ID, h = 3} = recv(Config),
ct:comment("Receiving unacknowledged stanza"),
#message{from = ServerJID, to = MyJID, body = [Txt]} = recv_message(Config), #message{from = ServerJID, to = MyJID, body = [Txt]} = recv_message(Config),
#sm_r{} = recv(Config), #sm_r{} = recv(Config),
send(Config, #sm_a{h = 1, xmlns = ?NS_STREAM_MGMT_3}), send(Config, #sm_a{h = 1, xmlns = ?NS_STREAM_MGMT_3}),
%% Send another stanza to increment the server's 'h' for sm_resume_failed. ct:comment("Checking if the server counts stanzas correctly"),
send(Config, #sm_r{xmlns = ?NS_STREAM_MGMT_3}),
#sm_a{h = 3} = recv(Config),
ct:comment("Send another stanza to increment the server's 'h' for sm_resume_failed"),
send(Config, #presence{to = ServerJID}), send(Config, #presence{to = ServerJID}),
ct:comment("Closing socket"),
close_socket(Config), close_socket(Config),
{save_config, set_opt(sm_previd, ID, Config)}. {save_config, set_opt(sm_previd, ID, Config)}.
resume_failed(Config) -> resume_failed(Config) ->
{_, SMConfig} = ?config(saved_config, Config), {_, SMConfig} = ?config(saved_config, Config),
ID = ?config(sm_previd, SMConfig), ID = ?config(sm_previd, SMConfig),
ct:sleep(5000), % Wait for session to time out. ct:comment("Waiting for the session to time out"),
ct:sleep(5000),
ct:comment("Trying to resume timed out session"),
send(Config, #sm_resume{previd = ID, h = 1, xmlns = ?NS_STREAM_MGMT_3}), send(Config, #sm_resume{previd = ID, h = 1, xmlns = ?NS_STREAM_MGMT_3}),
#sm_failed{reason = 'item-not-found', h = 4} = recv(Config), #sm_failed{reason = 'item-not-found', h = 4} = recv(Config),
disconnect(Config). disconnect(Config).