Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
RoadRunnr committed Oct 22, 2024
1 parent 9a455fd commit 27a06a0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: |
# rebar3 xref
# rebar3 dialyzer
rebar3 ct
rebar3 ct --config priv/ct-github.config
-
name: Tar Test Output
if: ${{ always() }}
Expand Down
1 change: 1 addition & 0 deletions priv/ct-github.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{nats_host, ~"jetstream"}.
60 changes: 34 additions & 26 deletions test/nats_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

%% NOTE: a gnatsd instance must be running at 127.0.0.1:4222

suite() ->
[{timetrap, {minutes,1}}].

all() ->
[connect_ok,
connect_fail_no_host,
Expand All @@ -42,7 +45,8 @@ all() ->
micro_verbose_ok].

init_per_suite(Config) ->
_ = logger:set_primary_config(level, debug),
Level = ct:get_config(log_level, info),
_ = logger:set_primary_config(level, Level).
application:ensure_started(enats),
Config.

Expand All @@ -59,7 +63,8 @@ connect_ok(_) ->
%% connect returns a new connection process, once the connection succeeds,
%% a {Connection, ready} message is sent to the owner

{ok, C} = nats:connect(~"jetstream", 4222),
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port),
receive
{C, ready} -> ok
after 1000 ->
Expand All @@ -71,7 +76,8 @@ connect_fail_no_host(_) ->
%% If the connection fails (host not found),
%% a {Connection, {error, nxdomain}} message is sent to the owner

{ok, C} = nats:connect(<<"doesnt-exist.google.com">>, 4222),
{ok, _Host, Port} = nats_addr(),
{ok, C} = nats:connect(<<"doesnt-exist.google.com">>, Port),
receive
{C, {error, nxdomain}} -> ok
after 1000 ->
Expand All @@ -83,8 +89,9 @@ connect_fail_no_port(_) ->
%% If the connection fails (port is not open),
%% a {Connection, {error, econnrefused}} message is sent to the owner

{ok, Host, _Port} = nats_addr(),
NonExistingPort = 4444,
{ok, C} = nats:connect(~"jetstream", NonExistingPort),
{ok, C} = nats:connect(Host, NonExistingPort),
receive
{C, {error, econnrefused}} -> ok
after 1000 ->
Expand All @@ -95,7 +102,8 @@ connect_verbose_ok(_) ->
%% connect returns a new connection process, once the connection succeeds,
%% a {Connection, ready} message is sent to the owner

{ok, C} = nats:connect(~"jetstream", 4222, #{verbose => true}),
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port, #{verbose => true}),
receive
{C, ready} -> ok
after 1000 ->
Expand All @@ -108,41 +116,42 @@ connect_verbose_fail(_) ->
%% If the connection fails (port is not open),
%% a {Connection, {error, econnrefused}} message is sent to the owner

{ok, Host, _Port} = nats_addr(),
NonExistingPort = 4444,
{ok, C} = nats:connect(~"jetstream", NonExistingPort),
{ok, C} = nats:connect(Host, NonExistingPort),
receive
{C, {error, econnrefused}} -> ok
after 1000 ->
throw(error_on_fail_not_sent)
end.

disconnect_ok(_) ->
Host = ~"jetstream",
Port = 4222,
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port, #{verbose => true}),
ok = nats:disconnect(C),
{error, not_found} = nats:is_ready(C).


pub_ok(_) ->
{ok, C} = nats:connect(~"jetstream", 4222),
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port),
receive {C, ready} -> ok end,
nats:pub(C, <<"foo.bar">>, <<"My payload">> ),
timer:sleep(100).

pub_verbose_ok(_) ->
{ok, C} = nats:connect(~"jetstream", 4222,
#{verbose => true}),
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port, #{verbose => true}),
ok = nats:pub(C, <<"foo.bar">>, <<"My payload">>).

pub_with_buffer_size(_) ->
{ok, C} = nats:connect(~"jetstream", 4222, #{buffer_size => 1}),
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port, #{buffer_size => 1}),
nats:pub(C, <<"foo.bar">>, <<"My payload">>),
timer:sleep(100).

sub_ok(_) ->
Host = ~"jetstream",
Port = 4222,
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port),
receive {C, ready} -> ok end,
{ok, Sid} = nats:sub(C, <<"foo.*">>),
Expand All @@ -155,8 +164,7 @@ sub_ok(_) ->
end.

sub_verbose_ok(_) ->
Host = ~"jetstream",
Port = 4222,
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port, #{verbose => true}),
receive {C, ready} -> ok end,

Expand All @@ -169,8 +177,8 @@ sub_verbose_ok(_) ->
end.

unsub_verbose_ok(_) ->
{ok, C} = nats:connect(~"jetstream", 4222,
#{verbose => true}),
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port, #{verbose => true}),
receive {C, ready} -> ok end,
{ok, Sid} = nats:sub(C, <<"foo.*">>),
nats:unsub(C, Sid),
Expand All @@ -183,8 +191,7 @@ unsub_verbose_ok(_) ->
end.

request_no_responders(_) ->
Host = ~"jetstream",
Port = 4222,
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port),
receive {C, ready} -> ok end,

Expand All @@ -193,17 +200,15 @@ request_no_responders(_) ->
ok.

request_verbose_no_responders(_) ->
Host = ~"jetstream",
Port = 4222,
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port),
receive {C, ready} -> ok end,

Response = nats:request(C, ~"FOOBAR.echo", ~"Hello World", #{}),
?assertEqual({error,no_responders}, Response),
ok.
micro_ok(_) ->
Host = ~"jetstream",
Port = 4222,
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port),
receive {C, ready} -> ok end,

Expand All @@ -227,8 +232,7 @@ micro_ok(_) ->
end.

micro_verbose_ok(_) ->
Host = ~"jetstream",
Port = 4222,
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port, #{verbose => true}),
receive {C, ready} -> ok end,

Expand Down Expand Up @@ -263,3 +267,7 @@ send_tcp_msg(BinHost, Port, BinMsg) ->

echo(_ReplyKey, _SvcName, _Op, Payload, _, CbState) ->
{reply, Payload, CbState}.

nats_addr() ->
Host = ct:get_config(nats_host, ~"localhost"),
{ok, Host, 4222}.
10 changes: 8 additions & 2 deletions test/nats_jetstream_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ init_per_testcase(_TestCase, Config) ->
Config.

end_per_testcase(_TestCase, Config) ->
{ok, Con} = nats:connect(~"jetstream", 4222),
{ok, Host, Port} = nats_addr(),
{ok, Con} = nats:connect(Host, Port),
receive
{Con, ready} -> ok
after 1000 ->
Expand Down Expand Up @@ -266,8 +267,13 @@ kv(_Client, Con, _Config) ->
%%% Internal helpers
%%%===================================================================

nats_addr() ->
Host = ct:get_config(nats_host, ~"localhost"),
{ok, Host, 4222}.

connect() ->
{ok, C} = nats:connect(~"jetstream", 4222, #{buffer_size => -1}),
{ok, Host, Port} = nats_addr(),
{ok, C} = nats:connect(Host, Port, #{buffer_size => -1}),
receive {C, ready} -> C
after 1000 ->
ct:fail(ready_msg_not_sent)
Expand Down

0 comments on commit 27a06a0

Please sign in to comment.