diff options
| author | dcorbacho <dparracorbacho@piotal.io> | 2020-04-08 11:47:24 +0100 |
|---|---|---|
| committer | dcorbacho <dparracorbacho@piotal.io> | 2020-04-08 11:47:24 +0100 |
| commit | ef499231bb4b08a52bc25d56acd55e3031c60f41 (patch) | |
| tree | e715682962af3bf36175080b805d5e8549117492 | |
| parent | 2092730359a59742fd6b76ff086665e507bdeed6 (diff) | |
| download | rabbitmq-server-git-ef499231bb4b08a52bc25d56acd55e3031c60f41.tar.gz | |
Fix flaky test - connection tracking is asynchronous
| -rw-r--r-- | test/unit_connection_tracking_SUITE.erl | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/test/unit_connection_tracking_SUITE.erl b/test/unit_connection_tracking_SUITE.erl index de30e4fdf2..ec1a611baa 100644 --- a/test/unit_connection_tracking_SUITE.erl +++ b/test/unit_connection_tracking_SUITE.erl @@ -93,10 +93,18 @@ queue_count(Config) -> rabbit_ct_client_helpers:close_connection(Conn), ok. +%% connection_count/1 has been failing on Travis. This seems a legit failure, as the registering +%% of connections in the tracker is async. `rabbit_connection_tracking_handler` receives a rabbit +%% event with `connection_created`, which then forwards as a cast to `rabbit_connection_tracker` +%% for register. We should wait a reasonable amount of time for the counter to increase before +%% failing. connection_count(Config) -> Conn = rabbit_ct_client_helpers:open_connection(Config, 0), - ?assertEqual(1, rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_connection_tracking, count, [])), + wait_until( + fun() -> + rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_connection_tracking, count, []) == 1 + end), rabbit_ct_client_helpers:close_connection(Conn), ok. @@ -104,6 +112,13 @@ connection_count(Config) -> connection_lookup(Config) -> Conn = rabbit_ct_client_helpers:open_connection(Config, 0), + %% Let's wait until the connection is registered, otherwise this test could fail in a slow + %% machine as connection tracking is asynchronous + wait_until( + fun() -> + rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_connection_tracking, count, []) == 1 + end), + [Connection] = rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_connection_tracking, list, []), ?assertMatch(Connection, rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_connection_tracking, lookup, @@ -111,3 +126,17 @@ connection_lookup(Config) -> rabbit_ct_client_helpers:close_connection(Conn), ok. + +wait_until(Condition) -> + wait_until(Condition, 60). + +wait_until(Condition, 0) -> + ?assertEqual(true, Condition()); +wait_until(Condition, N) -> + case Condition() of + true -> + ok; + _ -> + timer:sleep(500), + wait_until(Condition, N - 1) + end. |
