iilyak commented on code in PR #4151:
URL: https://github.com/apache/couchdb/pull/4151#discussion_r950324522


##########
src/couch_replicator/test/eunit/couch_replicator_use_checkpoints_tests.erl:
##########
@@ -14,133 +14,77 @@
 
 -include_lib("couch/include/couch_eunit.hrl").
 -include_lib("couch/include/couch_db.hrl").
-
--import(couch_replicator_test_helper, [
-    db_url/1,
-    replicate/1
-]).
+-include("couch_replicator_test.hrl").
 
 -define(DOCS_COUNT, 100).
 -define(TIMEOUT_EUNIT, 30).
 -define(i2l(I), integer_to_list(I)).
 -define(io2b(Io), iolist_to_binary(Io)).
 
-start(false) ->
-    fun
-        ({finished, _, {CheckpointHistory}}) ->
-            ?assertEqual([{<<"use_checkpoints">>, false}], CheckpointHistory);
-        (_) ->
-            ok
-    end;
-start(true) ->
-    fun
-        ({finished, _, {CheckpointHistory}}) ->
-            ?assertNotEqual(
-                false,
-                lists:keyfind(
-                    <<"session_id">>,
-                    1,
-                    CheckpointHistory
-                )
-            );
-        (_) ->
-            ok
-    end.
-
-stop(_, _) ->
-    ok.
-
-setup() ->
-    DbName = ?tempdb(),
-    {ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
-    ok = couch_db:close(Db),
-    DbName.
+setup_checkpoints() ->
+    {Ctx, {Source, Target}} = couch_replicator_test_helper:test_setup(),
+    Fun = fun notifier_checkpoint_fun/1,
+    {ok, Listener} = couch_replicator_notifier:start_link(Fun),
+    {Ctx, {Source, Target, Listener}}.
 
-setup(remote) ->
-    {remote, setup()};
-setup({_, Fun, {A, B}}) ->
-    Ctx = test_util:start_couch([couch_replicator]),
+setup_no_checkpoints() ->
+    {Ctx, {Source, Target}} = couch_replicator_test_helper:test_setup(),
+    Fun = fun notifier_no_checkpoint_fun/1,
     {ok, Listener} = couch_replicator_notifier:start_link(Fun),
-    Source = setup(A),
-    Target = setup(B),
     {Ctx, {Source, Target, Listener}}.
 
-teardown({remote, DbName}) ->
-    teardown(DbName);
-teardown(DbName) ->
-    ok = couch_server:delete(DbName, [?ADMIN_CTX]),
-    ok.
+teardown({Ctx, {Source, Target, Listener}}) ->
+    couch_replicator_notifier:stop(Listener),
+    couch_replicator_test_helper:test_teardown({Ctx, {Source, Target}}).
 
-teardown(_, {Ctx, {Source, Target, Listener}}) ->
-    teardown(Source),
-    teardown(Target),
+notifier_checkpoint_fun({finished, _, {CheckpointHistory}}) ->
+    SId = lists:keyfind(<<"session_id">>, 1, CheckpointHistory),
+    ?assertNotEqual(false, SId);

Review Comment:
   Depending on the nature of this assertion (is a test or a safety check to 
ensure we setup properly) we could add annotation before assertion.
   
   I don't know whether values other then `true | false` are expected.  
   
   ```
   # this would work only if valid value for SId is `true` (which I don't think 
it is)
   SId orelse debugMsg("There was a problem during setup the session checkpoint 
is not found", []),
   ?assertEqual(false, SId);
   
   # this should work regardless of other Sid values
   SId =/= false orelse debugMsg("There was a problem during setup the session 
checkpoint is not found"),
   ?assertEqual(false, SId);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to