Skip to content

Commit fc9ec1d

Browse files
seriypsCopilot
andcommitted
Upgrade ranch 1.7.0 → 2.2.0
Ranch 2.x breaking changes addressed: - Protocol callback changed from start_link/4 (Ref, Socket, Transport, Opts) to start_link/3 (Ref, Transport, Opts); socket obtained via ranch:handshake/1 - ranch:info/0 now returns #{Name => #{...}} instead of [{Name, [proplists]}]; updated mtp_listeners/0, running_ports/0, and config_change_case test Also update AGENTS.md with CT failure debugging workflow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 683732e commit fc9ec1d

7 files changed

Lines changed: 36 additions & 19 deletions

File tree

AGENTS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ Individual steps:
7979

8080
Always run `make test` before committing. Fix all xref warnings and dialyzer errors — they are treated as errors.
8181

82+
### Debugging CT failures
83+
84+
When `rebar3 ct` (or `make test`) reports failures, **do not rely on the terminal output** — it is truncated and shows only the last error. Instead, go straight to the HTML logs:
85+
86+
```
87+
_build/test/logs/ct_run.<timestamp>/lib.mtproto_proxy.logs/run.<timestamp>/
88+
```
89+
90+
Key files:
91+
- `suite.log` — machine-readable summary; `=case` lines show test order, `=result failed` shows which failed
92+
- `single_dc_suite.<test_name>.html` — full log for one test case (strip HTML tags to read: `sed 's/<[^>]*>//g'`)
93+
- `suite.log.html` / `index.html` — human-readable in a browser
94+
95+
Workflow:
96+
1. Run `make test` — note how many pass/fail
97+
2. Check `suite.log` for `=case` ordering and `=result failed` to identify the failing test
98+
3. Read that test's `.html` log for the full stacktrace and system reports
99+
4. Fix, then re-run `make test`. If tests still fail spuriously, try `rm -rf _build/test && make test` to clear stale test artifacts (removing only `_build/test` is faster than a full clean build).
100+
82101
## Code Style
83102

84103
- Language: **Erlang**. Follow standard Erlang OTP conventions.

rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% -*- mode: erlang -*-
22
{erl_opts, [debug_info]}.
33

4-
{deps, [{ranch, "1.7.0"},
4+
{deps, [{ranch, "2.2.0"},
55
{erlang_psq, {git, "https://github.com/seriyps/psq", {branch, "master"}}}
66
]}.
77
{project_plugins, [rebar3_proper,

rebar.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
{git,"https://github.com/seriyps/psq",
44
{ref,"46329ccb60f27d7d4c3f3643441ccef6c5f9c89c"}},
55
0},
6-
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.7.0">>},0}]}.
6+
{<<"ranch">>,{pkg,<<"ranch">>,<<"2.2.0">>},0}]}.
77
[
88
{pkg_hash,[
9-
{<<"ranch">>, <<"9583F47160CA62AF7F8D5DB11454068EAA32B56EEADF984D4F46E61A076DF5F2">>}]},
9+
{<<"ranch">>, <<"25528F82BC8D7C6152C57666CA99EC716510FE0925CB188172F41CE93117B1B0">>}]},
1010
{pkg_hash_ext,[
11-
{<<"ranch">>, <<"59F7501C3A56125B2FC5684C3048FAC9D043C0BF4D173941B12CA927949AF189">>}]}
11+
{<<"ranch">>, <<"FA0B99A1780C80218A4197A59EA8D3BDAE32FBFF7E88527D7D8A4787EFF4F8E7">>}]}
1212
].

src/mtp_handler.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
-behaviour(ranch_protocol).
1111

1212
%% API
13-
-export([start_link/4, send/2]).
13+
-export([start_link/3, send/2]).
1414
-export([hex/1, unhex/1]).
1515
-export([keys_str/0]).
1616

@@ -65,7 +65,7 @@
6565

6666
%% APIs
6767

68-
start_link(Ref, _Socket, Transport, Opts) ->
68+
start_link(Ref, Transport, Opts) ->
6969
{ok, proc_lib:spawn_link(?MODULE, ranch_init, [{Ref, Transport, Opts}])}.
7070

7171
keys_str() ->

src/mtproto_proxy_app.erl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,19 @@ diff_env(NewEnv, OldEnv) ->
9494
%% @doc List of ranch listeners running mtproto_proxy
9595
-spec mtp_listeners() -> [tuple()].
9696
mtp_listeners() ->
97-
lists:filter(
98-
fun({_Name, Opts}) ->
99-
proplists:get_value(protocol, Opts) == mtp_handler
100-
end,
101-
ranch:info()).
97+
maps:to_list(
98+
maps:filter(
99+
fun(_Name, #{protocol := Protocol}) ->
100+
Protocol == mtp_handler
101+
end,
102+
ranch:info())).
102103

103104

104105
%% @doc Currently running listeners in a form of proxy_port()
105106
-spec running_ports() -> [proxy_port()].
106107
running_ports() ->
107108
lists:map(
108-
fun({Name, Opts}) ->
109-
#{protocol_options := ProtoOpts,
110-
ip := Ip,
111-
port := Port} = maps:from_list(Opts),
109+
fun({Name, #{protocol_options := ProtoOpts, ip := Ip, port := Port}}) ->
112110
[Name, Secret, AdTag] = ProtoOpts,
113111
case inet:ntoa(Ip) of
114112
{error, einval} ->

test/mtp_test_middle_server.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-export([start/2,
77
stop/1,
88
get_rpc_handler_state/1]).
9-
-export([start_link/4,
9+
-export([start_link/3,
1010
ranch_init/1]).
1111
-export([init/1,
1212
callback_mode/0,
@@ -63,7 +63,7 @@ get_rpc_handler_state(Pid) ->
6363

6464
%% Callbacks
6565

66-
start_link(Ref, _, Transport, Opts) ->
66+
start_link(Ref, Transport, Opts) ->
6767
{ok, proc_lib:spawn_link(?MODULE, ranch_init, [{Ref, Transport, Opts}])}.
6868

6969
ranch_init({Ref, Transport, Opts}) ->

test/single_dc_SUITE.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,11 @@ config_change_case({post, Cfg}) ->
317317
stop_single(Cfg);
318318
config_change_case(Cfg) when is_list(Cfg) ->
319319
%% test "max_connections"
320-
MaxConnsBefore = [{Listener, proplists:get_value(max_connections, Opts)}
320+
MaxConnsBefore = [{Listener, maps:get(max_connections, Opts)}
321321
|| {Listener, Opts} <- mtproto_proxy_app:mtp_listeners()],
322322
NewMaxConns = 10,
323323
ok = mtproto_proxy_app:config_change([{max_connections, NewMaxConns}], [], []),
324-
MaxConnsAfter = [{Listener, proplists:get_value(max_connections, Opts)}
324+
MaxConnsAfter = [{Listener, maps:get(max_connections, Opts)}
325325
|| {Listener, Opts} <- mtproto_proxy_app:mtp_listeners()],
326326
?assertNotEqual(MaxConnsBefore, MaxConnsAfter),
327327
?assert(lists:all(fun({_Listener, MaxConns}) ->

0 commit comments

Comments
 (0)