summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Doane <jaydoane@apache.org>2022-11-16 12:01:21 -0800
committerNick Vatamaniuc <nickva@users.noreply.github.com>2022-11-18 14:10:55 -0500
commit2e0b5077bbdccdc440d8ea7a1f0042cfa0ee9b62 (patch)
treefcdf8739d26595d9957f087e2c1f940f2e8661c3
parentc4d2984da41e92938b4528ed25e66d7038816071 (diff)
downloadcouchdb-2e0b5077bbdccdc440d8ea7a1f0042cfa0ee9b62.tar.gz
Improve flaky dbs info test
This test can time out with the following stack trace because ibrowse sends {error, retry_later} under certain conditions [1] which causes test_request:request/6 to sleep and retry [2], which can result in this failure: chttpd_dbs_info_test:79: -dbs_info_test_/0-fun-20- (should_return_500_time_out_when_time_is_not_enough_for_get_dbs_info)...*timed out* in function timer:sleep/1 (timer.erl, line 219) in call from test_request:request/6 (src/test_request.erl, line 106) in call from 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 157) 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) undefined [1] https://github.com/cmullaparthi/ibrowse/blob/22d6fd6baa6e83633aa2923f41589945c1d2dc2f/src/ibrowse.erl#L409 [2] https://github.com/apache/couchdb/blob/62d92766e8b8042c2f3627c3ac3e2365410c7912/src/couch/src/test_request.erl#L104-L106
-rw-r--r--src/chttpd/test/eunit/chttpd_dbs_info_test.erl16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/chttpd/test/eunit/chttpd_dbs_info_test.erl b/src/chttpd/test/eunit/chttpd_dbs_info_test.erl
index 19bf0e543..9c9958a92 100644
--- a/src/chttpd/test/eunit/chttpd_dbs_info_test.erl
+++ b/src/chttpd/test/eunit/chttpd_dbs_info_test.erl
@@ -21,7 +21,7 @@
-define(CONTENT_JSON, {"Content-Type", "application/json"}).
start() ->
- Ctx = chttpd_test_util:start_couch(),
+ Ctx = test_util:start_couch([inets, chttpd]),
DbDir = config:get("couchdb", "database_dir"),
Suffix = ?b2l(couch_uuids:random()),
test_util:with_couch_server_restart(fun() ->
@@ -183,11 +183,15 @@ 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(),
- {ok, Code, _, ResultBody} = test_request:get(
- dbs_info_url("buffer_response=true"), [?CONTENT_JSON, ?AUTH]
- ),
- {Body} = jiffy:decode(ResultBody),
- ?assertEqual(<<"timeout">>, couch_util:get_value(<<"error">>, Body)),
+ % 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).
should_return_db2_for_get_dbs_info_with_descending({Suffix, Db1, Db2}) ->