From c7e9dd738bd6343ba29f005ed90fb2a9d2a668bc Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Fri, 9 Jun 2017 09:03:50 -0500 Subject: Account for extra newlines in response body The timeout=1 (1ms) parameter would some times trigger extra newlines to be included in the response body. The use of `binary:split/2` would then return different portions of the body depending on timing in the cluster. This change adds a helper function to split out all newlines in the response and then returns the last non-empty line. This also removes introspection of the clustered update sequence since this is an HTTP API behavior tests and those are defined as opaque values. COUCHDB-3415 --- src/chttpd/test/chttpd_db_test.erl | 40 ++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/chttpd/test/chttpd_db_test.erl b/src/chttpd/test/chttpd_db_test.erl index c6c1cec15..a739a3d15 100644 --- a/src/chttpd/test/chttpd_db_test.erl +++ b/src/chttpd/test/chttpd_db_test.erl @@ -84,35 +84,29 @@ should_return_ok_true_on_bulk_update(Url) -> should_accept_live_as_an_alias_for_continuous(Url) -> - ?_test(begin - {ok, _, _, ResultBody} = - test_request:get(Url ++ "/_changes?feed=live&timeout=1", [?AUTH]), - % https://issues.apache.org/jira/browse/COUCHDB-3415?filter=12340503 - % if the decode fails, print out ResultBody, so we can debug what - % extra data is coming in. - {ResultJson} = try ?JSON_DECODE(ResultBody) of - Json -> Json + GetLastSeq = fun(Bin) -> + Parts = binary:split(Bin, <<"\n">>, [global]), + Filtered = [P || P <- Parts, size(P) > 0], + LastSeqBin = lists:last(Filtered), + {Result} = try ?JSON_DECODE(LastSeqBin) of + Data -> Data catch - throw:Error -> - io:format(user, "~nJSON_DECODE error: ~p~n", [Error]), - io:format(user, "~nOffending String: ~p~n", [ResultBody]), + _:_ -> ?assert(false) % should not happen, abort end, - <> = couch_util:get_value( - <<"last_seq">>, ResultJson, undefined), - LastSeqNum = list_to_integer(binary_to_list(LastSeqNum0)), + couch_util:get_value(<<"last_seq">>, Result, undefined) + end, + ?_test(begin + {ok, _, _, ResultBody1} = + test_request:get(Url ++ "/_changes?feed=live&timeout=1", [?AUTH]), + LastSeq1 = GetLastSeq(ResultBody1), {ok, _, _, _} = create_doc(Url, "testdoc2"), - {ok, _, _, ResultBody2} = + {ok, _, _, ResultBody2} = test_request:get(Url ++ "/_changes?feed=live&timeout=1", [?AUTH]), - io:format(user, "~nDEBUG COUCHDB-3415: ResultBody2: ~p~n", [ResultBody2]), - [_, CleanedResult] = binary:split(ResultBody2, <<"\n">>), - io:format(user, "~nDEBUG COUCHDB-3415: CleanedResult: ~p~n", [CleanedResult]), - {[{_, Seq}, _]} = ?JSON_DECODE(CleanedResult), - <> = Seq, - SeqNum = list_to_integer(binary_to_list(SeqNum0)), - - ?assertEqual(LastSeqNum + 1, SeqNum) + LastSeq2 = GetLastSeq(ResultBody2), + + ?assertNotEqual(LastSeq1, LastSeq2) end). -- cgit v1.2.1