You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "jiahuili430 (via GitHub)" <gi...@apache.org> on 2025/03/12 20:46:10 UTC

[PR] chore: Clean up `meck` functions in `fabric` [couchdb]

jiahuili430 opened a new pull request, #5473:
URL: https://github.com/apache/couchdb/pull/5473

   
   
   <!-- Thank you for your contribution!
   
        Please file this form by replacing the Markdown comments
        with your text. If a section needs no action - remove it.
   
        Also remember, that CouchDB uses the Review-Then-Commit (RTC) model
        of code collaboration. Positive feedback is represented +1 from committers
        and negative is a -1. The -1 also means veto, and needs to be addressed
        to proceed. Once there are no objections, the PR can be merged by a
        CouchDB committer.
   
        See: http://couchdb.apache.org/bylaws.html#decisions for more info. -->
   
   ## Overview
   
   <!-- Please give a short brief for the pull request,
        what problem it solves or how it makes things better. -->
   
   - After upgrading `meck`, CI got errors about `context setup failed`.
   Cleaning up `meck` functions in `fabric` to fix this issue.
   
   ```
   [2025-03-12T20:04:15.632Z] module 'fabric_view_map'
   [2025-03-12T20:04:16.552Z]   fabric_view_map_meck_original:330: -handle_message_test_/0-fun-20- (t_handle_message_rexi_down)...[0.005 s] ok
   [2025-03-12T20:04:17.472Z]   undefined
   [2025-03-12T20:04:17.472Z]   *** context setup failed ***
   [2025-03-12T20:04:17.472Z] **in function persistent_term:get/1
   [2025-03-12T20:04:17.472Z]   called as get({cover,fabric_view_map_meck_original})
   [2025-03-12T20:04:17.472Z] in call from fabric_view_map_meck_original:'-handle_message_test_/0-fun-23-'/0
   [2025-03-12T20:04:17.472Z] **error:badarg
   ```
   
   - Simplify tests with `?TDEF` and `?TDEF_FE`
   
   ## Testing recommendations
   
   <!-- Describe how we can test your changes.
        Does it provide any behaviour that the end users
        could notice? -->
   
   `make eunit apps=fabric`
   
   ## Related Issues or Pull Requests
   
   <!-- If your changes affect multiple components in different
        repositories please put links to those issues or pull requests here.  -->
   
   ## Checklist
   
   - [ ] Code is written and works correctly
   - [ ] Changes are covered by tests
   - [ ] Any new configurable parameters are documented in `rel/overlay/etc/default.ini`
   - [ ] Documentation changes were made in the `src/docs` folder
   - [ ] Documentation changes were backported (separated PR) to affected branches
   


-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] chore: Clean up `meck` functions in `fabric` [couchdb]

Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on code in PR #5473:
URL: https://github.com/apache/couchdb/pull/5473#discussion_r1992295133


##########
src/fabric/src/fabric_doc_open.erl:
##########
@@ -230,67 +230,65 @@ open_doc_test_() ->
             fun setup/0,
             fun teardown/1,
             [
-                t_is_r_met(),
-                t_handle_message_down(),
-                t_handle_message_exit(),
-                t_handle_message_reply(),
-                t_store_node_revs(),
-                t_read_repair(),
-                t_no_read_repair_for_replicator(),
-                t_handle_response_quorum_met(),
-                t_get_doc_info()
+                ?TDEF_FE(t_is_r_met),
+                ?TDEF_FE(t_handle_message_down),
+                ?TDEF_FE(t_handle_message_exit),
+                ?TDEF_FE(t_handle_message_reply),
+                ?TDEF_FE(t_store_node_revs),
+                ?TDEF_FE(t_read_repair),
+                ?TDEF_FE(t_no_read_repair_for_replicator),
+                ?TDEF_FE(t_handle_response_quorum_met),
+                ?TDEF_FE(t_get_doc_info)
             ]
         }
     }.
 
-t_is_r_met() ->
-    ?_test(begin
-        Workers0 = [],
-        Workers1 = [nil],
-        Workers2 = [nil, nil],
-
-        SuccessCases = [
-            {{true, foo}, [fabric_util:kv(foo, 2)], 2},
-            {{true, foo}, [fabric_util:kv(foo, 3)], 2},
-            {{true, foo}, [fabric_util:kv(foo, 1)], 1},
-            {{true, foo}, [fabric_util:kv(foo, 2), fabric_util:kv(bar, 1)], 2},
-            {{true, bar}, [fabric_util:kv(bar, 1), fabric_util:kv(bar, 2)], 2},
-            {{true, bar}, [fabric_util:kv(bar, 2), fabric_util:kv(foo, 1)], 2}
-        ],
-        lists:foreach(
-            fun({Expect, Replies, Q}) ->
-                ?assertEqual(Expect, is_r_met(Workers0, Replies, Q))
-            end,
-            SuccessCases
-        ),
-
-        WaitForMoreCases = [
-            {[fabric_util:kv(foo, 1)], 2},
-            {[fabric_util:kv(foo, 2)], 3},
-            {[fabric_util:kv(foo, 1), fabric_util:kv(bar, 1)], 2}
-        ],
-        lists:foreach(
-            fun({Replies, Q}) ->
-                ?assertEqual(wait_for_more, is_r_met(Workers2, Replies, Q))
-            end,
-            WaitForMoreCases
-        ),
-
-        FailureCases = [
-            {Workers0, [fabric_util:kv(foo, 1)], 2},
-            {Workers1, [fabric_util:kv(foo, 1)], 2},
-            {Workers1, [fabric_util:kv(foo, 1), fabric_util:kv(bar, 1)], 2},
-            {Workers1, [fabric_util:kv(foo, 2)], 3}
-        ],
-        lists:foreach(
-            fun({Workers, Replies, Q}) ->
-                ?assertEqual(no_more_workers, is_r_met(Workers, Replies, Q))
-            end,
-            FailureCases
-        )
-    end).
+t_is_r_met(_) ->

Review Comment:
   Excellent cleanup!



-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] chore: Clean up `meck` functions in `fabric` [couchdb]

Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on code in PR #5473:
URL: https://github.com/apache/couchdb/pull/5473#discussion_r1992291270


##########
src/fabric/src/fabric_doc_open_revs.erl:
##########
@@ -327,19 +327,19 @@ collapse_duplicate_revs_int([Reply | Rest]) ->
 
 setup_all() ->
     config:start_link([]),
-    meck:new([fabric, couch_stats, couch_log]),
-    meck:new(fabric_util, [passthrough]),
-    meck:expect(fabric, update_docs, fun(_, _, _) -> {ok, nil} end),
-    meck:expect(couch_stats, increment_counter, fun(_) -> ok end),
-    meck:expect(couch_log, notice, fun(_, _) -> ok end),
-    meck:expect(fabric_util, cleanup, fun(_) -> ok end).
+    ok = meck:new([fabric, couch_stats, couch_log]),
+    ok = meck:new(fabric_util, [passthrough]),
+    ok = meck:expect(fabric, update_docs, fun(_, _, _) -> {ok, nil} end),
+    ok = meck:expect(couch_stats, increment_counter, fun(_) -> ok end),
+    ok = meck:expect(couch_log, notice, fun(_, _) -> ok end),
+    ok = meck:expect(fabric_util, cleanup, fun(_) -> ok end).

Review Comment:
   I wouldn't bother with `ok =`, I think these only return `ok` or throw an error. This won't catch an error anyway.



-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] chore: Clean up `meck` functions in `fabric` [couchdb]

Posted by "jiahuili430 (via GitHub)" <gi...@apache.org>.
jiahuili430 merged PR #5473:
URL: https://github.com/apache/couchdb/pull/5473


-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] chore: Clean up `meck` functions in `fabric` [couchdb]

Posted by "jiahuili430 (via GitHub)" <gi...@apache.org>.
jiahuili430 commented on code in PR #5473:
URL: https://github.com/apache/couchdb/pull/5473#discussion_r1992417856


##########
src/fabric/src/fabric_doc_open_revs.erl:
##########
@@ -327,19 +327,19 @@ collapse_duplicate_revs_int([Reply | Rest]) ->
 
 setup_all() ->
     config:start_link([]),
-    meck:new([fabric, couch_stats, couch_log]),
-    meck:new(fabric_util, [passthrough]),
-    meck:expect(fabric, update_docs, fun(_, _, _) -> {ok, nil} end),
-    meck:expect(couch_stats, increment_counter, fun(_) -> ok end),
-    meck:expect(couch_log, notice, fun(_, _) -> ok end),
-    meck:expect(fabric_util, cleanup, fun(_) -> ok end).
+    ok = meck:new([fabric, couch_stats, couch_log]),
+    ok = meck:new(fabric_util, [passthrough]),
+    ok = meck:expect(fabric, update_docs, fun(_, _, _) -> {ok, nil} end),
+    ok = meck:expect(couch_stats, increment_counter, fun(_) -> ok end),
+    ok = meck:expect(couch_log, notice, fun(_, _) -> ok end),
+    ok = meck:expect(fabric_util, cleanup, fun(_) -> ok end).

Review Comment:
   Removed all `ok = ` from `meck:expect()` and `meck:reset()` in `fabric` module, thanks for the review!



-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] chore: Clean up `meck` functions in `fabric` [couchdb]

Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on code in PR #5473:
URL: https://github.com/apache/couchdb/pull/5473#discussion_r1992294066


##########
src/fabric/test/eunit/fabric_db_uuids_tests.erl:
##########
@@ -29,7 +29,6 @@ setup() ->
     test_util:start_couch([fabric]).
 
 teardown(Ctx) ->
-    meck:unload(),

Review Comment:
   Nice find, an extra unload without a `new()` or `expect()`



-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] chore: Clean up `meck` functions in `fabric` [couchdb]

Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on code in PR #5473:
URL: https://github.com/apache/couchdb/pull/5473#discussion_r1992292298


##########
src/fabric/test/eunit/fabric_db_info_tests.erl:
##########
@@ -28,7 +28,6 @@ setup() ->
     test_util:start_couch([fabric]).
 
 teardown(Ctx) ->
-    meck:unload(),

Review Comment:
   Nice find!



-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org