<commit_before>%%
%% %CopyrightBegin%
%% 
%% Copyright Ericsson AB 2004-2017. All Rights Reserved.
%% 
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%% 
%% %CopyrightEnd%
%%
%%

%% 
%% ct:run("../inets_test", httpc_SUITE).
%%

-module(httpc_SUITE).

-include_lib("kernel/include/file.hrl").
-include_lib("common_test/include/ct.hrl").
-include("inets_test_lib.hrl").
-include("http_internal.hrl").
-include("httpc_internal.hrl").
%% Note: This directive should only be used in test suites.
-compile(export_all).

-define(URL_START, "http://").
-define(TLS_URL_START, "https://").
-define(NOT_IN_USE_PORT, 8997).

-record(sslsocket, {fd = nil, pid = nil}).
%%--------------------------------------------------------------------
%% Common Test interface functions -----------------------------------
%%--------------------------------------------------------------------
suite() ->
    [{ct_hooks,[ts_install_cth]}
    ].

all() ->
    [
     {group, http},
     {group, sim_http},
     {group, https},
     {group, sim_https},
     {group, misc}
    ].

groups() ->
    [
     {http, [], real_requests()},
     {sim_http, [], only_simulated()},
     {https, [], real_requests()},
     {sim_https, [], only_simulated()},
     {misc, [], misc()}
    ].

real_requests()->
    [
     head,
     get,
     post,
     delete,
     post_stream,
     patch,
     async,
     pipeline,
     persistent_connection,
     save_to_file,
     save_to_file_async,
     headers_as_is,
     page_does_not_exist,
     emulate_lower_versions,
     headers,
     headers_as_is,
     empty_body,
     stream,
     stream_to_pid,
     stream_through_fun,
     stream_through_mfa,
     streaming_error,
     inet_opts,
     invalid_headers,
     invalid_body
    ].

only_simulated() ->
    [
     cookie,
     cookie_profile,
     empty_set_cookie,
     invalid_set_cookie,
     trace,
     stream_once,
     stream_single_chunk,
     stream_no_length,
     not_streamed_once,
     stream_large_not_200_or_206,
     no_content_204,
     tolerate_missing_CR,
     userinfo,
     bad_response,
     timeout_redirect,
     internal_server_error,
     invalid_http,
     invalid_chunk_size,
     headers_dummy,
     headers_with_obs_fold,
     empty_response_header,
     remote_socket_close,
     remote_socket_close_async,
     process_leak_on_keepalive,
     transfer_encoding,
     transfer_encoding_identity,
     redirect_loop,
     redirect_moved_permanently,
     redirect_multiple_choises,
     redirect_found,
     redirect_see_other,
     redirect_temporary_redirect,
     port_in_host_header,
     redirect_port_in_host_header,
     relaxed,
     multipart_chunks
    ].

misc() ->
    [
     server_does_not_exist,
     timeout_memory_leak,
     wait_for_whole_response
    ].

%%--------------------------------------------------------------------

init_per_suite(Config) ->
    ct:timetrap({seconds, 30}),
    PrivDir = proplists:get_value(priv_dir, Config),
    DataDir = proplists:get_value(data_dir, Config),
    inets_test_lib:start_apps([inets]),
    ServerRoot = filename:join(PrivDir, "server_root"),
    DocRoot = filename:join(ServerRoot, "htdocs"),
    setup_server_dirs(ServerRoot, DocRoot, DataDir),
    [{server_root, ServerRoot}, {doc_root, DocRoot}  | Config].

end_per_suite(Config) ->
    inets_test_lib:stop_apps([inets]),
    PrivDir = proplists:get_value(priv_dir, Config),
    inets_test_lib:del_dirs(PrivDir),
    ok.

%%--------------------------------------------------------------------
init_per_group(misc = Group, Config) ->
    start_apps(Group),
    Inet = inet_version(),
    ok = httpc:set_options([{ipfamily, Inet}]),
    Config;


init_per_group(Group, Config0) when Group =:= sim_https; Group =:= https->
    catch crypto:stop(),
    try crypto:start() of
        ok ->
            ct:timetrap({seconds, 30}),
            start_apps(Group),
            do_init_per_group(Group, Config0)
    catch
        _:_ ->
            {skip, "Crypto did not start"}
    end;

init_per_group(Group, Config0) ->
    start_apps(Group),
    Config = proplists:delete(port, Config0),
    Port = server_start(Group, server_config(Group, Config)),
    [{port, Port} | Config].

end_per_group(_, _Config) ->
    ok.
do_init_per_group(Group, Config0) ->
    Config = proplists:delete(port, Config0),
    Port = server_start(Group, server_config(Group, Config)),
    [{port, Port} | Config].<commit_msg>inets: httpc - fix default timeout in httpc_SUITE<commit_after>%%
%% %CopyrightBegin%
%% 
%% Copyright Ericsson AB 2004-2017. All Rights Reserved.
%% 
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%% 
%% %CopyrightEnd%
%%
%%

%% 
%% ct:run("../inets_test", httpc_SUITE).
%%

-module(httpc_SUITE).

-include_lib("kernel/include/file.hrl").
-include_lib("common_test/include/ct.hrl").
-include("inets_test_lib.hrl").
-include("http_internal.hrl").
-include("httpc_internal.hrl").
%% Note: This directive should only be used in test suites.
-compile(export_all).

-define(URL_START, "http://").
-define(TLS_URL_START, "https://").
-define(NOT_IN_USE_PORT, 8997).

-record(sslsocket, {fd = nil, pid = nil}).
%%--------------------------------------------------------------------
%% Common Test interface functions -----------------------------------
%%--------------------------------------------------------------------
suite() ->
    [{ct_hooks,[ts_install_cth]},
     {timetrap,{seconds, 30}}
    ].

all() ->
    [
     {group, http},
     {group, sim_http},
     {group, https},
     {group, sim_https},
     {group, misc}
    ].

groups() ->
    [
     {http, [], real_requests()},
     {sim_http, [], only_simulated()},
     {https, [], real_requests()},
     {sim_https, [], only_simulated()},
     {misc, [], misc()}
    ].

real_requests()->
    [
     head,
     get,
     post,
     delete,
     post_stream,
     patch,
     async,
     pipeline,
     persistent_connection,
     save_to_file,
     save_to_file_async,
     headers_as_is,
     page_does_not_exist,
     emulate_lower_versions,
     headers,
     headers_as_is,
     empty_body,
     stream,
     stream_to_pid,
     stream_through_fun,
     stream_through_mfa,
     streaming_error,
     inet_opts,
     invalid_headers,
     invalid_body
    ].

only_simulated() ->
    [
     cookie,
     cookie_profile,
     empty_set_cookie,
     invalid_set_cookie,
     trace,
     stream_once,
     stream_single_chunk,
     stream_no_length,
     not_streamed_once,
     stream_large_not_200_or_206,
     no_content_204,
     tolerate_missing_CR,
     userinfo,
     bad_response,
     timeout_redirect,
     internal_server_error,
     invalid_http,
     invalid_chunk_size,
     headers_dummy,
     headers_with_obs_fold,
     empty_response_header,
     remote_socket_close,
     remote_socket_close_async,
     process_leak_on_keepalive,
     transfer_encoding,
     transfer_encoding_identity,
     redirect_loop,
     redirect_moved_permanently,
     redirect_multiple_choises,
     redirect_found,
     redirect_see_other,
     redirect_temporary_redirect,
     port_in_host_header,
     redirect_port_in_host_header,
     relaxed,
     multipart_chunks
    ].

misc() ->
    [
     server_does_not_exist,
     timeout_memory_leak,
     wait_for_whole_response
    ].

%%--------------------------------------------------------------------

init_per_suite(Config) ->
    PrivDir = proplists:get_value(priv_dir, Config),
    DataDir = proplists:get_value(data_dir, Config),
    inets_test_lib:start_apps([inets]),
    ServerRoot = filename:join(PrivDir, "server_root"),
    DocRoot = filename:join(ServerRoot, "htdocs"),
    setup_server_dirs(ServerRoot, DocRoot, DataDir),
    [{server_root, ServerRoot}, {doc_root, DocRoot}  | Config].

end_per_suite(Config) ->
    inets_test_lib:stop_apps([inets]),
    PrivDir = proplists:get_value(priv_dir, Config),
    inets_test_lib:del_dirs(PrivDir),
    ok.

%%--------------------------------------------------------------------
init_per_group(misc = Group, Config) ->
    start_apps(Group),
    Inet = inet_version(),
    ok = httpc:set_options([{ipfamily, Inet}]),
    Config;


init_per_group(Group, Config0) when Group =:= sim_https; Group =:= https->
    catch crypto:stop(),
    try crypto:start() of
        ok ->
            start_apps(Group),
            do_init_per_group(Group, Config0)
    catch
        _:_ ->
            {skip, "Crypto did not start"}
    end;

init_per_group(Group, Config0) ->
    start_apps(Group),
    Config = proplists:delete(port, Config0),
    Port = server_start(Group, server_config(Group, Config)),
    [{port, Port} | Config].

end_per_group(_, _Config) ->
    ok.
do_init_per_group(Group, Config0) ->
    Config = proplists:delete(port, Config0),
    Port = server_start(Group, server_config(Group, Config)),
    [{port, Port} | Config].
{'fraction_non_alphanumeric': 0.1774407003970274, 'fraction_numerical': 0.006922528759034918, 'mean_word_length': 2.531272465851905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '99955', 'n_tokens_mistral': 3160, 'n_tokens_neox': 3100, 'n_words': 617}