You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2023/01/09 20:52:52 UTC

[couchdb] 01/01: Wait for dbs_info 500 timeout error

This is an automated email from the ASF dual-hosted git repository.

jaydoane pushed a commit to branch wait-dbs-info-timeout-test
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit bb251e2dc85ca17d3dda55f3defbd7ff0d026812
Author: Jay Doane <ja...@apache.org>
AuthorDate: Mon Jan 9 12:52:29 2023 -0800

    Wait for dbs_info 500 timeout error
    
    With more recent OTP versions, this test has been observed to fail
    with the following error:
    
        chttpd_dbs_info_test:88: -dbs_info_test_/0-fun-22- (should_return_500_time_out_when_time_is_not_enough_for_get_dbs_info)...*failed*
    in function chttpd_dbs_info_test:should_return_500_time_out_when_time_is_not_enough_for_get_dbs_info/1 (test/eunit/chttpd_dbs_info_test.erl, line 192)
    in call from eunit_test:run_testfun/1 (eunit_test.erl, line 71)
    in call from eunit_proc:run_test/1 (eunit_proc.erl, line 531)
    in call from eunit_proc:with_timeout/3 (eunit_proc.erl, line 356)
    in call from eunit_proc:handle_test/2 (eunit_proc.erl, line 514)
    in call from eunit_proc:tests_inorder/3 (eunit_proc.erl, line 456)
    in call from eunit_proc:with_timeout/3 (eunit_proc.erl, line 346)
    in call from eunit_proc:run_group/2 (eunit_proc.erl, line 570)
    **error:{badmatch,{error,socket_closed_remotely}}
      output:<<"">>
    
    This change waits until the expected 500 timeout error is received.
---
 src/chttpd/test/eunit/chttpd_dbs_info_test.erl | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/chttpd/test/eunit/chttpd_dbs_info_test.erl b/src/chttpd/test/eunit/chttpd_dbs_info_test.erl
index 9c9958a92..a53442f98 100644
--- a/src/chttpd/test/eunit/chttpd_dbs_info_test.erl
+++ b/src/chttpd/test/eunit/chttpd_dbs_info_test.erl
@@ -183,16 +183,25 @@ should_return_nothing_when_db_not_exist_for_get_dbs_info(_) ->
 
 should_return_500_time_out_when_time_is_not_enough_for_get_dbs_info(_) ->
     mock_timeout(),
-    % Use httpc to avoid ibrowse returning {error, retry_later} in
-    % some cases, causing test_request to sleep and retry, resulting
-    % in timeout failures.
     Auth = base64:encode_to_string(?USER ++ ":" ++ ?PASS),
     Headers = [{"Authorization", "Basic " ++ Auth}],
     Request = {dbs_info_url("buffer_response=true"), Headers},
-    {ok, {{_, Code, _}, _, Body}} = httpc:request(get, Request, [], []),
-    {Props} = jiffy:decode(Body),
-    ?assertEqual(<<"timeout">>, couch_util:get_value(<<"error">>, Props)),
-    ?assertEqual(500, Code).
+    {Props} =
+        test_util:wait(
+            fun() ->
+                % Use httpc to avoid ibrowse returning {error,
+                % retry_later} in some cases, causing test_request to
+                % sleep and retry, resulting in timeout failures.
+                case httpc:request(get, Request, [], []) of
+                    {ok, {{_, Code, _}, _, Body}} ->
+                        ?assertEqual(500, Code),
+                        jiffy:decode(Body);
+                    _ ->
+                        wait
+                end
+            end
+        ),
+    ?assertEqual(<<"timeout">>, couch_util:get_value(<<"error">>, Props)).
 
 should_return_db2_for_get_dbs_info_with_descending({Suffix, Db1, Db2}) ->
     {ok, _, _, ResultBody} = test_request:get(