Skip to content

Commit a6c74ec

Browse files
bas0Nmergify[bot]
authored andcommitted
Fix tests and improve test helpers in rabbitmq_tracing
- Replace timer:sleep(100) with await_condition/1 to wait for trace files instead of using fixed delays, making tests more reliable - Remove explicit close_channel calls for managed CT helper channels - Add http_get_headers/5 helper function following the same pattern as http_get/5 and http_get_raw/5, replacing direct req/4 calls - Use helper function to validate HTTP status codes and return headers consistently with the module's existing helper pattern (cherry picked from commit b606cc0)
1 parent 767212d commit a6c74ec

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

deps/rabbitmq_tracing/test/rabbit_tracing_SUITE.erl

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ tracing_test(Config) ->
9393
#amqp_msg{props = #'P_basic'{},
9494
payload = <<"Hello world">>}),
9595

96-
rabbit_ct_client_helpers:close_channel(Ch),
97-
98-
timer:sleep(100),
96+
rabbit_ct_helpers:await_condition(fun() ->
97+
TraceFiles = http_get(Config, "/trace-files/"),
98+
lists:any(fun(#{name := Name}) -> Name =:= <<"test.log">> end, TraceFiles)
99+
end),
99100

100101
http_delete(Config, "/traces/%2f/test", ?NO_CONTENT),
101102
[] = http_get(Config, "/traces/%2f/"),
@@ -145,13 +146,14 @@ trace_file_content_type_test(Config) ->
145146
routing_key = <<"key">> },
146147
#amqp_msg{props = #'P_basic'{},
147148
payload = <<"Test message">>}),
148-
rabbit_ct_client_helpers:close_channel(Ch),
149149

150-
timer:sleep(100),
150+
rabbit_ct_helpers:await_condition(fun() ->
151+
TraceFiles = http_get(Config, "/trace-files/"),
152+
lists:any(fun(#{name := Name}) -> Name =:= <<"test-charset.log">> end, TraceFiles)
153+
end),
151154

152155
http_delete(Config, "/traces/%2f/test-charset", ?NO_CONTENT),
153-
{ok, {{_HTTP, 200, _}, Headers, _Body}} =
154-
req(Config, get, "/trace-files/test-charset.log", [auth_header("guest", "guest")]),
156+
Headers = http_get_headers(Config, "/trace-files/test-charset.log"),
155157
ContentType = proplists:get_value("content-type", Headers),
156158
?assertEqual(match, re:run(ContentType, "text/plain", [{capture, none}])),
157159
?assertEqual(match, re:run(ContentType, "charset=utf-8", [{capture, none}])),
@@ -184,6 +186,15 @@ http_get_raw(Config, Path, User, Pass, CodeExp) ->
184186
assert_code(CodeExp, CodeAct, "GET", Path, ResBody),
185187
ResBody.
186188

189+
http_get_headers(Config, Path) ->
190+
http_get_headers(Config, Path, "guest", "guest", ?OK).
191+
192+
http_get_headers(Config, Path, User, Pass, CodeExp) ->
193+
{ok, {{_HTTP, CodeAct, _}, Headers, ResBody}} =
194+
req(Config, get, Path, [auth_header(User, Pass)]),
195+
assert_code(CodeExp, CodeAct, "GET", Path, ResBody),
196+
Headers.
197+
187198
http_put(Config, Path, List, CodeExp) ->
188199
http_put_raw(Config, Path, format_for_upload(List), CodeExp).
189200

0 commit comments

Comments
 (0)