summaryrefslogtreecommitdiff
path: root/src/chttpd/test/eunit/chttpd_db_test.erl
blob: cebc3b6d664aa8846ffc06bba26c66af351fc379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% use this file except in compliance with the License. You may obtain a copy of
% the License at
%
%   http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
% License for the specific language governing permissions and limitations under
% the License.

-module(chttpd_db_test).

-include_lib("couch/include/couch_eunit.hrl").
-include_lib("couch/include/couch_db.hrl").

-define(USER, "chttpd_db_test_admin").
-define(PASS, "pass").
-define(AUTH, {basic_auth, {?USER, ?PASS}}).
-define(CONTENT_JSON, {"Content-Type", "application/json"}).
-define(DESTHEADER1, {"Destination", "foo%E5%95%8Abar"}).
-define(DESTHEADER2, {"Destination", "foo%2Fbar%23baz%3Fpow%3Afiz"}).
-define(FIXTURE_TXT, ?ABS_PATH(?FILE)).
-define(i2l(I), integer_to_list(I)).
-define(TIMEOUT, 60). % seconds

setup() ->
    Hashed = couch_passwords:hash_admin_password(?PASS),
    ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
    TmpDb = ?tempdb(),
    Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
    Port = mochiweb_socket_server:get(chttpd, port),
    Url = lists:concat(["http://", Addr, ":", Port, "/", ?b2l(TmpDb)]),
    create_db(Url),
    Url.

teardown(Url) ->
    delete_db(Url),
    ok = config:delete("admins", ?USER, _Persist=false).

create_db(Url) ->
    {ok, Status, _, _} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], "{}"),
    ?assert(Status =:= 201 orelse Status =:= 202).


create_doc(Url, Id) ->
    test_request:put(Url ++ "/" ++ Id,
        [?CONTENT_JSON, ?AUTH], "{\"mr\": \"rockoartischocko\"}").

delete_db(Url) ->
    {ok, 200, _, _} = test_request:delete(Url, [?AUTH]).

all_test_() ->
    {
        "chttpd db tests",
        {
            setup,
            fun chttpd_test_util:start_couch/0, fun chttpd_test_util:stop_couch/1,
            {
                foreach,
                fun setup/0, fun teardown/1,
                [
                    fun should_return_ok_true_on_bulk_update/1,
                    fun should_return_ok_true_on_ensure_full_commit/1,
                    fun should_return_404_for_ensure_full_commit_on_no_db/1,
                    fun should_accept_live_as_an_alias_for_continuous/1,
                    fun should_return_headers_after_starting_continious/1,
                    fun should_return_404_for_delete_att_on_notadoc/1,
                    fun should_return_409_for_del_att_without_rev/1,
                    fun should_return_200_for_del_att_with_rev/1,
                    fun should_return_409_for_put_att_nonexistent_rev/1,
                    fun should_return_update_seq_when_set_on_all_docs/1,
                    fun should_not_return_update_seq_when_unset_on_all_docs/1,
                    fun should_return_correct_id_on_doc_copy/1,
                    fun should_ignore_engine_parameter/1,
                    fun should_return_only_one_ok_on_doc_copy/1,
                    fun should_succeed_on_all_docs_with_queries_keys/1,
                    fun should_succeed_on_all_docs_with_queries_limit_skip/1,
                    fun should_succeed_on_all_docs_with_multiple_queries/1,
                    fun should_succeed_on_design_docs_with_queries_keys/1,
                    fun should_succeed_on_design_docs_with_queries_limit_skip/1,
                    fun should_succeed_on_design_docs_with_multiple_queries/1,
                    fun should_succeed_on_local_docs_with_queries_keys/1,
                    fun should_succeed_on_local_docs_with_queries_limit_skip/1,
                    fun should_succeed_on_local_docs_with_multiple_queries/1
                ]
            }
        }
    }.


should_return_ok_true_on_bulk_update(Url) ->
    {timeout, ?TIMEOUT, ?_assertEqual(true,
        begin
            {ok, _, _, Body} = create_doc(Url, "testdoc"),
            {Json} = ?JSON_DECODE(Body),
            Ref = couch_util:get_value(<<"rev">>, Json, undefined),
            NewDoc = "{\"docs\": [{\"_rev\": \"" ++ ?b2l(Ref) ++ "\", \"_id\": \"testdoc\"}]}",
            {ok, _, _, ResultBody} = test_request:post(Url ++ "/_bulk_docs/",
                [?CONTENT_JSON, ?AUTH], NewDoc),
            ResultJson = ?JSON_DECODE(ResultBody),
            {InnerJson} = lists:nth(1, ResultJson),
            couch_util:get_value(<<"ok">>, InnerJson, undefined)
        end)}.


should_return_ok_true_on_ensure_full_commit(Url0) ->
    {timeout, ?TIMEOUT, ?_test(begin
        Url = Url0 ++ "/_ensure_full_commit",
        {ok, RC, _, Body} = test_request:post(Url, [?CONTENT_JSON, ?AUTH], []),
        {Json} = ?JSON_DECODE(Body),
        ?assertEqual(201, RC),
        ?assert(couch_util:get_value(<<"ok">>, Json))
    end)}.


should_return_404_for_ensure_full_commit_on_no_db(Url0) ->
    {timeout, ?TIMEOUT, ?_test(begin
        Url = Url0 ++ "-missing-db" ++ "/_ensure_full_commit",
        {ok, RC, _, Body} = test_request:post(Url, [?CONTENT_JSON, ?AUTH], []),
        {Json} = ?JSON_DECODE(Body),
        ?assertEqual(404, RC),
        ?assertEqual(<<"not_found">>, couch_util:get_value(<<"error">>, Json))
    end)}.


should_accept_live_as_an_alias_for_continuous(Url) ->
    GetLastSeq = fun(Chunks) ->
        LastSeqBin = lists:last(Chunks),
        {Result} = try ?JSON_DECODE(LastSeqBin) of
            Data -> Data
        catch
            _:_ ->
                ?assert(false) % should not happen, abort
        end,
        couch_util:get_value(<<"last_seq">>, Result, undefined)
    end,
    {timeout, ?TIMEOUT, ?_test(begin
        LastSeq1 = GetLastSeq(wait_non_empty_chunk(Url)),

        {ok, _, _, _} = create_doc(Url, "testdoc2"),

        LastSeq2 = GetLastSeq(wait_non_empty_chunk(Url)),

        ?assertNotEqual(LastSeq1, LastSeq2)
    end)}.


should_return_404_for_delete_att_on_notadoc(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        {ok, RC, _, RespBody} = test_request:delete(
            Url ++ "/notadoc/att.pdf",
            [?CONTENT_JSON, ?AUTH],
            []
        ),
        ?assertEqual(404, RC),
        ?assertEqual(
          {[{<<"error">>,<<"not_found">>},
            {<<"reason">>,<<"missing">>}]},
          jiffy:decode(RespBody)
        ),
        {ok, RC1, _, _} = test_request:get(
            Url ++ "/notadoc",
            [?CONTENT_JSON, ?AUTH],
            []
        ),
        ?assertEqual(404, RC1)
    end)}.


should_return_409_for_del_att_without_rev(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        {ok, RC, _, _} = test_request:put(
            Url ++ "/testdoc3",
            [?CONTENT_JSON, ?AUTH],
            jiffy:encode(attachment_doc())
        ),
        ?assertEqual(201, RC),

        {ok, RC1, _, _} = test_request:delete(
            Url ++ "/testdoc3/file.erl",
            [?CONTENT_JSON, ?AUTH],
            []
        ),
        ?assertEqual(409, RC1)
    end)}.


should_return_200_for_del_att_with_rev(Url) ->
  {timeout, ?TIMEOUT, ?_test(begin
      {ok, RC, _Headers, RespBody} = test_request:put(
          Url ++ "/testdoc4",
          [?CONTENT_JSON, ?AUTH],
          jiffy:encode(attachment_doc())
      ),
      ?assertEqual(201, RC),

      {ResultJson} = ?JSON_DECODE(RespBody),
      Rev = couch_util:get_value(<<"rev">>, ResultJson, undefined),

      {ok, RC1, _, _} = test_request:delete(
          Url ++ "/testdoc4/file.erl?rev=" ++ Rev,
          [?CONTENT_JSON, ?AUTH],
          []
      ),
      ?assertEqual(200, RC1)
    end)}.


should_return_409_for_put_att_nonexistent_rev(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        {ok, RC, _Headers, RespBody} = test_request:put(
            Url ++ "/should_return_404/file.erl?rev=1-000",
            [?CONTENT_JSON, ?AUTH],
            jiffy:encode(attachment_doc())
        ),
        ?assertEqual(409, RC),
        ?assertMatch({[
            {<<"error">>,<<"not_found">>},
            {<<"reason">>,<<"missing_rev">>}]},
            ?JSON_DECODE(RespBody))
    end)}.


should_return_update_seq_when_set_on_all_docs(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "testdoc" ++ ?i2l(I)) || I <- lists:seq(1, 3)],
        {ok, RC, _, RespBody} = test_request:get(Url ++ "/_all_docs/"
            ++ "?update_seq=true&keys=[\"testdoc1\"]",[?CONTENT_JSON, ?AUTH]),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ?assertNotEqual(undefined,
            couch_util:get_value(<<"update_seq">>, ResultJson)),
        ?assertNotEqual(undefined,
            couch_util:get_value(<<"offset">>, ResultJson))
    end)}.


should_not_return_update_seq_when_unset_on_all_docs(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "testdoc" ++ ?i2l(I)) || I <- lists:seq(1, 3)],
        {ok, RC, _, RespBody} = test_request:get(Url ++ "/_all_docs/"
            ++ "?update_seq=false&keys=[\"testdoc1\"]",[?CONTENT_JSON, ?AUTH]),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ?assertEqual(undefined,
            couch_util:get_value(<<"update_seq">>, ResultJson)),
        ?assertNotEqual(undefined,
            couch_util:get_value(<<"offset">>, ResultJson))
    end)}.


should_return_correct_id_on_doc_copy(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        {ok, _, _, _} = create_doc(Url, "testdoc"),
        {_, _, _, ResultBody1} = test_request:copy(Url ++ "/testdoc/",
            [?CONTENT_JSON, ?AUTH, ?DESTHEADER1]),
        {ResultJson1} = ?JSON_DECODE(ResultBody1),
        Id1 = couch_util:get_value(<<"id">>, ResultJson1),
        
        {_, _, _, ResultBody2} = test_request:copy(Url ++ "/testdoc/",
            [?CONTENT_JSON, ?AUTH, ?DESTHEADER2]),
        {ResultJson2} = ?JSON_DECODE(ResultBody2),
        Id2 = couch_util:get_value(<<"id">>, ResultJson2),
        [
            ?assertEqual(<<102,111,111,229,149,138,98,97,114>>, Id1),
            ?assertEqual(<<"foo/bar#baz?pow:fiz">>, Id2)
        ]
    end)}.

should_return_only_one_ok_on_doc_copy(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
       {ok, _, _, _} = create_doc(Url, "testdoc"),
       {_, _, _, ResultBody} = test_request:copy(Url ++ "/testdoc",
           [?CONTENT_JSON, ?AUTH, ?DESTHEADER1]),
       {ResultJson} = jiffy:decode(ResultBody),
       NumOks = length(lists:filter(fun({Key, Value}) -> Key == <<"ok">> end, ResultJson)),
       [
           ?assertEqual(1, NumOks)
       ]
    end)}.

attachment_doc() ->
    {ok, Data} = file:read_file(?FIXTURE_TXT),
    {[
        {<<"_attachments">>, {[
            {<<"file.erl">>, {[
                {<<"content_type">>, <<"text/plain">>},
                {<<"data">>, base64:encode(Data)}
            ]}
        }]}}
    ]}.


should_ignore_engine_parameter(_) ->
    {timeout, ?TIMEOUT, ?_test(begin
        TmpDb = ?tempdb(),
        Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
        Port = mochiweb_socket_server:get(chttpd, port),
        BaseUrl = lists:concat(["http://", Addr, ":", Port, "/", ?b2l(TmpDb)]),
        Url = BaseUrl ++ "?engine=cowabunga",
        {ok, Status, _, _} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], "{}"),
        ?assertEqual(201, Status)
    end)}.


should_succeed_on_all_docs_with_queries_keys(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "testdoc" ++ ?i2l(I)) || I <- lists:seq(1, 10)],
        QueryDoc = "{\"queries\": [{\"keys\": [ \"testdoc3\", \"testdoc8\"]}]}",
        {ok, RC, _, RespBody} = test_request:post(Url ++ "/_all_docs/queries/",
            [?CONTENT_JSON, ?AUTH], QueryDoc),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ResultJsonBody = couch_util:get_value(<<"results">>, ResultJson),
        {InnerJson} = lists:nth(1, ResultJsonBody),
        ?assertEqual(2, length(couch_util:get_value(<<"rows">>, InnerJson)))
    end)}.


should_succeed_on_all_docs_with_queries_limit_skip(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "testdoc" ++ ?i2l(I)) || I <- lists:seq(1, 10)],
        QueryDoc = "{\"queries\": [{\"limit\": 5, \"skip\": 2}]}",
        {ok, RC, _, RespBody} = test_request:post(Url ++ "/_all_docs/queries/",
            [?CONTENT_JSON, ?AUTH], QueryDoc),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ResultJsonBody = couch_util:get_value(<<"results">>, ResultJson),
        {InnerJson} = lists:nth(1, ResultJsonBody),
        ?assertEqual(null, couch_util:get_value(<<"offset">>, InnerJson)),
        ?assertEqual(5, length(couch_util:get_value(<<"rows">>, InnerJson)))
    end)}.


should_succeed_on_all_docs_with_multiple_queries(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "testdoc" ++ ?i2l(I)) || I <- lists:seq(1, 10)],
        QueryDoc = "{\"queries\": [{\"keys\": [ \"testdoc3\", \"testdoc8\"]},
            {\"limit\": 5, \"skip\": 2}]}",
        {ok, RC, _, RespBody} = test_request:post(Url ++ "/_all_docs/queries/",
            [?CONTENT_JSON, ?AUTH], QueryDoc),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ResultJsonBody = couch_util:get_value(<<"results">>, ResultJson),
        {InnerJson1} = lists:nth(1, ResultJsonBody),
        ?assertEqual(2, length(couch_util:get_value(<<"rows">>, InnerJson1))),
        {InnerJson2} = lists:nth(2, ResultJsonBody),
        ?assertEqual(null, couch_util:get_value(<<"offset">>, InnerJson2)),
        ?assertEqual(5, length(couch_util:get_value(<<"rows">>, InnerJson2)))
    end)}.


should_succeed_on_design_docs_with_queries_keys(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "_design/ddoc" ++ ?i2l(I)) || I <- lists:seq(1, 10)],
        QueryDoc = "{\"queries\": [{\"keys\": [ \"_design/ddoc3\",
            \"_design/ddoc8\"]}]}",
        {ok, RC, _, RespBody} = test_request:post(Url ++
            "/_design_docs/queries/", [?CONTENT_JSON, ?AUTH], QueryDoc),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ResultJsonBody = couch_util:get_value(<<"results">>, ResultJson),
        {InnerJson} = lists:nth(1, ResultJsonBody),
        ?assertEqual(2, length(couch_util:get_value(<<"rows">>, InnerJson)))
    end)}.


should_succeed_on_design_docs_with_queries_limit_skip(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "_design/ddoc" ++ ?i2l(I)) || I <- lists:seq(1, 10)],
        QueryDoc = "{\"queries\": [{\"limit\": 5, \"skip\": 2}]}",
        {ok, RC, _, RespBody} = test_request:post(Url ++
            "/_design_docs/queries/", [?CONTENT_JSON, ?AUTH], QueryDoc),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ResultJsonBody = couch_util:get_value(<<"results">>, ResultJson),
        {InnerJson} = lists:nth(1, ResultJsonBody),
        ?assertEqual(null, couch_util:get_value(<<"offset">>, InnerJson)),
        ?assertEqual(5, length(couch_util:get_value(<<"rows">>, InnerJson)))
    end)}.


should_succeed_on_design_docs_with_multiple_queries(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "_design/ddoc" ++ ?i2l(I)) || I <- lists:seq(1, 10)],
        QueryDoc = "{\"queries\": [{\"keys\": [ \"_design/ddoc3\",
            \"_design/ddoc8\"]}, {\"limit\": 5, \"skip\": 2}]}",
        {ok, RC, _, RespBody} = test_request:post(Url ++
            "/_design_docs/queries/", [?CONTENT_JSON, ?AUTH], QueryDoc),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ResultJsonBody = couch_util:get_value(<<"results">>, ResultJson),
        {InnerJson1} = lists:nth(1, ResultJsonBody),
        ?assertEqual(2, length(couch_util:get_value(<<"rows">>, InnerJson1))),
        {InnerJson2} = lists:nth(2, ResultJsonBody),
        ?assertEqual(null, couch_util:get_value(<<"offset">>, InnerJson2)),
        ?assertEqual(5, length(couch_util:get_value(<<"rows">>, InnerJson2)))
    end)}.


should_succeed_on_local_docs_with_queries_keys(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "_local/doc" ++ ?i2l(I)) || I <- lists:seq(1, 10)],
        QueryDoc = "{\"queries\": [{\"keys\":
            [ \"_local/doc3\", \"_local/doc8\"]}]}",
        {ok, RC, _, RespBody} = test_request:post(Url ++ "/_local_docs/queries/",
            [?CONTENT_JSON, ?AUTH], QueryDoc),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ResultJsonBody = couch_util:get_value(<<"results">>, ResultJson),
        {InnerJson} = lists:nth(1, ResultJsonBody),
        ?assertEqual(2, length(couch_util:get_value(<<"rows">>, InnerJson)))
    end)}.


should_succeed_on_local_docs_with_queries_limit_skip(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "_local/doc" ++ ?i2l(I)) || I <- lists:seq(1, 10)],
        QueryDoc = "{\"queries\": [{\"limit\": 5, \"skip\": 2}]}",
        {ok, RC, _, RespBody} = test_request:post(Url ++
            "/_local_docs/queries/", [?CONTENT_JSON, ?AUTH], QueryDoc),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ResultJsonBody = couch_util:get_value(<<"results">>, ResultJson),
        {InnerJson} = lists:nth(1, ResultJsonBody),
        ?assertEqual(5, length(couch_util:get_value(<<"rows">>, InnerJson)))
    end)}.


should_succeed_on_local_docs_with_multiple_queries(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
        [create_doc(Url, "_local/doc" ++ ?i2l(I)) || I <- lists:seq(1, 10)],
        QueryDoc = "{\"queries\": [{\"keys\": [ \"_local/doc3\",
            \"_local/doc8\"]}, {\"limit\": 5, \"skip\": 2}]}",
        {ok, RC, _, RespBody} = test_request:post(Url ++
            "/_local_docs/queries/", [?CONTENT_JSON, ?AUTH], QueryDoc),
        ?assertEqual(200, RC),
        {ResultJson} = ?JSON_DECODE(RespBody),
        ResultJsonBody = couch_util:get_value(<<"results">>, ResultJson),
        {InnerJson1} = lists:nth(1, ResultJsonBody),
        ?assertEqual(2, length(couch_util:get_value(<<"rows">>, InnerJson1))),
        {InnerJson2} = lists:nth(2, ResultJsonBody),
        ?assertEqual(5, length(couch_util:get_value(<<"rows">>, InnerJson2)))
    end)}.


should_return_headers_after_starting_continious(Url) ->
    {timeout, ?TIMEOUT, ?_test(begin
       {ok, _, _, Bin} =
            test_request:get(Url ++ "/_changes?feed=live&timeout=1", [?AUTH]),

        Parts = binary:split(Bin, <<"\n">>, [global]),
        %% we should receive at least one part even when timeout=1
        ?assertNotEqual([], Parts)
    end)}.

wait_non_empty_chunk(Url) ->
    test_util:wait(fun() ->
        {ok, _, _, Bin} =
            test_request:get(Url ++ "/_changes?feed=live&timeout=1", [?AUTH]),

        Parts = binary:split(Bin, <<"\n">>, [global]),

        case [P || P <- Parts, size(P) > 0] of
            [] -> wait;
            Chunks -> Chunks
        end
    end).