couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] branch 2.1.x updated: Account for extra newlines in response body
Date Fri, 09 Jun 2017 16:23:39 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch 2.1.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/2.1.x by this push:
     new aca0693  Account for extra newlines in response body
aca0693 is described below

commit aca0693a5a0767254c5d5146b44fac6fba339f7f
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
AuthorDate: Fri Jun 9 09:03:50 2017 -0500

    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 | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/src/chttpd/test/chttpd_db_test.erl b/src/chttpd/test/chttpd_db_test.erl
index 02d74ad..96ce01e 100644
--- a/src/chttpd/test/chttpd_db_test.erl
+++ b/src/chttpd/test/chttpd_db_test.erl
@@ -83,33 +83,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]),
-        [_, CleanedResult] = binary:split(ResultBody2, <<"\n">>),
-        {[{_, Seq}, _]} = ?JSON_DECODE(CleanedResult),
-        <<SeqNum0:1/binary, "-", _/binary>> = Seq,
-        SeqNum = list_to_integer(binary_to_list(SeqNum0)),
+        LastSeq2 = GetLastSeq(ResultBody2),
 
-        ?assertEqual(LastSeqNum + 1, SeqNum)
+        ?assertNotEqual(LastSeq1, LastSeq2)
     end).
 
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <commits@couchdb.apache.org>'].

Mime
View raw message