Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oltarasenko/52056e50f3e1243811195b2e90c57162 to your computer and use it in GitHub Desktop.
Save oltarasenko/52056e50f3e1243811195b2e90c57162 to your computer and use it in GitHub Desktop.
{"Multiline for long messages", {timeout, 190 ,fun() ->
meck:expect(gen_tcp, recv, fun(_, _, _) -> {ok, <<"+OK POP3 ready">>} end),
Opts = [{addr, "pop.gmail.com"}, {port, 995}],
{ok, Connection} = epop_client:connect("test@example.com", "foo", Opts, 1000),
% Creating 1Kb chunk
Chunk = << <<"X">> || X <- lists:seq(1, 1 * 1000) >>,
% Generating a 10 Mb binary
Msgs = [{ok, <<"+OK Some">>}] ++ [{ok, Chunk} || _X <- lists:seq(1, 10 * 1000)] ++ [{ok, <<"\r\n.\r\n">>}],
?debugMsg("List generated"),
Loop = meck:loop(Msgs),
meck:expect(gen_tcp, recv, 3, Loop),
FullMsg = lists:foldl(
fun({ok, Msg}, Acc) -> <<Acc/binary, Msg/binary>> end,
<<>>, Msgs
),
<<"+OK ", ExpectedMsg/binary>> = FullMsg,
?debugFmt("ExpectedMsg size: ~p", [byte_size(ExpectedMsg)]),
{Time, _} = timer:tc(fun() -> epop_client:retrieve(Connection, <<"1">>) end),
% ?debugFmt("Call time large email: ~p", [Time])
% Entire processing time should not take more then 5 seconds
?debugFmt("Time: ~p", [Time]),
?assert(Time < 100 * 1000 * 1000)
end}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment