Skip to content

Commit 6f42f49

Browse files
committed
Clean up meck functions in fabric
- 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`
1 parent 5c08b39 commit 6f42f49

11 files changed

+376
-415
lines changed

src/fabric/src/fabric.erl

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ set_namespace(NS, #mrargs{extra = Extra} = Args) ->
761761
Args#mrargs{extra = [{namespace, NS} | Extra]}.
762762

763763
-ifdef(TEST).
764-
-include_lib("eunit/include/eunit.hrl").
764+
-include_lib("couch/include/couch_eunit.hrl").
765765

766766
update_doc_test_() ->
767767
{
@@ -770,18 +770,12 @@ update_doc_test_() ->
770770
setup,
771771
fun setup/0,
772772
fun teardown/1,
773-
fun(Ctx) ->
774-
[
775-
should_throw_conflict(Ctx)
776-
]
777-
end
773+
with([?TDEF(should_throw_conflict)])
778774
}
779775
}.
780776

781777
should_throw_conflict(Doc) ->
782-
?_test(begin
783-
?assertThrow(conflict, update_doc(<<"test-db">>, Doc, []))
784-
end).
778+
?assertThrow(conflict, update_doc(<<"test-db">>, Doc, [])).
785779

786780
setup() ->
787781
Doc = #doc{
@@ -793,25 +787,13 @@ setup() ->
793787
meta = []
794788
},
795789
ok = application:ensure_started(config),
796-
ok = meck:expect(mem3, shards, fun(_, _) -> [] end),
797-
ok = meck:expect(mem3, quorum, fun(_) -> 1 end),
798-
ok = meck:expect(rexi, cast, fun(_, _) -> ok end),
799-
ok = meck:expect(
800-
rexi_utils,
801-
recv,
802-
fun(_, _, _, _, _, _) ->
803-
{ok, {error, [{Doc, conflict}]}}
804-
end
805-
),
806-
ok = meck:expect(
807-
couch_util,
808-
reorder_results,
809-
fun(_, [{_, Res}], _) ->
810-
[Res]
811-
end
812-
),
813-
ok = meck:expect(fabric_util, create_monitors, fun(_) -> ok end),
814-
ok = meck:expect(rexi_monitor, stop, fun(_) -> ok end),
790+
meck:expect(mem3, shards, fun(_, _) -> [] end),
791+
meck:expect(mem3, quorum, fun(_) -> 1 end),
792+
meck:expect(rexi, cast, fun(_, _) -> ok end),
793+
meck:expect(rexi_utils, recv, fun(_, _, _, _, _, _) -> {ok, {error, [{Doc, conflict}]}} end),
794+
meck:expect(couch_util, reorder_results, fun(_, [{_, Res}], _) -> [Res] end),
795+
meck:expect(fabric_util, create_monitors, fun(_) -> ok end),
796+
meck:expect(rexi_monitor, stop, fun(_) -> ok end),
815797
Doc.
816798

817799
teardown(_) ->

src/fabric/src/fabric_db_create.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,15 @@ db_exists_for_existing_db() ->
221221
Mock = fun(DbName) when is_binary(DbName) ->
222222
[#shard{dbname = DbName, range = [0, 100]}]
223223
end,
224-
ok = meck:expect(mem3, shards, Mock),
224+
meck:expect(mem3, shards, Mock),
225225
?assertEqual(true, db_exists(<<"foobar">>)),
226226
?assertEqual(true, meck:validate(mem3)).
227227

228228
db_exists_for_missing_db() ->
229229
Mock = fun(DbName) ->
230230
erlang:error(database_does_not_exist, [DbName])
231231
end,
232-
ok = meck:expect(mem3, shards, Mock),
232+
meck:expect(mem3, shards, Mock),
233233
?assertEqual(false, db_exists(<<"foobar">>)),
234234
?assertEqual(false, meck:validate(mem3)).
235235

0 commit comments

Comments
 (0)