diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-06-09 09:03:50 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-06-09 09:12:57 -0500 |
commit | c7e9dd738bd6343ba29f005ed90fb2a9d2a668bc (patch) | |
tree | a4fc099de0b892859fc9f70ae617b25f6c1a668b | |
parent | f6321df8ad231451181845b7523ba791780dc747 (diff) | |
download | couchdb-c7e9dd738bd6343ba29f005ed90fb2a9d2a668bc.tar.gz |
Account for extra newlines in response bodyCOUCHDB-3415-fix-chttpd-db-test-eunit
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
-rw-r--r-- | src/chttpd/test/chttpd_db_test.erl | 40 |
1 files 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, - <<LastSeqNum0:1/binary, "-", _/binary>> = 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), - <<SeqNum0:1/binary, "-", _/binary>> = Seq, - SeqNum = list_to_integer(binary_to_list(SeqNum0)), - - ?assertEqual(LastSeqNum + 1, SeqNum) + LastSeq2 = GetLastSeq(ResultBody2), + + ?assertNotEqual(LastSeq1, LastSeq2) end). |